splitFrom<T> static method

List<Stream<T>> splitFrom<T>(
  1. Stream<T> stream,
  2. [int? count]
)

Splits stream into count identical streams.

count defaults to 2. This is the same as creating count branches and then closing the StreamSplitter.

Implementation

static List<Stream<T>> splitFrom<T>(Stream<T> stream, [int? count]) {
  count ??= 2;
  var splitter = StreamSplitter<T>(stream);
  var streams = List<Stream<T>>.generate(count, (_) => splitter.split());
  splitter.close();
  return streams;
}