variable / @typed/async-data

map

Maps successful and every optimistic value while preserving state structure.

Package version
1.0.0-beta.7
Category
Value transformations
Since
1.0.0

Import

import { map } from "@typed/async-data";

Signatures

export declare const map: {
    <A, B>(f: (a: A) => B): <E>(data: AsyncData<A, E>) => AsyncData<B, E>;
    <A, E, B>(data: AsyncData<A, E>, f: (a: A) => B): AsyncData<B, E>;
};

Why

Value transformations should not erase progress, Causes, or optimistic rollback history. Cyclic history throws TypeError.

Ownership and lifetime

This pure transformation acquires no resources and returns new plain wrappers.

Examples

import { map, success } from "@typed/async-data"
const state = map(success(2), (n) => n * 2)

Source