3 ms·
Working with streams of data often makes pointfree syntax beneficial, since you can start to see the omitted arguments "flow" through your chain of composed fun
by mrkgnao 9y ago
Working with streams of data often makes pointfree syntax beneficial, since you can start to see the omitted arguments "flow" through your chain of composed functions. If you write
f # g = \x -> g (f x)
then you could implement functions like this:
f :: Stream Int -> Stream Int
f = drop 3 -- drop the first three elements
# skipEvery 3 -- skip every third element
# sumEvery 2 -- sum every consecutive pair of elements
# map (* 2) -- double everything
This would turn
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...
into
2 * (4 + 5), 2 * (7 + 8), 2 * (10 + 11), ...
You can find many non-pointfree versions of similar streaming code here: https://github.com/snoyberg/conduit/ https://github.com/snoyberg/conduit/