@b-jones-rfd/func-help - v0.7.1
    Preparing search index...

    Interface Monad<T>

    The shape every monad in this package has: map and bind.

    TypeScript has no higher-kinded types, so bind here accepts any Monad<U>; each class narrows it to its own type. Code written against Monad (as Do is) can't stop a caller mixing kinds.

    import { IO, type Monad } from '@b-jones-rfd/func-help'
    const m: Monad<number> = IO.of(1).map((n) => n + 1)
    interface Monad<T> {
        bind<U>(f: (t: T) => Monad<U>): Monad<U>;
        map<U>(f: (t: T) => U): Monad<U>;
    }

    Type Parameters

    • T

      The value the monad carries.

    Implemented by

    Index
    • Chains a step that itself returns a monad, flattening the result so contexts don't nest. Haskell's >>=.

      Type Parameters

      • U

        The value the returned monad carries.

      Parameters

      • f: (t: T) => Monad<U>

        Applied to the carried value; returns the next monad.

      Returns Monad<U>

      The monad f returns, sequenced after this one.

    • Transforms the carried value, keeping the monad's context.

      Type Parameters

      • U

        The type f returns.

      Parameters

      • f: (t: T) => U

        Applied to the carried value.

      Returns Monad<U>

      A monad of the same kind carrying f's result.