ts-data-forge
    Preparing search index...
    • Returns a new array with a value prepended to the beginning.

      Type Parameters

      • const Ar extends readonly unknown[]
      • const V

      Parameters

      • array: Ar
      • newValue: V

      Returns readonly [V, Ar] & readonly [V | Ar[number], V | Ar[number]] & Readonly<
          { MinLength: readonly [0, 0] },
      > & Readonly<
          {
              "TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3": unknown;
          },
      >

      const base = [2, 3] as const;

      const prefixed = Arr.toUnshifted(base, 1);

      const prefixedCurried = Arr.toUnshifted(0)(base);

      // The result is guaranteed non-empty, so it is assignable to NonEmptyArray.
      const nonEmpty: NonEmptyArray<number> = prefixed;

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

      assert.deepStrictEqual<readonly number[]>(prefixedCurried, [0, 2, 3]);

      assert.isTrue(nonEmpty.length >= 1);
    • Returns a new array with a value prepended to the beginning.

      Type Parameters

      • const V

      Parameters

      • newValue: V

      Returns <const Ar extends readonly unknown[]>(
          array: Ar,
      ) => readonly [V, Ar] & readonly [V | Ar[number], V | Ar[number]] & Readonly<
          { MinLength: readonly [0, 0] },
      > & Readonly<
          {
              "TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3": unknown;
          },
      >

      const base = [2, 3] as const;

      const prefixed = Arr.toUnshifted(base, 1);

      const prefixedCurried = Arr.toUnshifted(0)(base);

      // The result is guaranteed non-empty, so it is assignable to NonEmptyArray.
      const nonEmpty: NonEmptyArray<number> = prefixed;

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

      assert.deepStrictEqual<readonly number[]>(prefixedCurried, [0, 2, 3]);

      assert.isTrue(nonEmpty.length >= 1);