[Proposal] !> for pipe-lining tuples

117 views
Skip to first unread message

david.and...@gmail.com

unread,
Aug 17, 2017, 7:01:09 AM8/17/17
to elixir-lang-core
We all love the feeling of writing a nice pipeline, but using anonymous functions and captures to deal with :ok tuples can get rather frustrating.

Instead, I'd like the ability to utilise `!>! to tell the Elixir to unwrap the tuple for me, only on {:ok, val} - crashing on anything else.

Example:

1
|> twice         # 2
|> ok_tuple      # {:ok, 2}
!> twice         # 4

defp twice
(val), do:val*2
defp ok_tuple
(val), do: {:ok,val}

I have already started an implementation and it seems pretty simple. The only question now is: Is this a valuable addition to Elixir?

José Valim

unread,
Aug 17, 2017, 7:03:25 AM8/17/17
to elixir-l...@googlegroups.com
Hi David,

If you search the mailing list archives, you will see proposals to the pipe operator are very common. If we had accepted them all, it would have become a very complex beast.

The pipe operator works because it is simple. So we plan to keep it that way.

Thank you,



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/1c6103ec-bf2c-4366-984c-bdc5a931191b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

david.and...@gmail.com

unread,
Aug 17, 2017, 7:33:31 AM8/17/17
to elixir-lang-core, jose....@plataformatec.com.br
Yeah, I've read a few of them and found some user land libraries that seem to implement something akin to this proposal.

No problem.
Thanks


On Thursday, 17 August 2017 13:03:25 UTC+2, José Valim wrote:
Hi David,

If you search the mailing list archives, you will see proposals to the pipe operator are very common. If we had accepted them all, it would have become a very complex beast.

The pipe operator works because it is simple. So we plan to keep it that way.

Thank you,



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

On Thu, Aug 17, 2017 at 1:01 PM, <david.and...@gmail.com> wrote:
We all love the feeling of writing a nice pipeline, but using anonymous functions and captures to deal with :ok tuples can get rather frustrating.

Instead, I'd like the ability to utilise `!>! to tell the Elixir to unwrap the tuple for me, only on {:ok, val} - crashing on anything else.

Example:

1
|> twice         # 2
|> ok_tuple      # {:ok, 2}
!> twice         # 4

defp twice
(val), do:val*2
defp ok_tuple
(val), do: {:ok,val}

I have already started an implementation and it seems pretty simple. The only question now is: Is this a valuable addition to Elixir?

--
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.
Message has been deleted

niahoo osef

unread,
Aug 17, 2017, 9:41:37 AM8/17/17
to elixir-lang-core, jose....@plataformatec.com.br
I wrote something like that already, when there was no `with` : https://hex.pm/packages/monk

But I do not use it that much in the end.

What I use most is

def ok!({:ok, val}), do: val

SImpler.
Reply all
Reply to author
Forward
0 new messages