[Proposal] Pipe to any parameter?

41 views
Skip to first unread message

and...@paypip.com

unread,
Jul 10, 2017, 3:01:44 AM7/10/17
to elixir-lang-core
Hi guys,

I see a lot of libraries try to allow piping to the first parameter by default, but some don't support this easily.

I propose the following syntax to remedy this where it's needed to pipe to a specific parameter:

1) Normal pipe clearly works the same:

%{} |> SomeCode.function(other_params) === SomeCode.function(%{}, other_params)

2) The number of > dictates the position of the function we want to pipe into:

%{} |>> SomeCode.function("param1") === SomeCode.function("param1", %{})

3) We could also supply opts and other params:

%{} |>> SomeCode.function("param1", %{opts_are_param_3: true}) === SomeCode.function("param1", %{}, %{opts_are_param_3: true})

4) We can move to any specific param we want with more arrows, maybe limit it to 4, say to avoid it becoming ridiculous.

%{} |>>> SomeCode.function("param1", %{this_is_param_2: true}) === SomeCode.function("param1", %{this_is_param_2: true}, %{})

Thoughts?  Would other people find this useful in some situations?

José Valim

unread,
Jul 10, 2017, 4:32:43 AM7/10/17
to elixir-l...@googlegroups.com
Andrew, "pipe improvements" are common proposals to the mailing list that are always rejected. Please search for previous discussions on the topic for more information.



José Valim
Skype: jv.ptec
Founder and Director of R&D

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/2f2e23c7-bbbc-4c20-b177-95dea8628752%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages