aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoris2025-03-23 13:02:09 +0100
committerJoris2025-03-23 13:02:09 +0100
commit9c1c50c30bc4a74851338f9bb844ee625ba0bd65 (patch)
treefee3db18188d899948fc31d122219f307be44bbe /src
parentf144db6f109807cc9a60ed766090df2b3ec9d139 (diff)
Add map2, map3, map4 and map5
Diffstat (limited to 'src')
-rw-r--r--src/rx.ts16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/rx.ts b/src/rx.ts
index afcebac..db91bdb 100644
--- a/src/rx.ts
+++ b/src/rx.ts
@@ -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