UNPKG

resig.js

Version:

Universal reactive signal library with complete platform features: signals, animations, CRDTs, scheduling, DOM integration. Works identically across React, SolidJS, Svelte, Vue, and Qwik.

36 lines (35 loc) 1.25 kB
/** * Effect Monad - Extends Signal with monadic composition * Following monadic laws for effect composition */ import { MutableSignal } from './signal'; export interface Effect<A> extends MutableSignal<A> { readonly bind: <B>(f: (a: A) => Effect<B>) => Effect<B>; readonly chain: <B>(f: (a: A) => Effect<B>) => Effect<B>; } /** * Creates an Effect that follows monadic laws * Laws verified: * - bind(pure(a), f) ≡ f(a) (left identity) * - bind(ma, pure) ≡ ma (right identity) * - bind(bind(ma, f), g) ≡ bind(ma, λa. bind(f(a), g)) (associativity) */ export declare const effect: <A>(initial: A) => Effect<A> & { _set: (value: A) => void; }; /** * Lifts a value into Effect context (pure for Effect monad) */ export declare const pureEffect: <A>(value: A) => Effect<A>; /** * Flattens nested Effects (join operation) */ export declare const flatten: <A>(nestedEffect: Effect<Effect<A>>) => Effect<A>; /** * Applies a function wrapped in an Effect to a value wrapped in an Effect */ export declare const apply: <A, B>(effectF: Effect<(a: A) => B>, effectA: Effect<A>) => Effect<B>; /** * Sequences an array of Effects into an Effect of array */ export declare const sequence: <A>(effects: Effect<A>[]) => Effect<A[]>;