While discussing what I've written here with a colleague, I've come across another neat implementation using unfoldr from this article which I've missed.
unfoldr
fibs = unfoldr (\(a,b) -> Just (a,(b,a+b))) (0,1) take 10 fibs
unfoldr is a method that builds an array list (towards the right) when given an initial seed (in this case, 0 and 1).
Just is a term used in Haskell's Maybe type, which draws parallel to how Optionals work in Java. Think of it as Optional.of()
Just
Maybe
Optionals
Optional.of()
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
While discussing what I've written here with a colleague, I've come across another neat implementation using
unfoldr
from this article which I've missed.unfoldr
is a method that builds an array list (towards the right) when given an initial seed (in this case, 0 and 1).Just
is a term used in Haskell'sMaybe
type, which draws parallel to howOptionals
work in Java. Think of it asOptional.of()