top | item 41718163 (no title) finder83 | 1 year ago Infinite, yes, but I would say it's not quite as core to the language as it is in Haskell where everything's lazy. Infinite streams are quite simple though: Stream.iterate(1, fn(x) -> x end) |> Enum.take(5) [1, 1, 1, 1, 1] discuss order hn newest tromp|1 year ago How do you use that for lists that do not simply iterate, like ghci> fibs = 0 : 1 : zipWith (+) fibs (drop 1 fibs) ghci> take 10 fibs [0,1,1,2,3,5,8,13,21,34] ? darcien|1 year ago You can use Stream.unfold/2: Stream.unfold({0,1}, fn {a,b} -> {a,{b,a+b}} end) |> Enum.take(10) [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] https://rosettacode.org/wiki/Fibonacci_sequence#Elixir
tromp|1 year ago How do you use that for lists that do not simply iterate, like ghci> fibs = 0 : 1 : zipWith (+) fibs (drop 1 fibs) ghci> take 10 fibs [0,1,1,2,3,5,8,13,21,34] ? darcien|1 year ago You can use Stream.unfold/2: Stream.unfold({0,1}, fn {a,b} -> {a,{b,a+b}} end) |> Enum.take(10) [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] https://rosettacode.org/wiki/Fibonacci_sequence#Elixir
darcien|1 year ago You can use Stream.unfold/2: Stream.unfold({0,1}, fn {a,b} -> {a,{b,a+b}} end) |> Enum.take(10) [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] https://rosettacode.org/wiki/Fibonacci_sequence#Elixir
tromp|1 year ago
darcien|1 year ago