|
|
@@ -9,14 +9,19 @@ import {
|
|
|
BatchedStreamBuilder,
|
|
|
ThrottledStreamBuilder,
|
|
|
FilteredStreamBuilder,
|
|
|
+ LinearShape,
|
|
|
+ builderSymbol,
|
|
|
} from './internal/StreamStageBuilder'
|
|
|
|
|
|
import { Sink } from './Sink'
|
|
|
+import { Flow } from './Flow'
|
|
|
|
|
|
-export class Source<T> {
|
|
|
+export class Source<T> extends LinearShape<T> {
|
|
|
protected __phantom__!: T
|
|
|
|
|
|
- private constructor(private builder: StreamStageBuilder<T>) {}
|
|
|
+ private constructor(protected builder: StreamStageBuilder<T>) {
|
|
|
+ super(builder)
|
|
|
+ }
|
|
|
|
|
|
map<O>(f: (v: T) => O): Source<O> {
|
|
|
return new Source(MappedStreamBuilder(this.builder, f))
|
|
|
@@ -38,10 +43,19 @@ export class Source<T> {
|
|
|
return new Source(FilteredStreamBuilder(this.builder, predicate))
|
|
|
}
|
|
|
|
|
|
- throttle(elements: number, perDurationMs: number) {
|
|
|
+ throttle(elements: number, perDurationMs: number): Source<T> {
|
|
|
return new Source(ThrottledStreamBuilder(this.builder, elements, perDurationMs))
|
|
|
}
|
|
|
|
|
|
+ via<O>(flow: Flow<T, O>): Source<O> {
|
|
|
+ const builder = this.builder
|
|
|
+ return new Source({
|
|
|
+ build() {
|
|
|
+ return [...builder.build(), ...flow[builderSymbol].build()]
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
into<M>(sink: Sink<T, M>) {
|
|
|
const self = this
|
|
|
return {
|