Function tuple

  • Creates a tuple from the given arguments, preserving tuple types for better type inference. Useful when working with sequences that need to maintain tuple types, especially when using toMap.

    Type Parameters

    • T extends any[]

    Parameters

    • Rest ...args: T

      Arguments to create a tuple from

    Returns T

    Tuple of the arguments

    Example

    // Preserves tuple type [string, number] instead of (string | number)[]
    const result = sequenceOf(["a", 1], ["b", 2])
    .mapNotNull(([key, value]) => value > 0 ? tuple(key, value) : null)
    .toMap();
    // result: Map<string, number>