This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Seq.unfold (https://msdn.microsoft.com/en-us/library/ee340363.aspx) | |
// works with a generator function that gets a state and returns | |
// Some (element, state) to generate another iterator, or | |
// None to stop the iteration. | |
// The problem is that tuples are allocated every single iteration. | |
// | |
// The solution below uses instead a generator function that gets | |
// a state and an iterator function. The iterator function can be called | |
// to yield a new element and set a new state for the next iterator. If the | |
// generator function returns a unit, i.e. (), the iteration stops. |
NewerOlder