Enum.each_with_index

3,413 views
Skip to first unread message

Janis Miezitis

unread,
Aug 16, 2014, 8:42:15 AM8/16/14
to elixir-l...@googlegroups.com
Hey guys,
Right now in Elixir there is Enum.with_index that returns tuple that has index and value of the element. You have to have two steps to add indexes to collection and iterate over that collection. Would that be useful work on and submit pull request for Enum.each_with_index? 

Eric Meadows-Jönsson

unread,
Aug 16, 2014, 8:43:41 AM8/16/14
to elixir-l...@googlegroups.com

You can use lazy streams to do it one step:

coll
|> Stream.with_index
|> Enum.each(...)


On Sat, Aug 16, 2014 at 2:42 PM, Janis Miezitis <jan...@gmail.com> wrote:
Hey guys,
Right now in Elixir there is Enum.with_index that returns tuple that has index and value of the element. You have to have two steps to add indexes to collection and iterate over that collection. Would that be useful work on and submit pull request for Enum.each_with_index? 

--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Eric Meadows-Jönsson

Tallak Tveide

unread,
Aug 16, 2014, 10:28:46 AM8/16/14
to elixir-l...@googlegroups.com
I find each is less used in elixir compard to eg. Ruby, dt immutability. So map and reduce with index would probably be more useful. Even so, i like just chaining them with the pipe operator...

Tallak Tveide

unread,
Aug 16, 2014, 10:28:56 AM8/16/14
to elixir-l...@googlegroups.com

Tallak Tveide

unread,
Aug 16, 2014, 10:29:01 AM8/16/14
to elixir-l...@googlegroups.com

Janis Miezitis

unread,
Aug 17, 2014, 1:58:53 PM8/17/14
to elixir-l...@googlegroups.com
Thanks guys, that makes sens. I guess I need to switch my thinking a bit :)
Reply all
Reply to author
Forward
0 new messages