ts-data-forge
    Preparing search index...
    • Partitions an array into sub-arrays of a specified size.

      Type Parameters

      • E
      • N extends WithSmallInt<
            number & {
                "!=0": true;
                "<=0": false;
                "> -2^16": true;
                "> -2^32": true;
                ">= -2^15": true;
                ">= -2^31": true;
                ">=0": true;
                Finite: true;
                Int: true;
                NaNValue: false;
            } & Readonly<
                {
                    "TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3": unknown;
                },
            > & {
                "< 2^32": true;
                "> -2^16": true;
                "> -2^32": true;
                ">= -2^15": true;
                ">= -2^31": true;
                ">=0": true;
                Finite: true;
                Int: true;
                NaNValue: false;
                SafeInt: true;
            },
        >

      Parameters

      • array: readonly E[]
      • chunkSize: N

      Returns readonly PartitionChunk<N, E>[]

      const values = [1, 2, 3, 4, 5] as const;

      const pairs = Arr.partition(values, 2);

      const triples = Arr.partition(3)(values);

      // Every chunk is branded `BoundedLengthArray<1, N, …>` — `partition` never
      // emits an empty chunk — so the expected values are annotated with the
      // unbranded type.
      const expectedPairs = [[1, 2], [3, 4], [5]] as const;

      assert.deepStrictEqual<readonly (readonly number[])[]>(
      pairs,
      expectedPairs,
      );

      assert.deepStrictEqual<readonly (readonly number[])[]>(triples, [
      [1, 2, 3],
      [4, 5],
      ]);

      const pairs2 = Arr.chunk([1, 2, 3, 4, 5, 6], 2);

      assert.deepStrictEqual<readonly (readonly number[])[]>(pairs2, [
      [1, 2],
      [3, 4],
      [5, 6],
      ]);
    • Partitions an array into sub-arrays of a specified size.

      Type Parameters

      • N extends WithSmallInt<
            number & {
                "!=0": true;
                "<=0": false;
                "> -2^16": true;
                "> -2^32": true;
                ">= -2^15": true;
                ">= -2^31": true;
                ">=0": true;
                Finite: true;
                Int: true;
                NaNValue: false;
            } & Readonly<
                {
                    "TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3": unknown;
                },
            > & {
                "< 2^32": true;
                "> -2^16": true;
                "> -2^32": true;
                ">= -2^15": true;
                ">= -2^31": true;
                ">=0": true;
                Finite: true;
                Int: true;
                NaNValue: false;
                SafeInt: true;
            },
        >

      Parameters

      • chunkSize: N

      Returns <E>(array: readonly E[]) => readonly PartitionChunk<N, E>[]

      const values = [1, 2, 3, 4, 5] as const;

      const pairs = Arr.partition(values, 2);

      const triples = Arr.partition(3)(values);

      // Every chunk is branded `BoundedLengthArray<1, N, …>` — `partition` never
      // emits an empty chunk — so the expected values are annotated with the
      // unbranded type.
      const expectedPairs = [[1, 2], [3, 4], [5]] as const;

      assert.deepStrictEqual<readonly (readonly number[])[]>(
      pairs,
      expectedPairs,
      );

      assert.deepStrictEqual<readonly (readonly number[])[]>(triples, [
      [1, 2, 3],
      [4, 5],
      ]);

      const pairs2 = Arr.chunk([1, 2, 3, 4, 5, 6], 2);

      assert.deepStrictEqual<readonly (readonly number[])[]>(pairs2, [
      [1, 2],
      [3, 4],
      [5, 6],
      ]);