[Proposal] Add a pipe-right macro |>> to Kernel

98 views
Skip to first unread message

Boyd Multerer

unread,
Mar 9, 2018, 2:45:24 PM3/9/18
to elixir-lang-core
A pattern I find myself in all the time is when I am writing a piped  series of function calls, when I need to pass the result into some parameter other than the first one.

Something like this.

        Map.get( p_map, puid )
        |> Group.insert_at( index, uid )
        |> ( &Map.put(p_map, puid, &1) ).()
        |> ( &put_primitive_map(graph, &1) ).()
        |> something_else()

The trick to pipe into a anonymous function works, but is ugly and least to poor readability.

I would really like a pipe_right macro, which would work something like this.

        Map.get( p_map, puid )
        |> Group.insert_at( index, uid )
        |>> Map.put(p_map, puid, &1)
        |>> put_primitive_map(graph, &1)
        |> something_else()

Note that it should be interchangeable with the standard pipe without breaking the piping flow.

I keep running into this and reached the point where I really want this macro in the Kernel module.

Ben Wilson

unread,
Mar 9, 2018, 2:49:09 PM3/9/18
to elixir-lang-core
I would highly recommend taking a walk through existing threads in the mailing list and forums. This and other similar pipe additions have been requested before. I'm glad you're interested in improving the language, but the proposal itself doesn't reflect a familiarity with existing answers to this very question.

Matt Jadczak

unread,
Mar 10, 2018, 1:05:45 PM3/10/18
to elixir-lang-core
Additionally, for the specific example you mentioned, where you seem to be getting something out of a map, updating it, and putting it back in, there is `Map.update!/3` (https://hexdocs.pm/elixir/Map.html#update!/3)
 and `Map.update/4`.
Reply all
Reply to author
Forward
0 new messages