Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any stream combinator libraries for dart?

Tags:

dart

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.

like image 258
jz87 Avatar asked Oct 04 '22 21:10

jz87


2 Answers

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.

like image 188
Seth Ladd Avatar answered Oct 12 '22 08:10

Seth Ladd


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

like image 24
Dan Schultz Avatar answered Oct 12 '22 06:10

Dan Schultz