From 9c1c50c30bc4a74851338f9bb844ee625ba0bd65 Mon Sep 17 00:00:00 2001
From: Joris
Date: Sun, 23 Mar 2025 13:02:09 +0100
Subject: Add map2, map3, map4 and map5
---
src/rx.ts | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
(limited to 'src')
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 {
}
}
+export function map2(rx: [Rx, Rx], f: (a: A, b: B) => C): Rx {
+ return rx[0].flatMap(a => rx[1].map(b => f(a, b)))
+}
+
+export function map3(rx: [Rx, Rx, Rx], f: (a: A, b: B, c: C) => D): Rx {
+ return rx[0].flatMap(a => rx[1].flatMap(b => rx[2].map(c => f(a, b, c))))
+}
+
+export function map4(rx: [Rx, Rx, Rx, Rx], f: (a: A, b: B, c: C, d: D) => E): Rx {
+ 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(rx: [Rx, Rx, Rx, Rx, Rx], f: (a: A, b: B, c: C, d: D, e: E) => F): Rx {
+ 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 extends Rx {
readonly type: 'Pure'
readonly value: A
--
cgit v1.2.3