stream<S> function

ValueStream<S> stream<S>(
  1. S computation()
)

Create a stream that is derived from a computation.

Declare a computation whose derived value is used within a ValueStream. This allows signals to be used where Streams are expected instead, such as with the StreamBuilder widget. In addition this may be used for composition without the use of an effect.

Implementation

ValueStream<S> stream<S>(S Function() computation) {
  final derived = BehaviorSubject<S>();

  effect(() => derived.add(computation()));

  return derived.stream;
}