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"
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
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
This would allow pipelines to be composed. Think Plug, but functional.
Function composition is a key part of FP.
--
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-co...@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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/b65549eb-89fb-47f6-b6ce-eb226ab75538n%40googlegroups.com.
For the plugs example, how is it better than the alternative that exists today?
Function composition is a key part of FP.
Agreed, but functional composition(h = g ∘ f) is not the way the overwhelming majority of elixir code is written.
--
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-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/4debfa0c-7489-4e70-8025-be746a40d63an%40googlegroups.com.
--
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-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/4debfa0c-7489-4e70-8025-be746a40d63an%40googlegroups.com.
The other thing is that the original code can be written as this:& &1 |> downcase |> split("_") |> map(&capitalize/1) |> join
--
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-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/a021d58c-3ec8-43c3-9de3-8383f5e2e9a3n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4JfPzs31TVUUZSU3KEcuuctyXSkpr8ZNuvGu4VNzSD6ew%40mail.gmail.com.
We could resolve it, yes, and allow &capitalize/1 inside captures. I wouldn't oppose it.
--
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-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CADwvmaX_NKEsWsQYhxeGoxb2fzqJ0bXAg4gh3NxocEVRpqj4zg%40mail.gmail.com.