4 ms·
It's notable that raku (previously known as perl6) lets you write things in either direction, if I remember correctly something like @source >>> map { ... }
by mst 4y ago
It's notable that raku (previously known as perl6) lets you write things in either direction, if I remember correctly something like
@source >>> map { ... } >>> grep { ... } >>> my @sink;
though note I'm typing from memory on my second coffee so I may have got that slightly wrong.
Plus of course there's many languages with a |> operator so you can do
g(x) |> f
I also (the example is specialised for I/O but the implementation technique could trivially be borrowed for something that wasn't) implemented something sort of in this direction for perl once: http://p3rl.org/IO::Pipeline http://p3rl.org/IO::Pipeline
I'm not convinced that left-to-right is -always- the best option and prefer having the choice of both, but I wouldn't be at all surprised if a survey of developers found that if they could only pick one they'd pick left-to-right, and while I'd find it hard to choose for myself alone I'd probably pick left-to-right on the basis that it'd likely make it easier to onboard people to any given codebase.
- tmtvl 4y agoRaku also has map and grep methods for collections, so it could be written as... my @sink = @source.map({...}).grep({...}).sort; Which also makes multithreading the operation easy: my @sink = @source.hyper.map({...}).grep({...}).sort.list; That said, I think the operator you're looking for is the feed operator, ==>: my @sink; @source ==> map {...} ==> grep {...} ==> sort ==> @sink; It also has the corresponding reverse, <==, because why not. The docs* mention that ==> may at some point do automatic parallelization, but I don't know what the status of that feature is. * https://docs.raku.org/routine/==%3E https://docs.raku.org/routine/==%3E
- mst 4y ago> That said, I think the operator you're looking for is the feed operator, ==> Yes, yes it was. Your clarifications, corrections and elaborations are much appreciated.