type-alias / @typed/fx/Fx

fn.NonGen

Contract for functions whose body returns an Fx directly.

Package version
2.0.0-beta.7
Category
Type contracts
Since
1.0.0
Member of
fn

Import

import { fn } from "@typed/fx/Fx";

Access fn.NonGen through the imported fn export. Its declaration below describes the member.

Signatures

type NonGen = {
    <Args extends Array<any>, ReturnFx extends Fx.Any>(body: (this: unassigned, ...args: Args) => ReturnFx): (...args: Args) => ReturnFx;
    <Self, Args extends Array<any>, ReturnFx extends Fx.Any>(body: (this: Self, ...args: Args) => ReturnFx): (this: Self, ...args: Args) => ReturnFx;
    <Args extends Array<any>, ReturnFx extends Fx.Any, A>(body: (this: unassigned, ...args: Args) => ReturnFx, a: (_: ReturnFx, ...args: Args) => A): (...args: Args) => A;
    <Self, Args extends Array<any>, ReturnFx extends Fx.Any, A>(body: (this: Self, ...args: Args) => ReturnFx, a: (_: ReturnFx, ...args: Args) => A): (this: Self, ...args: Args) => A;
    <Args extends Array<any>, ReturnFx extends Fx.Any, A, B>(body: (this: unassigned, ...args: Args) => ReturnFx, a: (_: ReturnFx, ...args: Args) => A, b: (_: A, ...args: Args) => B): (...args: Args) => B;
    <Self, Args extends Array<any>, ReturnFx extends Fx.Any, A, B>(body: (this: Self, ...args: Args) => ReturnFx, a: (_: ReturnFx, ...args: Args) => A, b: (_: A, ...args: Args) => B): (this: Self, ...args: Args) => B;
    <Args extends Array<any>, ReturnFx extends Fx.Any, A, B, C>(body: (this: unassigned, ...args: Args) => ReturnFx, a: (_: ReturnFx, ...args: Args) => A, b: (_: A, ...args: Args) => B, c: (_: B, ...args: Args) => C): (...args: Args) => C;
    <Self, Args extends Array<any>, ReturnFx extends Fx.Any, A, B, C>(body: (this: Self, ...args: Args) => ReturnFx, a: (_: ReturnFx, ...args: Args) => A, b: (_: A, ...args: Args) => B, c: (_: B, ...args: Args) => C): (this: Self, ...args: Args) => C;
};

Why

NonGen adds Effect-style tracing and a typed pipeline to ordinary Fx factories without forcing a generator when no Effect acquisition is needed.

Ownership and lifetime

Defining and invoking the function are both inert. Invocation returns an Fx without evaluating body; Effect.fn suspends it. Each run evaluates the body once, then runs its returned producer in that same ownership and interruption lifetime.

Examples

import { Fx } from "@typed/fx"

let bodyCalls = 0
const greeting = Fx.fn(
  (name: string) => {
    bodyCalls += 1
    return Fx.succeed(name)
  },
  (source) => Fx.map(source, (name) => `hello ${name}`)
)
const source = greeting("Ada") // bodyCalls is still 0
const program = Fx.collectAll(source) // running program increments bodyCalls

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source