WingNews logo WingNews
top | new | best | ask | show | jobs
top | item 41719177

(no title)

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

discuss

order

No comments yet.

powered by hn/api // news.ycombinator.com