5

Does anyone know of any stream combinator libraries for dart? Things like joining multiple Stream into one Stream, split, combine(Stream, Stream) -> Stream<(A, B)>, etc.

jz87
  • 9,199
  • 10
  • 37
  • 42

2 Answers2

3

I'm not aware of a stream combinator library, but you could try to use StreamController to join streams.

Stream join(Stream a, Stream b) {
  var sc = new StreamController();
  int countDone = 0;
  done() {
    countDone++;
    if (countDone == 2) {
      sc.close();
    }
  }
  a.listen((e) => sc.add(e), onDone: done);
  b.listen((e) => sc.add(e), onDone: done);

  return sc.stream;
}

Warning: untested code.

Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
  • Yes, that's basically what I wrote, but there are problems that I pointed out here. http://stackoverflow.com/questions/17018427/dart-how-do-i-implement-stream-join-that-preserves-the-order-of-incoming-items/17019119?noredirect=1#comment24596762_17019119 – jz87 Jun 10 '13 at 16:55
1

Check out my library Frappe. It's loosely inspired by Bacon.js, and has a bunch of methods for combining streams.

Dan Schultz
  • 196
  • 3