Proposal: Add Enum.at!/2

46 views
Skip to first unread message

eksperimental

unread,
Jul 18, 2016, 11:28:40 AM7/18/16
to elixir-l...@googlegroups.com
Hi everyone.
I think if we have Enum.at/3 we should also have Enum.at!/2

as with Enum.at/3 there is no way to guarantee that certain index
doesn't exist, since the default value could be contained in any of the
indexes.

The only option is to use Enum.fetch!/2

what do you guys think of this?

José Valim

unread,
Jul 18, 2016, 11:33:47 AM7/18/16
to elixir-l...@googlegroups.com
How Enum.at!/2 would be different from Enum.fetch!/2?



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-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/20160718222830.4f1c21d4.eksperimental%40autistici.org.
For more options, visit https://groups.google.com/d/optout.

eksperimental

unread,
Jul 18, 2016, 11:55:08 AM7/18/16
to elixir-l...@googlegroups.com
it doesn't (other than one returns a tuple and another the element
itself),
but same thing as Myron Marston mentioned,
it is useful when used in pipelines.

If we decide not to included. We should mention that in the at/3 docs.


On Mon, 18 Jul 2016 17:33:24 +0200
José Valim <jose....@plataformatec.com.br> wrote:

> How Enum.at!/2 would be different from Enum.fetch!/2?
>
>
>
> *José Valim*

Ben Wilson

unread,
Jul 18, 2016, 1:00:34 PM7/18/16
to elixir-lang-core, eksper...@autistici.org
Enum.fetch! returns simply the item itself. http://elixir-lang.org/docs/master/elixir/Enum.html#fetch!/2

fetch returns the tuples.

eksperimental

unread,
Jul 18, 2016, 4:55:35 PM7/18/16
to elixir-l...@googlegroups.com
thank you Ben and José,
I totally missed that!
> > > > <javascript:>. To view this discussion on the web visit
Reply all
Reply to author
Forward
0 new messages