Mirror: 🎩 A tiny but capable push & pull stream library for TypeScript and Flow

Replace tapAll with separate onStart, onPush, onEnd

+3
src/operators/wonka_operator_onEnd.d.ts
···
+
import { Operator } from '../wonka_types';
+
+
export const onEnd: <A>(f: (value: A) => void) => Operator<A, A>;
+28
src/operators/wonka_operator_onEnd.re
···
+
open Wonka_types;
+
+
let onEnd = f => curry(source => curry(sink => {
+
let ended = ref(false);
+
+
source((.signal) => {
+
switch (signal) {
+
| Start(talkback) => {
+
sink(.Start((.signal) => {
+
talkback(.signal);
+
+
if (!ended^) {
+
ended := true;
+
f(.);
+
}
+
}));
+
}
+
| End => {
+
if (!ended^) {
+
ended := true;
+
sink(.signal);
+
f(.);
+
}
+
}
+
| _ => sink(.signal)
+
};
+
});
+
}));
+3
src/operators/wonka_operator_onEnd.rei
···
+
open Wonka_types;
+
+
let onEnd: ((.unit) => unit, sourceT('a), sinkT('a)) => unit;
+4
src/operators/wonka_operator_onPush.rei
···
+
open Wonka_types;
+
+
let onPush: ((.'a) => unit, sourceT('a), sinkT('a)) => unit;
+
let tap: ((.'a) => unit, sourceT('a), sinkT('a)) => unit;
+3
src/operators/wonka_operator_onStart.d.ts
···
+
import { Operator } from '../wonka_types';
+
+
export const onStart: <A>(f: (value: A) => void) => Operator<A, A>;
+13
src/operators/wonka_operator_onStart.re
···
+
open Wonka_types;
+
+
let onStart = f => curry(source => curry(sink => {
+
source((.signal) => {
+
switch (signal) {
+
| Start(_) => {
+
sink(.signal);
+
f(.);
+
}
+
| _ => sink(.signal)
+
};
+
});
+
}));
+3
src/operators/wonka_operator_onStart.rei
···
+
open Wonka_types;
+
+
let onStart: ((.unit) => unit, sourceT('a), sinkT('a)) => unit;
+1
src/operators/wonka_operator_tap.d.ts src/operators/wonka_operator_onPush.d.ts
···
import { Operator } from '../wonka_types';
+
export const onPush: <A>(f: (value: A) => void) => Operator<A, A>;
export const tap: <A>(f: (value: A) => void) => Operator<A, A>;
+3 -1
src/operators/wonka_operator_tap.re src/operators/wonka_operator_onPush.re
···
open Wonka_types;
-
let tap = f => curry(source => curry(sink => {
+
let onPush = f => curry(source => curry(sink => {
source((.signal) => {
switch (signal) {
| Push(x) => f(.x)
···
sink(.signal);
});
}));
+
+
let tap = onPush;
-3
src/operators/wonka_operator_tap.rei
···
-
open Wonka_types;
-
-
let tap: ((.'a) => unit, sourceT('a), sinkT('a)) => unit;
-7
src/operators/wonka_operator_tapAll.d.ts
···
-
import { Operator } from '../wonka_types';
-
-
export const tapAll: <A>(
-
onStart: () => void,
-
onPush: (value: A) => void,
-
onEnd: () => void
-
) => Operator<A, A>;
-36
src/operators/wonka_operator_tapAll.re
···
-
open Wonka_types;
-
-
let tapAll = (~onStart, ~onPush, ~onEnd) => {
-
curry(source => curry(sink => {
-
let ended = ref(false);
-
-
source((.signal) => {
-
switch (signal) {
-
| Start(talkback) => {
-
onStart(.)
-
-
sink(.Start((.signal) => {
-
switch (signal) {
-
| Close when !ended^ => {
-
ended := true;
-
onEnd(.);
-
}
-
| Close => ()
-
| _ => talkback(.signal)
-
}
-
}));
-
}
-
| Push(x) => {
-
onPush(.x)
-
sink(.signal);
-
}
-
| End when !ended^ => {
-
ended := true;
-
onEnd(.)
-
}
-
| _ => ()
-
};
-
-
});
-
}));
-
};
-9
src/operators/wonka_operator_tapAll.rei
···
-
open Wonka_types;
-
-
let tapAll: (
-
~onStart: (.unit) => unit,
-
~onPush: (.'a) => unit,
-
~onEnd: (.unit) => unit,
-
sourceT('a),
-
sinkT('a)
-
) => unit;
+3 -2
src/wonka.d.ts
···
export * from './operators/wonka_operator_filter';
export * from './operators/wonka_operator_map';
export * from './operators/wonka_operator_mergeMap';
+
export * from './operators/wonka_operator_onEnd';
+
export * from './operators/wonka_operator_onPush';
+
export * from './operators/wonka_operator_onStart';
export * from './operators/wonka_operator_scan';
export * from './operators/wonka_operator_share';
export * from './operators/wonka_operator_skip';
···
export * from './operators/wonka_operator_takeLast';
export * from './operators/wonka_operator_takeUntil';
export * from './operators/wonka_operator_takeWhile';
-
export * from './operators/wonka_operator_tap';
-
export * from './operators/wonka_operator_tapAll';
/* sinks */
export * from './sinks/wonka_sink_publish';
+3 -2
src/wonka.ml
···
include Wonka_operator_filter
include Wonka_operator_map
include Wonka_operator_mergeMap
+
include Wonka_operator_onEnd
+
include Wonka_operator_onPush
+
include Wonka_operator_onStart
include Wonka_operator_scan
include Wonka_operator_share
include Wonka_operator_skip
···
include Wonka_operator_takeLast
include Wonka_operator_takeUntil
include Wonka_operator_takeWhile
-
include Wonka_operator_tap
-
include Wonka_operator_tapAll
(* sinks *)
include Wonka_sink_publish