Documentation
    Preparing search index...

    Type Alias DictionariesAPI

    Actual Type: Struct
    Note: Stripped to generate better documentation.

    The API for Dictionarys.

    The Serializable equivalent of a vanilla JavaScript Map.

    type DictionariesAPI = {
        create: <T extends Serializable>(
            iterable?: Iterable<readonly [string, T]> | null,
        ) => Dictionary<T>;
        groupBy: <T extends Serializable>(
            items: Iterable<T>,
            callback:
                | ((item: T, index: number) => string)
                | Method<(item: T, index: number) => string>,
        ) => Dictionary<List<T[]>>;
    }
    Index

    Properties

    Properties

    create: <T extends Serializable>(
        iterable?: Iterable<readonly [string, T]> | null,
    ) => Dictionary<T>

    Actual Type: Method
    Note: Stripped to generate better documentation.

    Creates a Dictionary.

    Type Declaration

      • <T extends Serializable>(
            iterable?: Iterable<readonly [string, T]> | null,
        ): Dictionary<T>
      • Type Parameters

        Parameters

        • Optionaliterable: Iterable<readonly [string, T]> | null

          An iterable that yields [key, value] entries which will be used to create the initial state of the Dictionary. keys must be strings and values must be Serializable.

          If not provided, the Dictionary is constructed with no entries.

        Returns Dictionary<T>

        A Dictionary.

    const { containers } = createFutureMachine(db);

    const dictionary = containers.dictionary.create<number>([
    ['hello', 1],
    ['world', 2],
    ]);
    groupBy: <T extends Serializable>(
        items: Iterable<T>,
        callback:
            | ((item: T, index: number) => string)
            | Method<(item: T, index: number) => string>,
    ) => Dictionary<List<T[]>>

    Actual Type: Method
    Note: Stripped to generate better documentation.

    Creates a Dictionary by grouping items according to the keys returned by callback.

    Type Declaration

      • <T extends Serializable>(
            items: Iterable<T>,
            callback:
                | ((item: T, index: number) => string)
                | Method<(item: T, index: number) => string>,
        ): Dictionary<List<T[]>>
      • Type Parameters

        Parameters

        • items: Iterable<T>

          An iterable that yields the values that will be grouped by callback.

          Can only contain Serializable values

        • callback:
              | ((item: T, index: number) => string)
              | Method<(item: T, index: number) => string>

          Called for each item of items, returns the group the item belongs to.

        Returns Dictionary<List<T[]>>

        A Dictionary containing the groups.

    const { containers } = createFutureMachine(db);

    const items: number[] = [0,1,2,3,4,5,6,7,8,9];

    const groups = containers.dictionary.groupBy(items, (item) => {
    return item % 2 === 0 ? 'even' : 'odd';
    });
    // groups is a Dictionary containing List components:
    // 'even' -> List([0, 2, 4, 6, 8])
    // 'odd' -> List([1, 3, 5, 7, 9])