Elixir range for arithmetic progression

Is it possible to express arithmetic progression in a list without listing them all?

In Haskell, you can do this with a range function.

[2,4..10] == [2,4,6,8,10] 

Is there a similar way to do this with Elixir?

+4
source share
3 answers

Stream.iterate / 2 does what you want:

 Stream.iterate(2, &(&1+2)) 
+4
source

You can use the Erlang lists:seq function, from Elixir:

 :lists.seq(2,10,2) 
+4
source
+1
source

Source: https://habr.com/ru/post/1497444/


All Articles