1. 18

  2. 9

    This is sometimes called unfold as it “unfolds” a stream of values from a seed.

    Interestingly, you can unfold many kinds of structures, not just streams. A stream occurs when a seed value turns into the next seed. A list occurs when the seed turns into either 1 or 0 new seeds. A (potentially infinite) binary tree occurs when a seed value turns into two subsequent seeds. More than this, we can return data structures containing new seeds and this will result in a unique kind of “stream” composed of “layers” of these data structures.

    1. 7

      Unfold is mentioned in the bug-tracker discussion, but they sought a different name as Ruby does not use the term “fold” either.

      It’s nice to see more functional concepts emerge in established languages, so I thought I’d share that here. :)

      1. 3

        Good call! I think it’s great for Ruby to adopt Rubyish names. I didn’t want to suggest that the implementers weren’t aware of the theory, just to share the connection.

      2. [Comment removed by author]

        1. 1

          Huh, that Wiki page is a lot nicer than the last time I saw it. Cool!