Skip to content

Instantly share code, notes, and snippets.

@jhusain
Last active November 29, 2017 01:26
Show Gist options
  • Save jhusain/fe7db6efd31b53e8f0fc58d1e7f4e6df to your computer and use it in GitHub Desktop.
Save jhusain/fe7db6efd31b53e8f0fc58d1e7f4e6df to your computer and use it in GitHub Desktop.
class Observable<T, E> {
// cant be typed in flow, but perhaps we can
// somehow declare several overloads?
// pipe(Observable<T0, E0> => Observable<T1, E1>): Observable<T1, E1>
// pipe(Observable<T0, E0> => Observable<T1, E1>, Observable<T1, E1> => Observable<T2, E2>): Observable<T2, E2>
// etc...
pipe(...operators) {
return operators.reduce((acc, curr) => curr(acc), this);
}
}
// example: outputs an Observable of 2,3,4
Observable.
of(1,2,3).
// map returns Observable<T, E> => Observable<R, E> (faking partial application in JS)
pipe(map(x => x + 1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment