Can I fork a sequence in F#?

I have a sequence that streams a large amount of data from the disk.

While using the sequence, there are some cases where I’d like to explore two paths.
Is there a way to turn the sequence, at a given point, into two different objects and, from that point, use it into two different code paths, independently?

The dataset is very large and streamed from a disk, so I can’t turn it into a list, etc.

  • Seq.groupBy might be closest from out of the box. But at some moment you might want to have some buffering or conditional accumulation so yielding from while loop in seq{} expression with enumerator and mutables might be the best option

    – 




  • I think this is a nice explanation why a “seq.tee” is not generally possible. Unless you own the Enumerator code of the sequence.

    – 

Leave a Comment