3 ms·
I had created a solution to scratch my itch while waiting for the pipe operator which even got a logo when it got more than a hundred stars, for anyone interest
by egeozcan 7y ago
I had created a solution to scratch my itch while waiting for the pipe operator which even got a logo when it got more than a hundred stars, for anyone interested: https://github.com/egeozcan/ppipe https://github.com/egeozcan/ppipe (needs ts typings though)
- svrtknst 7y agoThis is a neat one. In my current project, I created a (non-lazy) pipe function that take a value and a bunch of functions, composes the functions, and applies the value. pipe(2, add(2), square, n => n + 7) // -> 23 Nothing fancy but comes in handy at times. What I really miss is something like the |> from Elixir. Maybe it's the same as F#, I don't know, but it automatically performs partial application, so that: Enum.filter([1, 2, 3, 4], fn n -> n % 2 == 0 end) also works like: [1, 2, 3, 4] |> Enum.filter(fn n -> n % 2 == 0 end)
- egeozcan 7y agoMy library adds the piped value as the last parameter but if you read the docs, you'd see that you can use a placeholder to change its place: ppipe([1, 2, 3, 4]).pipe(Enum.filter, _, x => x % 2 === 0) Not that filter fn in js is in the prototype of arrays so you'd need to extract it. There's a shortcut when using my library though: ppipe([1,2,3]).filter(x => x > 2) I made the practical decision to provide prototype functions from the piped value while chaining.