combined<R, O> method

ValueStream<R> combined<R, O>(
  1. ValueStream<O> other,
  2. R combiner(
    1. T? self,
    2. O? other
    )
)

Combines another stream.

Implementation

ValueStream<R> combined<R, O>(ValueStream<O> other, R combiner(T? self, O? other)) {
  final startCombined = this.get().thenOrNull((first) {
    return other.get().thenOrNull((otherFirst) {
      return combiner(first, otherFirst);
    });
  });

  final _self = get().futureValue().asStream().combine(after);
  final Stream<O> _other = other.get().futureValue().asStream().whereType<O>().combine(other.after);

  /// THe combine transformation requires both stream to publish at least once, so we'll force the current value
  /// to be republished.
  return ValueStream<R>.of(startCombined.unbox(), _self.combineLatest(_other, combiner));
}