I turned the code snippets above into benchmarks, and ran them with and without the proposed changes in the stdlib. (Please note that the "after" keeps the LazyMap...
and LazyFilter...
types and corresponding functions, i.e. it is pretty much apple/swift#14841).
Here are the results:
Before
> bin/Benchmark_O ChainedFilterMap FatCompactMap --num-samples=5
#,TEST,SAMPLES,MIN(us),MAX(us),MEAN(us),SD(us),MEDIAN(us)
1,ChainedFilterMap,5,1293,1361,1317,29,1307
2,FatCompactMap,5,192573,201983,196937,4094,195579
Totals,2,193866,203344,198254,0,0
After
> bin/Benchmark_O ChainedFilterMap FatCompactMap --num-samples=5
#,TEST,SAMPLES,MIN(us),MAX(us),MEAN(us),SD(us),MEDIAN(us)
1,ChainedFilterMap,5,1348,1357,1351,3,1350
2,FatCompactMap,5,1295,1308,1298,5,1296
Totals,2,2643,2665,2649,0,0
My interpretation of the results is that we don't lose much in the chaining case, but gain a lot in the compactMap
case, and also gain a simpler type for complex lazy chains.