• Passes inputs through a function before handing them to the given index. If the function returns undefined, the input is ignored.

    Type Parameters

    • In

    • Out

    • InnerIn

    • Inner extends Index<InnerIn, Out, Inner>

    Parameters

    • f: ((_) => undefined | InnerIn)
        • (_): undefined | InnerIn
        • Parameters

          • _: In

          Returns undefined | InnerIn

    • inner: UnregisteredIndex<InnerIn, Out, Inner>

    Returns UnregisteredIndex<In, Out, PremapIndex<In, Out, InnerIn, Inner>>

    Example

    const collection = new Collection<Readonly<{
    name: string,
    age: number,
    }>>();

    // Ensure all names are unique
    const ixUniqueNames = collection.registerIndex(
    premap(
    p.name,
    uniqueHashIndex()
    )
    );

    // Maintain the number of adults
    const ixAdultCount = collection.registerIndex(
    premap(
    p => p.age >= 18 ? p : undefined,
    countIndex()
    )
    );

    console.log(ixAdultCount.get().value);

Generated using TypeDoc