Ever want to create an infinite sequence?
Me neither. But it’s really cool to see how we can do that with Stream.unfold/2.
You can think of unfold as something like the opposite of reduce. When we reduce, we grab a list (or sequence) and iterate over the values to generate a final value. With unfold, we start with a single value (the seed) and then generate a sequence by applying a transformation on each subsequent value.
Check out more at www.elixirstreams.com/tips/cr...
28 июн 2024