A couple thoughts: * The proposed operator `&>` may be ambiguous to parse due to function capture syntax, e.g. distinguishing between `&>` and `&>/2` might be problematic. A different operator would probably be better. José would have to chime in on that * I like the idea of having a simple way of capturing a pipeline built in to the language, but I'm not really a fan of introducing more operators. My gut feeling is that I'd prefer a special form or plain macro instead, but if naming is an issue an operator might be the only option. Is there an equivalent in other languages? Nothing comes to mind as being a direct equivalent of this * I'm not entirely convinced this is necessary when it is so trivial to wrap a pipeline expression in an anonymous function anyway, but maybe I'm just not working on stuff which benefits from this kind of functional composition where the improved ergonomics would be more noticeable.
Paul On Tue, Oct 25, 2022, at 8:46 PM, pragdave wrote: > I know this has been discussed before, in different forms, but I thought I’d > just have another go following my recent earth-shattering PR :) > > I’d like to propose a new unary operator, `&>`. It works just like the > pipeline `|>`, but doesn’t take a left argument. Instead it returns an arity > 1 function that, when called, executes the pipeline. > > `toCamel = &> downcase |> split("_") |> map(&capitalize/1) |> join > > toCamel.("now is") *# => "NowIs"* > "the_time" |> toCamel.() *# => "the time"* ` > Why? > > * Function composition is a key part of FP. It would be nice to support it > natively. > > * The current pipeline semantic both defines a processing flow *and executes > it*. Splitting this into two would allow a lot more expressiveness. > > * This would allow pipelines to be composed. Think Plug, but functional . > > ` pipeline :browser *do* > > plug :accepts, ["html"] > > plug :fetch_session > > plug :fetch_flash > > plug :protect_from_forgery > *end* ` > would become > > `browser_pipeline = > &> accepts("html") |> fetch_session |> fetch_flash |> protect_from_forgery ` > The cool thing here is that each of the elements of the pipe is simply a > function, and could be a nested pipeline. For example, we could create an > authenticated pipeline by embedding the browser pipeline: > > `authenticated_pipeline = &> browser_pipeline.() |> authenticate ` > How? > > If we created a new prefix operator in the interpreter, then we could > implement a proof of concept as a library. Folks could then use this for a > while to see if the idea has merit, and if so, possibly roll this into the > language syntax. > > I’d be happy to do this if there’s interest. > > Dave > > > > > -- > You received this message because you are subscribed to the Google Groups > "elixir-lang-core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to elixir-lang-core+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/elixir-lang-core/a5b1186c-a4ea-4f50-8143-354738f47632n%40googlegroups.com > > <https://groups.google.com/d/msgid/elixir-lang-core/a5b1186c-a4ea-4f50-8143-354738f47632n%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/1ba84d64-301c-49d6-a9a5-18228fbdfa20%40app.fastmail.com.