join method

Future<String> join([String separator = "" ])

Collects string of data events' string representations.

If separator is provided, it is inserted between any two elements.

Any error in the stream causes the future to complete with that error. Otherwise it completes with the collected string when the "done" event arrives.

Source

Future<String> join([String separator = ""]) {
  _Future<String> result = new _Future<String>();
  StringBuffer buffer = new StringBuffer();
  StreamSubscription subscription;
  bool first = true;
  subscription = this.listen((T element) {
    if (!first) {
      buffer.write(separator);
    }
    first = false;
    try {
      buffer.write(element);
    } catch (e, s) {
      _cancelAndErrorWithReplacement(subscription, result, e, s);
    }
  }, onError: (e) {
    result._completeError(e);
  }, onDone: () {
    result._complete(buffer.toString());
  }, cancelOnError: true);
  return result;
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/1.24.3/dart-async/Stream/join.html