type-plus
    Preparing search index...

    Type Alias SplitAt<A, Index, DeleteCount, Insert>

    SplitAt: IsArray<
        A,
        {
            $else: ArrayPlus.SplitAt._<
                A,
                [],
                [],
                ArrayPlus.IndexAt._<A, Index>,
                DeleteCount,
                Insert,
            >;
            $then: [A, A];
            exact: true;
        },
    >

    ⚗️ transform

    Splits array or tuple A into two at the specified Index.

    If the Index is out of bounds, it will set to the boundary value.

    It is the type level splice().

    Type Parameters

    • A extends readonly unknown[]
    • Index extends number
    • DeleteCount extends number | never = never
    • Insert extends readonly unknown[] | never = never
    SplitAt<[1, 2, 3, 4, 5], 2> // [[1, 2], [3, 4, 5]]
    SplitAt<[1, 2, 3, 4, 5], -3> // [[1, 2], [3, 4, 5]]

    SplitAt<[1, 2, 3, 4, 5], 2, 2> // [[1, 2, 5], [3, 4]]

    SplitAt<[1, 2, 3, 4, 5], 2, 2, ['a', 'b']> // [[1, 2, 'a', 'b', 5], [3, 4]]

    // out of bound resets to boundary
    SplitAt<[1, 2, 3, 4, 5], 6> // [[1, 2, 3, 4, 5], []]
    SplitAt<[1, 2, 3, 4, 5], -6> // [[], [1, 2, 3, 4, 5]]