castFrom<S, T> method Null safety

Stream<T> castFrom<S, T>(
  1. Stream<S> source
)

Adapts source to be a Stream<T>.

This allows source to be used at the new type, but at run-time it must satisfy the requirements of both the new type and its original type.

Data events created by the source stream must also be instances of T.

Implementation

static Stream<T> castFrom<S, T>(Stream<S> source) =>
    new CastStream<S, T>(source);