-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
Streams offer an interesting way to bottle up a closure, effectively hiding state and then consume the output later. However, this is limited to consuming the entire stream at a later point, in some cases it might be useful to be able to stop and resume in sections.
The feature request is first class support in the language for Stream suspension, however, I don't have a concrete suggestion on how that might look? My requirements are fairly "toy" at present, but my use might mainly be to pull items one by one from a stream, eg
s = Stream.cycle([1,2,3])
{first, s} = "take_one" s
do something with first
{next, s} = "take_one" s
Perhaps an "iterator" type which could wrap a stream? The iterator could support Enumerable, and then the interface feels approximately like using Enum methods, but you also get back a continuation (the iterator) which allows you to continue if you wish?