Is it possible to express arithmetic progression in a list without listing them all?
In Haskell, you could do it with the range function.
[2,4..10] == [2,4,6,8,10]
Is there a similar way to do it with Elixir ?
Stream.iterate/2 does what you want:
Stream.iterate(2, &(&1+2))
You can use Erlang's lists:seq
function, from Elixir:
:lists.seq(2,10,2)
As I can see, there is a Stream.seq() added a month ago:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With