diff options
-rw-r--r-- | src/rx.ts | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -175,6 +175,22 @@ export class Rx<A> { } } +export function map2<A, B, C>(rx: [Rx<A>, Rx<B>], f: (a: A, b: B) => C): Rx<C> { + return rx[0].flatMap(a => rx[1].map(b => f(a, b))) +} + +export function map3<A, B, C, D>(rx: [Rx<A>, Rx<B>, Rx<C>], f: (a: A, b: B, c: C) => D): Rx<D> { + return rx[0].flatMap(a => rx[1].flatMap(b => rx[2].map(c => f(a, b, c)))) +} + +export function map4<A, B, C, D, E>(rx: [Rx<A>, Rx<B>, Rx<C>, Rx<D>], f: (a: A, b: B, c: C, d: D) => E): Rx<E> { + return rx[0].flatMap(a => rx[1].flatMap(b => rx[2].flatMap(c => rx[3].map(d => f(a, b, c, d))))) +} + +export function map5<A, B, C, D, E, F>(rx: [Rx<A>, Rx<B>, Rx<C>, Rx<D>, Rx<E>], f: (a: A, b: B, c: C, d: D, e: E) => F): Rx<F> { + return rx[0].flatMap(a => rx[1].flatMap(b => rx[2].flatMap(c => rx[3].flatMap(d => rx[4].map(e => f(a, b, c, d, e)))))) +} + class Pure<A> extends Rx<A> { readonly type: 'Pure' readonly value: A |