Created
February 14, 2024 14:21
-
-
Save maxsei/b925e56fc881cd2e829bd90e9cf02c64 to your computer and use it in GitHub Desktop.
attempt at using an object with merge function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { labeled, pairs, mapA } from "@thi.ng/transducers"; | |
| import { | |
| merge, | |
| TransformableOpts, | |
| ISubscribable, | |
| Subscription, | |
| } from "@thi.ng/rstream"; | |
| import { IObjectOf, Pair } from "@thi.ng/api"; | |
| type MappedSubcribable<K, V> = { | |
| [P in K]: ISubscribable<V>; | |
| }; | |
| export const mergeKeyed = <K, V>( | |
| obj: MappedSubcribable<K, V>, | |
| ): Subscription<any, Pair<K, V>> => | |
| merge({ src: mapA(([k, v]) => v.transform(labeled(k)), pairs(x)) }); | |
| mergeKeyed({ a: reactive(42), b: reactive("abc") }).map((x) => { | |
| switch (k) { | |
| case "a": | |
| x; // (parameter) x: Pair<"a" | "b", unknown> | |
| case "b": | |
| default: | |
| throw new Error("unreachable"); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment