ts-data-forge 12.2.1 → 12.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -6
- package/dist/array/impl/array-utils-creation.d.mts +1 -1
- package/dist/array/impl/array-utils-creation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-element-access.d.mts +1 -1
- package/dist/array/impl/array-utils-element-access.d.mts.map +1 -1
- package/dist/array/impl/array-utils-element-access.mjs +10 -13
- package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
- package/dist/array/impl/array-utils-iterators.d.mts +1 -1
- package/dist/array/impl/array-utils-iterators.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs +53 -53
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs.map +1 -1
- package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
- package/dist/array/impl/array-utils-modification.mjs +61 -70
- package/dist/array/impl/array-utils-modification.mjs.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.mjs +37 -47
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-search.d.mts.map +1 -1
- package/dist/array/impl/array-utils-search.mjs +80 -92
- package/dist/array/impl/array-utils-search.mjs.map +1 -1
- package/dist/array/impl/array-utils-set-op.d.mts +1 -1
- package/dist/array/impl/array-utils-set-op.d.mts.map +1 -1
- package/dist/array/impl/array-utils-size.d.mts +1 -1
- package/dist/array/impl/array-utils-size.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slice-clamped.mjs +9 -10
- package/dist/array/impl/array-utils-slice-clamped.mjs.map +1 -1
- package/dist/array/impl/array-utils-slicing.d.mts +1 -1
- package/dist/array/impl/array-utils-slicing.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slicing.mjs +20 -32
- package/dist/array/impl/array-utils-slicing.mjs.map +1 -1
- package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-transformation.mjs +41 -52
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
- package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-validation.mjs +10 -16
- package/dist/array/impl/array-utils-validation.mjs.map +1 -1
- package/dist/json/json.mjs +1 -1
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/branded-types/finite-number.d.mts +6 -3
- package/dist/number/branded-types/finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/negative-finite-number.d.mts +8 -4
- package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/negative-int.d.mts +2 -1
- package/dist/number/branded-types/negative-int.d.mts.map +1 -1
- package/dist/number/branded-types/negative-safe-int.d.mts +2 -1
- package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.d.mts +6 -3
- package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.d.mts +6 -3
- package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.d.mts +6 -3
- package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/positive-finite-number.d.mts +6 -3
- package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
- package/dist/number/enum/int8.d.mts +26 -13
- package/dist/number/enum/int8.d.mts.map +1 -1
- package/dist/number/enum/uint8.d.mts +24 -12
- package/dist/number/enum/uint8.d.mts.map +1 -1
- package/dist/others/if-then.d.mts +1 -1
- package/dist/others/if-then.d.mts.map +1 -1
- package/dist/string/str.d.mts.map +1 -1
- package/dist/string/str.mjs +52 -52
- package/dist/string/str.mjs.map +1 -1
- package/package.json +4 -4
- package/src/array/impl/array-utils-element-access.mts +15 -16
- package/src/array/impl/array-utils-length-bounded-array-cast.mts +73 -60
- package/src/array/impl/array-utils-modification.mts +96 -94
- package/src/array/impl/array-utils-reducing-value.mts +68 -57
- package/src/array/impl/array-utils-search.mts +146 -148
- package/src/array/impl/array-utils-slice-clamped.mts +16 -14
- package/src/array/impl/array-utils-slicing.mts +37 -40
- package/src/array/impl/array-utils-transformation.mts +64 -62
- package/src/array/impl/array-utils-transformation.test.mts +1 -1
- package/src/array/impl/array-utils-validation.mts +18 -20
- package/src/collections/iset.test.mts +2 -2
- package/src/functional/pipe.test.mts +1 -1
- package/src/json/json.mts +1 -1
- package/src/string/str.mts +74 -61
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-utils-modification.mjs","sources":["../../../src/array/impl/array-utils-modification.mts"],"sourcesContent":["import {\n type FixedLengthTuple,\n type Increment,\n type IsFixedLengthList,\n type NonEmptyArray,\n type NonEmptyTuple,\n} from 'ts-type-forge';\nimport { asPositiveUint32 } from '../../number/index.mjs';\nimport { castMutable } from '../../others/index.mjs';\nimport {\n type ArgArrayIndex,\n type ArgArrayIndexWithNegative,\n type SizeType,\n} from '../../types.mjs';\nimport { copy, create } from './array-utils-creation.mjs';\n\n/**\n * Returns a new array with an element at the specified index replaced.\n *\n * @example\n *\n * ```ts\n * const scores: readonly number[] = [10, 20, 30] as const;\n *\n * const updated = Arr.set(scores, 1, 25);\n *\n * assert.deepStrictEqual(updated, [10, 25, 30]);\n * ```\n */\nexport function set<const Ar extends readonly unknown[], const V = Ar[number]>(\n array: Ar,\n index: ArgArrayIndex<Ar>,\n newValue: V,\n): IsFixedLengthList<Ar> extends true\n ? Readonly<{ [K in keyof Ar]: Ar[K] | V }>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<Ar[number] | V>\n : readonly (Ar[number] | V)[];\n\n// curried version\nexport function set<const V>(\n index: SizeType.ArgArr,\n newValue: V,\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? Readonly<{ [K in keyof Ar]: Ar[K] | V }>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<Ar[number] | V>\n : readonly (Ar[number] | V)[];\n\nexport function set<E, const V = E>(\n ...args:\n | readonly [array: readonly E[], index: SizeType.ArgArr, newValue: V]\n | readonly [index: SizeType.ArgArr, newValue: V]\n): readonly (E | V)[] | ((array: readonly E[]) => readonly (E | V)[]) {\n switch (args.length) {\n case 3: {\n const [array, index, newValue] = args;\n\n return (array as readonly (E | V)[]).with(index, newValue);\n }\n\n case 2: {\n const [index, newValue] = args;\n\n return (array) => set(array, index, newValue);\n }\n }\n}\n\n/**\n * Returns a new array with an element at the specified index updated by applying a function.\n *\n * @example\n *\n * ```ts\n * const temperatures: readonly number[] = [20, 21, 22] as const;\n *\n * const increased = Arr.toUpdated(temperatures, 1, (value) => value + 5);\n *\n * const incrementLast = Arr.toUpdated<number>(\n * 2,\n * (value) => value + 1,\n * )(temperatures);\n *\n * assert.deepStrictEqual(increased, [20, 26, 22]);\n *\n * assert.deepStrictEqual(incrementLast, [20, 21, 23]);\n * ```\n */\nexport function toUpdated<\n const Ar extends readonly unknown[],\n const V = Ar[number],\n>(\n array: Ar,\n index: ArgArrayIndex<Ar>,\n updater: (prev: Ar[number]) => V,\n): IsFixedLengthList<Ar> extends true\n ? Readonly<{ [K in keyof Ar]: Ar[K] | V }>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<Ar[number] | V>\n : readonly (Ar[number] | V)[];\n\n// curried version\nexport function toUpdated<E, const V = E>(\n index: SizeType.ArgArr,\n updater: (prev: E) => V,\n): <const Ar extends readonly E[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? Readonly<{ [K in keyof Ar]: Ar[K] | V }>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<Ar[number] | V>\n : readonly (Ar[number] | V)[];\n\nexport function toUpdated<E, V = E>(\n ...args:\n | readonly [\n array: readonly E[],\n index: SizeType.ArgArr,\n updater: (prev: E) => V,\n ]\n | readonly [index: SizeType.ArgArr, updater: (prev: E) => V]\n): readonly (E | V)[] | ((array: readonly E[]) => readonly (E | V)[]) {\n switch (args.length) {\n case 3: {\n const [array, index, updater] = args;\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return (array as readonly (E | V)[]).with(index, updater(array[index]!));\n }\n\n case 2: {\n const [index, updater] = args;\n\n return (array) => toUpdated(array, index, updater);\n }\n }\n}\n\n/**\n * Returns a new array with a value inserted at the specified index.\n *\n * @example\n *\n * ```ts\n * const numbers = [1, 2, 4] as const;\n *\n * const withThree = Arr.toInserted(numbers, 2, 3);\n *\n * const appendFive = Arr.toInserted(3, 5)(numbers);\n *\n * assert.deepStrictEqual(withThree, [1, 2, 3, 4]);\n *\n * assert.deepStrictEqual(appendFive, [1, 2, 4, 5]);\n * ```\n */\nexport function toInserted<\n const Ar extends readonly unknown[],\n const V = Ar[number],\n>(\n array: Ar,\n index: ArgArrayIndexWithNegative<Ar>,\n newValue: V,\n): IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<CastToNumber<Increment<Ar['length']>>, Ar[number] | V>\n : NonEmptyArray<Ar[number] | V>;\n\n// curried version\nexport function toInserted<const V>(\n index: SizeType.ArgArrWithNegative,\n newValue: V,\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<CastToNumber<Increment<Ar['length']>>, Ar[number] | V>\n : NonEmptyArray<Ar[number] | V>;\n\nexport function toInserted<E, const V = E>(\n ...args:\n | readonly [\n array: readonly E[],\n index: SizeType.ArgArrWithNegative,\n newValue: V,\n ]\n | readonly [index: SizeType.ArgArrWithNegative, newValue: V]\n): NonEmptyArray<E | V> | ((array: readonly E[]) => NonEmptyArray<E | V>) {\n switch (args.length) {\n case 3: {\n const [array, index, newValue] = args;\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return (array as readonly (E | V)[]).toSpliced(\n index,\n 0,\n newValue,\n ) as unknown as NonEmptyArray<E | V>;\n }\n\n case 2: {\n const [index, newValue] = args;\n\n return (array) => toInserted(array, index, newValue);\n }\n }\n}\n\ntype CastToNumber<T> = T extends number ? T : never;\n\n/**\n * Returns a new array with the element at the specified index removed.\n *\n * @example\n *\n * ```ts\n * const letters = ['a', 'b', 'c', 'd'] as const;\n *\n * const withoutSecond = Arr.toRemoved(letters, 1);\n *\n * const withoutFirstCurried = Arr.toRemoved(0)(letters);\n *\n * assert.deepStrictEqual(withoutSecond, ['a', 'c', 'd']);\n *\n * assert.deepStrictEqual(withoutFirstCurried, ['b', 'c', 'd']);\n * ```\n */\nexport function toRemoved<const Ar extends readonly unknown[]>(\n array: Ar,\n index: ArgArrayIndexWithNegative<Ar>,\n): readonly Ar[number][];\n\nexport function toRemoved(\n index: SizeType.ArgArrWithNegative,\n): <E>(array: readonly E[]) => readonly E[];\n\nexport function toRemoved<E>(\n ...args:\n | readonly [array: readonly E[], index: SizeType.ArgArrWithNegative]\n | readonly [index: SizeType.ArgArrWithNegative]\n): readonly E[] | ((array: readonly E[]) => readonly E[]) {\n switch (args.length) {\n case 2: {\n const [array, index] = args;\n\n return array.toSpliced(index, 1);\n }\n\n case 1: {\n const [index] = args;\n\n return (array) => toRemoved(array, index);\n }\n }\n}\n\n/**\n * Returns a new array with a value appended to the end.\n *\n * @example\n *\n * ```ts\n * const base = [1, 2] as const;\n *\n * const appended = Arr.toPushed(base, 3);\n *\n * const appendedCurried = Arr.toPushed(4)(base);\n *\n * // The result is guaranteed non-empty, so it is assignable to NonEmptyArray.\n * const nonEmpty: NonEmptyArray<number> = appended;\n *\n * assert.deepStrictEqual<readonly number[]>(appended, [1, 2, 3]);\n *\n * assert.deepStrictEqual<readonly number[]>(appendedCurried, [1, 2, 4]);\n *\n * assert.isTrue(nonEmpty.length >= 1);\n * ```\n */\nexport function toPushed<const Ar extends readonly unknown[], const V>(\n array: Ar,\n newValue: V,\n): readonly [...Ar, V] & NonEmptyArray<Ar[number] | V>;\n\nexport function toPushed<const V>(\n newValue: V,\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => readonly [...Ar, V] & NonEmptyArray<Ar[number] | V>;\n\nexport function toPushed<const Ar extends readonly unknown[], const V>(\n ...args: readonly [array: Ar, newValue: V] | readonly [newValue: V]\n): readonly [...Ar, V] | ((array: Ar) => readonly [...Ar, V]) {\n switch (args.length) {\n case 2: {\n const [array, newValue] = args;\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return array.toSpliced(array.length, 0, newValue) as unknown as readonly [\n ...Ar,\n V,\n ];\n }\n\n case 1: {\n const [newValue] = args;\n\n return (array) => toPushed(array, newValue);\n }\n }\n}\n\n/**\n * Returns a new array with a value prepended to the beginning.\n *\n * @example\n *\n * ```ts\n * const base = [2, 3] as const;\n *\n * const prefixed = Arr.toUnshifted(base, 1);\n *\n * const prefixedCurried = Arr.toUnshifted(0)(base);\n *\n * // The result is guaranteed non-empty, so it is assignable to NonEmptyArray.\n * const nonEmpty: NonEmptyArray<number> = prefixed;\n *\n * assert.deepStrictEqual<readonly number[]>(prefixed, [1, 2, 3]);\n *\n * assert.deepStrictEqual<readonly number[]>(prefixedCurried, [0, 2, 3]);\n *\n * assert.isTrue(nonEmpty.length >= 1);\n * ```\n */\nexport function toUnshifted<const Ar extends readonly unknown[], const V>(\n array: Ar,\n newValue: V,\n): readonly [V, ...Ar] & NonEmptyArray<V | Ar[number]>;\n\nexport function toUnshifted<const V>(\n newValue: V,\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => readonly [V, ...Ar] & NonEmptyArray<V | Ar[number]>;\n\nexport function toUnshifted<Ar extends readonly unknown[], const V>(\n ...args: readonly [array: Ar, newValue: V] | readonly [newValue: V]\n): readonly [V, ...Ar] | ((array: Ar) => readonly [V, ...Ar]) {\n switch (args.length) {\n case 2: {\n const [array, newValue] = args;\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return array.toSpliced(0, 0, newValue) as unknown as readonly [V, ...Ar];\n }\n\n case 1: {\n const [newValue] = args;\n\n return (array) => toUnshifted(array, newValue);\n }\n }\n}\n\n/**\n * Returns a new array with all elements replaced by the specified value.\n *\n * @example\n *\n * ```ts\n * const base = [1, 2, 3] as const;\n *\n * const filled = Arr.toFilled(base, 0);\n *\n * const filledCurried = Arr.toFilled('x')(base);\n *\n * assert.deepStrictEqual(filled, [0, 0, 0]);\n *\n * assert.deepStrictEqual(filledCurried, ['x', 'x', 'x']);\n * ```\n */\nexport function toFilled<const Ar extends readonly unknown[], const V>(\n array: Ar,\n value: V,\n): IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<Ar['length'], V>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<V>\n : readonly V[];\n\n// curried version\nexport function toFilled<const V>(\n value: V,\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<Ar['length'], V>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<V>\n : readonly V[];\n\nexport function toFilled<E>(\n ...args: readonly [array: readonly E[], value: E] | readonly [value: E]\n): readonly E[] | ((array: readonly E[]) => readonly E[]) {\n switch (args.length) {\n case 2: {\n const [array, value] = args;\n\n return create(asPositiveUint32(array.length), value);\n }\n\n case 1: {\n const [value] = args;\n\n return (array) => toFilled(array, value);\n }\n }\n}\n\n/**\n * Returns a new array with elements in the specified range replaced by the specified value.\n *\n * @example\n *\n * ```ts\n * const base = [0, 1, 2, 3, 4] as const;\n *\n * const filledMiddle = Arr.toRangeFilled(base, 9, [1, 4]);\n *\n * const filledPrefix = Arr.toRangeFilled(8, [0, 2])(base);\n *\n * assert.deepStrictEqual(filledMiddle, [0, 9, 9, 9, 4]);\n *\n * assert.deepStrictEqual(filledPrefix, [8, 8, 2, 3, 4]);\n * ```\n */\nexport function toRangeFilled<const Ar extends readonly unknown[], const V>(\n array: Ar,\n value: V,\n fillRange: readonly [\n start: ArgArrayIndexWithNegative<Ar>,\n end: ArgArrayIndexWithNegative<Ar>,\n ],\n): IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<Ar['length'], V | Ar[number]>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<V | Ar[number]>\n : readonly (V | Ar[number])[];\n\n// curried version\nexport function toRangeFilled<const V>(\n value: V,\n fillRange: readonly [\n start: SizeType.ArgArrWithNegative,\n end: SizeType.ArgArrWithNegative,\n ],\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<Ar['length'], V | Ar[number]>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<V | Ar[number]>\n : readonly (V | Ar[number])[];\n\nexport function toRangeFilled<E, const V>(\n ...args:\n | readonly [\n array: readonly E[],\n value: V,\n fillRange: readonly [\n start: SizeType.ArgArrWithNegative,\n end: SizeType.ArgArrWithNegative,\n ],\n ]\n | readonly [\n value: V,\n fillRange: readonly [\n start: SizeType.ArgArrWithNegative,\n end: SizeType.ArgArrWithNegative,\n ],\n ]\n): readonly (E | V)[] | ((array: readonly E[]) => readonly (E | V)[]) {\n switch (args.length) {\n case 3: {\n const [array, value, [start, end]] = args;\n\n const mut_cp: (E | V)[] = castMutable(copy(array));\n\n mut_cp.fill(value, start, end);\n\n return mut_cp;\n }\n\n case 2: {\n const [value, fillRange] = args;\n\n return (array) => toRangeFilled(array, value, fillRange);\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDO,SAAS,OACX,IAAA,EAGiE;AACpE,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,KAAA,EAAO,KAAA,EAAO,QAAQ,CAAA,GAAI,IAAA;AAEjC,MAAA,OAAQ,KAAA,CAA6B,IAAA,CAAK,KAAA,EAAO,QAAQ,CAAA;AAAA,IAC3D;AAAA,IAEA,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,KAAA,EAAO,QA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AK,CAAA,GAAI,IAAA;AAEvB,MAAA,OAAO,MAAA,CAAO,gBAAA,CAAiB,KAAA,CAAM,MAAM,GAAG,KAAK,CAAA;AAAA,IACrD;AAAA,IAEA,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,KAAK,CAAA,GAAI,IAAA;AAEhB,MAAA,OAAO,CAAC,KAAA,KAAU,QAAA,CAAS,KAAA,EAAO,KAAK,CAAA;AAAA,IACzC;AAAA;AAEJ;AA+CO,SAAS,iBACX,IAAA,EAgBiE;AACpE,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,KAAA,EAAO,KAAA,EAAO,CAAC,KAAA,EAAO,GAAG,CAAC,CAAA,GAAI,IAAA;AAErC,MAAA,MAAM,MAAA,GAAoB,WAAA,CAAY,IAAA,CAAK,KAAK,CAAC,CAAA;AAEjD,MAAA,MAAA,CAAO,IAAA,CAAK,KAAA,EAAO,KAAA,EAAO,GAAG,CAAA;AAE7B,MAAA,OAAO,MAAA;AAAA,IACT;AAAA,IAEA,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,KAAA,EAAO,SAAS,CAAA,GAAI,IAAA;AAE3B,MAAA,OAAO,CAAC,KAAA,KAAU,aAAA,CAAc,KAAA,EAAO,OAAO,SAAS,CAAA;AAAA,IACzD;AAAA;AAEJ;;;;"}
|
|
1
|
+
{"version":3,"file":"array-utils-modification.mjs","sources":["../../../src/array/impl/array-utils-modification.mts"],"sourcesContent":["import {\n type FixedLengthTuple,\n type Increment,\n type IsFixedLengthList,\n type NonEmptyArray,\n type NonEmptyTuple,\n} from 'ts-type-forge';\nimport { asPositiveUint32 } from '../../number/index.mjs';\nimport { castMutable } from '../../others/index.mjs';\nimport {\n type ArgArrayIndex,\n type ArgArrayIndexWithNegative,\n type SizeType,\n} from '../../types.mjs';\nimport { copy, create } from './array-utils-creation.mjs';\n\n/**\n * Returns a new array with an element at the specified index replaced.\n *\n * @example\n *\n * ```ts\n * const scores: readonly number[] = [10, 20, 30] as const;\n *\n * const updated = Arr.set(scores, 1, 25);\n *\n * assert.deepStrictEqual(updated, [10, 25, 30]);\n * ```\n */\nexport function set<const Ar extends readonly unknown[], const V = Ar[number]>(\n array: Ar,\n index: ArgArrayIndex<Ar>,\n newValue: V,\n): IsFixedLengthList<Ar> extends true\n ? Readonly<{ [K in keyof Ar]: Ar[K] | V }>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<Ar[number] | V>\n : readonly (Ar[number] | V)[];\n\n// curried version\nexport function set<const V>(\n index: SizeType.ArgArr,\n newValue: V,\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? Readonly<{ [K in keyof Ar]: Ar[K] | V }>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<Ar[number] | V>\n : readonly (Ar[number] | V)[];\n\nexport function set<E, const V = E>(\n ...args:\n | readonly [array: readonly E[], index: SizeType.ArgArr, newValue: V]\n | readonly [index: SizeType.ArgArr, newValue: V]\n): readonly (E | V)[] | ((array: readonly E[]) => readonly (E | V)[]) {\n switch (args.length) {\n case 3:\n return setImpl(...args);\n\n case 2:\n return (array) => setImpl(array, ...args);\n }\n}\n\nconst setImpl = <E, const V = E>(\n array: readonly E[],\n index: SizeType.ArgArr,\n newValue: V,\n): readonly (E | V)[] => (array as readonly (E | V)[]).with(index, newValue);\n\n/**\n * Returns a new array with an element at the specified index updated by applying a function.\n *\n * @example\n *\n * ```ts\n * const temperatures: readonly number[] = [20, 21, 22] as const;\n *\n * const increased = Arr.toUpdated(temperatures, 1, (value) => value + 5);\n *\n * const incrementLast = Arr.toUpdated<number>(\n * 2,\n * (value) => value + 1,\n * )(temperatures);\n *\n * assert.deepStrictEqual(increased, [20, 26, 22]);\n *\n * assert.deepStrictEqual(incrementLast, [20, 21, 23]);\n * ```\n */\nexport function toUpdated<\n const Ar extends readonly unknown[],\n const V = Ar[number],\n>(\n array: Ar,\n index: ArgArrayIndex<Ar>,\n updater: (prev: Ar[number]) => V,\n): IsFixedLengthList<Ar> extends true\n ? Readonly<{ [K in keyof Ar]: Ar[K] | V }>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<Ar[number] | V>\n : readonly (Ar[number] | V)[];\n\n// curried version\nexport function toUpdated<E, const V = E>(\n index: SizeType.ArgArr,\n updater: (prev: E) => V,\n): <const Ar extends readonly E[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? Readonly<{ [K in keyof Ar]: Ar[K] | V }>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<Ar[number] | V>\n : readonly (Ar[number] | V)[];\n\nexport function toUpdated<E, V = E>(\n ...args:\n | readonly [\n array: readonly E[],\n index: SizeType.ArgArr,\n updater: (prev: E) => V,\n ]\n | readonly [index: SizeType.ArgArr, updater: (prev: E) => V]\n): readonly (E | V)[] | ((array: readonly E[]) => readonly (E | V)[]) {\n switch (args.length) {\n case 3:\n return toUpdatedImpl(...args);\n\n case 2:\n return (array) => toUpdatedImpl(array, ...args);\n }\n}\n\nconst toUpdatedImpl = <E, V = E>(\n array: readonly E[],\n index: SizeType.ArgArr,\n updater: (prev: E) => V,\n): readonly (E | V)[] =>\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n (array as readonly (E | V)[]).with(index, updater(array[index]!));\n\n/**\n * Returns a new array with a value inserted at the specified index.\n *\n * @example\n *\n * ```ts\n * const numbers = [1, 2, 4] as const;\n *\n * const withThree = Arr.toInserted(numbers, 2, 3);\n *\n * const appendFive = Arr.toInserted(3, 5)(numbers);\n *\n * assert.deepStrictEqual(withThree, [1, 2, 3, 4]);\n *\n * assert.deepStrictEqual(appendFive, [1, 2, 4, 5]);\n * ```\n */\nexport function toInserted<\n const Ar extends readonly unknown[],\n const V = Ar[number],\n>(\n array: Ar,\n index: ArgArrayIndexWithNegative<Ar>,\n newValue: V,\n): IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<CastToNumber<Increment<Ar['length']>>, Ar[number] | V>\n : NonEmptyArray<Ar[number] | V>;\n\n// curried version\nexport function toInserted<const V>(\n index: SizeType.ArgArrWithNegative,\n newValue: V,\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<CastToNumber<Increment<Ar['length']>>, Ar[number] | V>\n : NonEmptyArray<Ar[number] | V>;\n\nexport function toInserted<E, const V = E>(\n ...args:\n | readonly [\n array: readonly E[],\n index: SizeType.ArgArrWithNegative,\n newValue: V,\n ]\n | readonly [index: SizeType.ArgArrWithNegative, newValue: V]\n): NonEmptyArray<E | V> | ((array: readonly E[]) => NonEmptyArray<E | V>) {\n switch (args.length) {\n case 3:\n return toInsertedImpl(...args);\n\n case 2:\n return (array) => toInsertedImpl(array, ...args);\n }\n}\n\nconst toInsertedImpl = <E, const V = E>(\n array: readonly E[],\n index: SizeType.ArgArrWithNegative,\n newValue: V,\n): NonEmptyArray<E | V> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n (array as readonly (E | V)[]).toSpliced(\n index,\n 0,\n newValue,\n ) as unknown as NonEmptyArray<E | V>;\n\ntype CastToNumber<T> = T extends number ? T : never;\n\n/**\n * Returns a new array with the element at the specified index removed.\n *\n * @example\n *\n * ```ts\n * const letters = ['a', 'b', 'c', 'd'] as const;\n *\n * const withoutSecond = Arr.toRemoved(letters, 1);\n *\n * const withoutFirstCurried = Arr.toRemoved(0)(letters);\n *\n * assert.deepStrictEqual(withoutSecond, ['a', 'c', 'd']);\n *\n * assert.deepStrictEqual(withoutFirstCurried, ['b', 'c', 'd']);\n * ```\n */\nexport function toRemoved<const Ar extends readonly unknown[]>(\n array: Ar,\n index: ArgArrayIndexWithNegative<Ar>,\n): readonly Ar[number][];\n\nexport function toRemoved(\n index: SizeType.ArgArrWithNegative,\n): <E>(array: readonly E[]) => readonly E[];\n\nexport function toRemoved<E>(\n ...args:\n | readonly [array: readonly E[], index: SizeType.ArgArrWithNegative]\n | readonly [index: SizeType.ArgArrWithNegative]\n): readonly E[] | ((array: readonly E[]) => readonly E[]) {\n switch (args.length) {\n case 2:\n return toRemovedImpl(...args);\n\n case 1:\n return (array) => toRemovedImpl(array, ...args);\n }\n}\n\nconst toRemovedImpl = <E,>(\n array: readonly E[],\n index: SizeType.ArgArrWithNegative,\n): readonly E[] => array.toSpliced(index, 1);\n\n/**\n * Returns a new array with a value appended to the end.\n *\n * @example\n *\n * ```ts\n * const base = [1, 2] as const;\n *\n * const appended = Arr.toPushed(base, 3);\n *\n * const appendedCurried = Arr.toPushed(4)(base);\n *\n * // The result is guaranteed non-empty, so it is assignable to NonEmptyArray.\n * const nonEmpty: NonEmptyArray<number> = appended;\n *\n * assert.deepStrictEqual<readonly number[]>(appended, [1, 2, 3]);\n *\n * assert.deepStrictEqual<readonly number[]>(appendedCurried, [1, 2, 4]);\n *\n * assert.isTrue(nonEmpty.length >= 1);\n * ```\n */\nexport function toPushed<const Ar extends readonly unknown[], const V>(\n array: Ar,\n newValue: V,\n): readonly [...Ar, V] & NonEmptyArray<Ar[number] | V>;\n\nexport function toPushed<const V>(\n newValue: V,\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => readonly [...Ar, V] & NonEmptyArray<Ar[number] | V>;\n\nexport function toPushed<const Ar extends readonly unknown[], const V>(\n ...args: readonly [array: Ar, newValue: V] | readonly [newValue: V]\n): readonly [...Ar, V] | ((array: Ar) => readonly [...Ar, V]) {\n switch (args.length) {\n case 2:\n return toPushedImpl(...args);\n\n case 1:\n return (array) => toPushedImpl(array, ...args);\n }\n}\n\nconst toPushedImpl = <const Ar extends readonly unknown[], const V>(\n array: Ar,\n newValue: V,\n): readonly [...Ar, V] =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n array.toSpliced(array.length, 0, newValue) as unknown as readonly [...Ar, V];\n\n/**\n * Returns a new array with a value prepended to the beginning.\n *\n * @example\n *\n * ```ts\n * const base = [2, 3] as const;\n *\n * const prefixed = Arr.toUnshifted(base, 1);\n *\n * const prefixedCurried = Arr.toUnshifted(0)(base);\n *\n * // The result is guaranteed non-empty, so it is assignable to NonEmptyArray.\n * const nonEmpty: NonEmptyArray<number> = prefixed;\n *\n * assert.deepStrictEqual<readonly number[]>(prefixed, [1, 2, 3]);\n *\n * assert.deepStrictEqual<readonly number[]>(prefixedCurried, [0, 2, 3]);\n *\n * assert.isTrue(nonEmpty.length >= 1);\n * ```\n */\nexport function toUnshifted<const Ar extends readonly unknown[], const V>(\n array: Ar,\n newValue: V,\n): readonly [V, ...Ar] & NonEmptyArray<V | Ar[number]>;\n\nexport function toUnshifted<const V>(\n newValue: V,\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => readonly [V, ...Ar] & NonEmptyArray<V | Ar[number]>;\n\nexport function toUnshifted<Ar extends readonly unknown[], const V>(\n ...args: readonly [array: Ar, newValue: V] | readonly [newValue: V]\n): readonly [V, ...Ar] | ((array: Ar) => readonly [V, ...Ar]) {\n switch (args.length) {\n case 2:\n return toUnshiftedImpl(...args);\n\n case 1:\n return (array) => toUnshiftedImpl(array, ...args);\n }\n}\n\nconst toUnshiftedImpl = <Ar extends readonly unknown[], const V>(\n array: Ar,\n newValue: V,\n): readonly [V, ...Ar] =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n array.toSpliced(0, 0, newValue) as unknown as readonly [V, ...Ar];\n\n/**\n * Returns a new array with all elements replaced by the specified value.\n *\n * @example\n *\n * ```ts\n * const base = [1, 2, 3] as const;\n *\n * const filled = Arr.toFilled(base, 0);\n *\n * const filledCurried = Arr.toFilled('x')(base);\n *\n * assert.deepStrictEqual(filled, [0, 0, 0]);\n *\n * assert.deepStrictEqual(filledCurried, ['x', 'x', 'x']);\n * ```\n */\nexport function toFilled<const Ar extends readonly unknown[], const V>(\n array: Ar,\n value: V,\n): IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<Ar['length'], V>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<V>\n : readonly V[];\n\n// curried version\nexport function toFilled<const V>(\n value: V,\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<Ar['length'], V>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<V>\n : readonly V[];\n\nexport function toFilled<E>(\n ...args: readonly [array: readonly E[], value: E] | readonly [value: E]\n): readonly E[] | ((array: readonly E[]) => readonly E[]) {\n switch (args.length) {\n case 2:\n return toFilledImpl(...args);\n\n case 1:\n return (array) => toFilledImpl(array, ...args);\n }\n}\n\nconst toFilledImpl = <E,>(array: readonly E[], value: E): readonly E[] =>\n create(asPositiveUint32(array.length), value);\n\n/**\n * Returns a new array with elements in the specified range replaced by the specified value.\n *\n * @example\n *\n * ```ts\n * const base = [0, 1, 2, 3, 4] as const;\n *\n * const filledMiddle = Arr.toRangeFilled(base, 9, [1, 4]);\n *\n * const filledPrefix = Arr.toRangeFilled(8, [0, 2])(base);\n *\n * assert.deepStrictEqual(filledMiddle, [0, 9, 9, 9, 4]);\n *\n * assert.deepStrictEqual(filledPrefix, [8, 8, 2, 3, 4]);\n * ```\n */\nexport function toRangeFilled<const Ar extends readonly unknown[], const V>(\n array: Ar,\n value: V,\n fillRange: readonly [\n start: ArgArrayIndexWithNegative<Ar>,\n end: ArgArrayIndexWithNegative<Ar>,\n ],\n): IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<Ar['length'], V | Ar[number]>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<V | Ar[number]>\n : readonly (V | Ar[number])[];\n\n// curried version\nexport function toRangeFilled<const V>(\n value: V,\n fillRange: readonly [\n start: SizeType.ArgArrWithNegative,\n end: SizeType.ArgArrWithNegative,\n ],\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? FixedLengthTuple<Ar['length'], V | Ar[number]>\n : Ar extends NonEmptyTuple<unknown>\n ? NonEmptyArray<V | Ar[number]>\n : readonly (V | Ar[number])[];\n\nexport function toRangeFilled<E, const V>(\n ...args:\n | readonly [\n array: readonly E[],\n value: V,\n fillRange: readonly [\n start: SizeType.ArgArrWithNegative,\n end: SizeType.ArgArrWithNegative,\n ],\n ]\n | readonly [\n value: V,\n fillRange: readonly [\n start: SizeType.ArgArrWithNegative,\n end: SizeType.ArgArrWithNegative,\n ],\n ]\n): readonly (E | V)[] | ((array: readonly E[]) => readonly (E | V)[]) {\n switch (args.length) {\n case 3:\n return toRangeFilledImpl(...args);\n\n case 2:\n return (array) => toRangeFilledImpl(array, ...args);\n }\n}\n\nconst toRangeFilledImpl = <E, const V>(\n array: readonly E[],\n value: V,\n fillRange: readonly [\n start: SizeType.ArgArrWithNegative,\n end: SizeType.ArgArrWithNegative,\n ],\n): readonly (E | V)[] => {\n const [start, end] = fillRange;\n\n const mut_cp: (E | V)[] = castMutable(copy(array));\n\n mut_cp.fill(value, start, end);\n\n return mut_cp;\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDO,SAAS,OACX,IAAA,EAGiE;AACpE,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA;AACH,MAAA,OAAO,OAAA,CAAQ,GAAG,IAAI,CAAA;AAAA,IAExB,KAAK,CAAA;AACH,MAAA,OAAO,CAAC,KAAA,KAAU,OAAA,CAAQ,KAAA,EAAO,GAAG,IAAI,CAAA;AAAA;AAE9C;AAEA,MAAM,OAAA,GAAU,CACd,KAAA,EACA,KAAA,EACA,aACwB,KAAA,CAA6B,IAAA,CAAK,OAAO,QAAQ,CAAA;AA+CpE,SAAS,aACX,IAAA,EAOiE;AACpE,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA;AACH,MAAA,OAAO,aAAA,CAAc,GAAG,IAAI,CAAA;AAAA,IAE9B,KAAK,CAAA;AACH,MAAA,OAAO,CAAC,KAAA,KAAU,aAAA,CAAc,KAAA,EAAO,GA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E,CAAC,EACpC,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GACpB,GAAG,CAAC;AAEP,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EACvC,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GACpB,MAAM,CAAC;AASV;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,IAAI,CAClB,KAAK,EAAE,SAAS,OAAO,EAAE,EACzB,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAEzB,wBAAgB,IAAI,CAClB,SAAS,CAAC,EAAE,MAAM,GACjB,CAAC,KAAK,EAAE,SAAS,OAAO,EAAE,KAAK,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AA8CxD;;;;GAIG;AACH,eAAO,MAAM,MAAM,cAAQ,CAAC;AAE5B;;;;GAIG;AACH,eAAO,MAAM,WAAW,cAAQ,CAAC"}
|
|
@@ -77,67 +77,57 @@ function maxBy(array, comparatorValueMapper, comparator) {
|
|
|
77
77
|
}
|
|
78
78
|
function count(...args) {
|
|
79
79
|
switch (args.length) {
|
|
80
|
-
case 2:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
asUint32(0)
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
case 1: {
|
|
88
|
-
const [predicate] = args;
|
|
89
|
-
return (array) => count(array, predicate);
|
|
90
|
-
}
|
|
80
|
+
case 2:
|
|
81
|
+
return countImpl(...args);
|
|
82
|
+
case 1:
|
|
83
|
+
return (array) => countImpl(array, ...args);
|
|
91
84
|
}
|
|
92
85
|
}
|
|
86
|
+
const countImpl = (array, predicate) => array.reduce(
|
|
87
|
+
(acc, curr, index) => predicate(curr, asUint32(index)) ? Uint32.add(acc, 1) : acc,
|
|
88
|
+
asUint32(0)
|
|
89
|
+
);
|
|
93
90
|
function countBy(...args) {
|
|
94
91
|
switch (args.length) {
|
|
95
|
-
case 2:
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const key = grouper(e, asUint32(index));
|
|
100
|
-
const curr = mut_groups.get(key) ?? 0;
|
|
101
|
-
mut_groups.set(key, asUint32(curr + 1));
|
|
102
|
-
}
|
|
103
|
-
return IMap.create(mut_groups);
|
|
104
|
-
}
|
|
105
|
-
case 1: {
|
|
106
|
-
const [grouper] = args;
|
|
107
|
-
return (array) => countBy(array, grouper);
|
|
108
|
-
}
|
|
92
|
+
case 2:
|
|
93
|
+
return countByImpl(...args);
|
|
94
|
+
case 1:
|
|
95
|
+
return (array) => countByImpl(array, ...args);
|
|
109
96
|
}
|
|
110
97
|
}
|
|
98
|
+
const countByImpl = (array, grouper) => {
|
|
99
|
+
const mut_groups = /* @__PURE__ */ new Map();
|
|
100
|
+
for (const [index, e] of array.entries()) {
|
|
101
|
+
const key = grouper(e, asUint32(index));
|
|
102
|
+
const curr = mut_groups.get(key) ?? 0;
|
|
103
|
+
mut_groups.set(key, asUint32(curr + 1));
|
|
104
|
+
}
|
|
105
|
+
return IMap.create(mut_groups);
|
|
106
|
+
};
|
|
111
107
|
function foldl(...args) {
|
|
112
108
|
switch (args.length) {
|
|
113
|
-
case 3:
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
initialValue
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
case 2: {
|
|
121
|
-
const [callbackfn, initialValue] = args;
|
|
122
|
-
return (array) => foldl(array, callbackfn, initialValue);
|
|
123
|
-
}
|
|
109
|
+
case 3:
|
|
110
|
+
return foldlImpl(...args);
|
|
111
|
+
case 2:
|
|
112
|
+
return (array) => foldlImpl(array, ...args);
|
|
124
113
|
}
|
|
125
114
|
}
|
|
115
|
+
const foldlImpl = (array, callbackfn, initialValue) => array.reduce(
|
|
116
|
+
(prev, curr, index) => callbackfn(prev, curr, asUint32(index)),
|
|
117
|
+
initialValue
|
|
118
|
+
);
|
|
126
119
|
function foldr(...args) {
|
|
127
120
|
switch (args.length) {
|
|
128
|
-
case 3:
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
initialValue
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
case 2: {
|
|
136
|
-
const [callbackfn, initialValue] = args;
|
|
137
|
-
return (array) => foldr(array, callbackfn, initialValue);
|
|
138
|
-
}
|
|
121
|
+
case 3:
|
|
122
|
+
return foldrImpl(...args);
|
|
123
|
+
case 2:
|
|
124
|
+
return (array) => foldrImpl(array, ...args);
|
|
139
125
|
}
|
|
140
126
|
}
|
|
127
|
+
const foldrImpl = (array, callbackfn, initialValue) => array.reduceRight(
|
|
128
|
+
(prev, curr, index) => callbackfn(prev, curr, asUint32(index)),
|
|
129
|
+
initialValue
|
|
130
|
+
);
|
|
141
131
|
function sum(array) {
|
|
142
132
|
return array.reduce((prev, curr) => prev + curr, 0);
|
|
143
133
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-utils-reducing-value.mjs","sources":["../../../src/array/impl/array-utils-reducing-value.mts"],"sourcesContent":["import { isError } from '@sindresorhus/is';\nimport { type Int, type NonEmptyTuple, type Uint } from 'ts-type-forge';\nimport { IMap } from '../../collections/index.mjs';\nimport { Optional, Result } from '../../functional/index.mjs';\nimport { isString, isUndefined } from '../../guard/index.mjs';\nimport { asUint32, Num, Uint32 } from '../../number/index.mjs';\nimport { unknownToString } from '../../others/index.mjs';\nimport {\n type ArrayIndex,\n type MapSetKeyType,\n type SizeType,\n type Some,\n} from '../../types.mjs';\nimport { isNonEmpty } from './array-utils-validation.mjs';\n\n/**\n * Finds the minimum value in an array.\n *\n * @example\n *\n * ```ts\n * const values = [5, 3, 9] as const;\n *\n * const empty: readonly number[] = [] as const;\n *\n * const smallest = Arr.min(values);\n *\n * const none = Arr.min(empty);\n *\n * const custom = Arr.min(values, (a, b) => b - a);\n *\n * assert.deepStrictEqual(smallest, Optional.some(3));\n *\n * assert.deepStrictEqual(none, Optional.none);\n *\n * assert.deepStrictEqual(custom, Optional.some(9));\n * ```\n */\nexport function min<const Ar extends readonly number[]>(\n array: Ar,\n // If the array elements are numbers, comparator is optional.\n comparator?: (x: Ar[number], y: Ar[number]) => number,\n): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;\n\nexport function min<const Ar extends readonly unknown[]>(\n array: Ar,\n comparator: (x: Ar[number], y: Ar[number]) => number,\n): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;\n\nexport function min<E extends number>(\n array: readonly E[],\n comparator?: (x: E, y: E) => number,\n): Optional<E> {\n if (!isNonEmpty(array)) {\n return Optional.none;\n }\n\n const cmp = comparator ?? ((x, y) => Num.from(x) - Num.from(y));\n\n return Optional.some(\n array.reduce(\n (currentMin, curr) => (cmp(curr, currentMin) < 0 ? curr : currentMin),\n array[0],\n ),\n );\n}\n\n/**\n * Finds the maximum value in an array.\n *\n * @example\n *\n * ```ts\n * const values = [5, 3, 9] as const;\n *\n * const largest = Arr.max(values);\n *\n * const reversed = Arr.max(values, (a, b) => b - a);\n *\n * assert.deepStrictEqual(largest, Optional.some(9));\n *\n * assert.deepStrictEqual(reversed, Optional.some(3));\n * ```\n */\nexport function max<const Ar extends readonly number[]>(\n array: Ar,\n // If the array elements are numbers, comparator is optional.\n comparator?: (x: Ar[number], y: Ar[number]) => number,\n): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;\n\nexport function max<const Ar extends readonly unknown[]>(\n array: Ar,\n comparator: (x: Ar[number], y: Ar[number]) => number,\n): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;\n\nexport function max<E extends number>(\n array: readonly E[],\n comparator?: (x: E, y: E) => number,\n): Optional<E> {\n const cmp = comparator ?? ((x, y) => Num.from(x) - Num.from(y));\n\n // Find max by finding min with an inverted comparator\n return min(array, (x, y) => -cmp(x, y));\n}\n\n/**\n * Finds the element with the minimum mapped value.\n *\n * @example\n *\n * ```ts\n * const users = [\n * { id: 1, visits: 10 },\n * { id: 2, visits: 3 },\n * { id: 3, visits: 5 },\n * ] as const;\n *\n * const leastVisits = Arr.minBy(users, (user) => user.visits);\n *\n * const custom = Arr.minBy(\n * users,\n * (user) => user.visits,\n * (a, b) => b - a,\n * );\n *\n * assert.deepStrictEqual(leastVisits, Optional.some({ id: 2, visits: 3 }));\n *\n * assert.deepStrictEqual(custom, Optional.some({ id: 1, visits: 10 }));\n * ```\n */\nexport function minBy<const Ar extends readonly unknown[]>(\n array: Ar,\n // If the array elements are mapped to numbers, comparator is optional.\n comparatorValueMapper: (value: Ar[number]) => number,\n): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;\n\nexport function minBy<const Ar extends readonly unknown[], V>(\n array: Ar,\n comparatorValueMapper: (value: Ar[number]) => V,\n comparator: (x: V, y: V) => number,\n): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;\n\nexport function minBy<E, V>(\n array: readonly E[],\n comparatorValueMapper: (value: E) => V,\n comparator?: (x: V, y: V) => number,\n): Optional<E> {\n return min(array, (x, y) =>\n comparator === undefined\n ? Num.from(comparatorValueMapper(x)) - Num.from(comparatorValueMapper(y))\n : comparator(comparatorValueMapper(x), comparatorValueMapper(y)),\n );\n}\n\n/**\n * Finds the element with the maximum mapped value.\n *\n * @example\n *\n * ```ts\n * const projects = [\n * { id: 'a', stars: 10 },\n * { id: 'b', stars: 30 },\n * { id: 'c', stars: 20 },\n * ] as const;\n *\n * const mostStars = Arr.maxBy(projects, (project) => project.stars);\n *\n * const smallestStars = Arr.maxBy(\n * projects,\n * (project) => project.stars,\n * (a, b) => b - a,\n * );\n *\n * assert.deepStrictEqual(mostStars, Optional.some({ id: 'b', stars: 30 }));\n *\n * assert.deepStrictEqual(\n * smallestStars,\n * Optional.some({ id: 'a', stars: 10 }),\n * );\n * ```\n */\nexport function maxBy<const Ar extends readonly unknown[]>(\n array: Ar,\n // If the array elements are mapped to numbers, comparator is optional.\n comparatorValueMapper: (value: Ar[number]) => number,\n): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;\n\nexport function maxBy<const Ar extends readonly unknown[], V>(\n array: Ar,\n comparatorValueMapper: (value: Ar[number]) => V,\n comparator: (x: V, y: V) => number,\n): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;\n\nexport function maxBy<E, V>(\n array: readonly E[],\n comparatorValueMapper: (value: E) => V,\n comparator?: (x: V, y: V) => number,\n): Optional<E> {\n return max(array, (x, y) =>\n comparator === undefined\n ? Num.from(comparatorValueMapper(x)) - Num.from(comparatorValueMapper(y))\n : comparator(comparatorValueMapper(x), comparatorValueMapper(y)),\n );\n}\n\n/**\n * Counts the number of elements that satisfy a predicate.\n *\n * @example\n *\n * ```ts\n * const words = ['Ada', 'Grace', 'Linus'] as const;\n *\n * const longWords = Arr.count(words, (word) => word.length > 4);\n *\n * const withCurried = Arr.count<string>((word) => word.includes('a'))(words);\n *\n * assert.isTrue(longWords === 2);\n *\n * assert.isTrue(withCurried === 2);\n * ```\n */\nexport function count<const Ar extends readonly unknown[]>(\n array: Ar,\n predicate: (value: Ar[number], index: ArrayIndex<Ar>) => boolean,\n): SizeType.Arr;\n\nexport function count<E>(\n predicate: (value: E, index: SizeType.Arr) => boolean,\n): (array: readonly E[]) => SizeType.Arr;\n\nexport function count<E>(\n ...args:\n | readonly [\n array: readonly E[],\n predicate: (value: E, index: SizeType.Arr) => boolean,\n ]\n | readonly [predicate: (value: E, index: SizeType.Arr) => boolean]\n): SizeType.Arr | ((array: readonly E[]) => SizeType.Arr) {\n switch (args.length) {\n case 2: {\n const [array, predicate] = args;\n\n return array.reduce<Uint32>(\n (acc, curr, index) =>\n predicate(curr, asUint32(index)) ? Uint32.add(acc, 1) : acc,\n asUint32(0),\n );\n }\n\n case 1: {\n const [predicate] = args;\n\n return (array) => count(array, predicate);\n }\n }\n}\n\n/**\n * Groups elements by a key and counts the elements in each group.\n *\n * @example\n *\n * ```ts\n * const words = ['Ada', 'Grace', 'Alan', 'Barbara'] as const;\n *\n * const counts = Arr.countBy(words, (word) => word.at(0));\n *\n * assert.deepStrictEqual(counts.get('A'), Optional.some(2));\n *\n * assert.deepStrictEqual(counts.get('G'), Optional.some(1));\n *\n * assert.deepStrictEqual(counts.get('B'), Optional.some(1));\n * ```\n */\nexport function countBy<\n const Ar extends readonly unknown[],\n G extends MapSetKeyType,\n>(\n array: Ar,\n grouper: (value: Ar[number], index: ArrayIndex<Ar>) => G,\n): IMap<G, ArrayIndex<Ar>>;\n\nexport function countBy<E, G extends MapSetKeyType>(\n grouper: (value: E, index: SizeType.Arr) => G,\n): (array: readonly E[]) => IMap<G, SizeType.Arr>;\n\nexport function countBy<E, G extends MapSetKeyType>(\n ...args:\n | readonly [\n array: readonly E[],\n grouper: (value: E, index: SizeType.Arr) => G,\n ]\n | readonly [grouper: (value: E, index: SizeType.Arr) => G]\n): IMap<G, SizeType.Arr> | ((array: readonly E[]) => IMap<G, SizeType.Arr>) {\n switch (args.length) {\n case 2: {\n const [array, grouper] = args;\n\n const mut_groups = new Map<G, SizeType.Arr>();\n\n for (const [index, e] of array.entries()) {\n const key = grouper(e, asUint32(index));\n\n const curr = mut_groups.get(key) ?? 0;\n\n mut_groups.set(key, asUint32(curr + 1));\n }\n\n return IMap.create(mut_groups);\n }\n\n case 1: {\n const [grouper] = args;\n\n return (array) => countBy(array, grouper);\n }\n }\n}\n\n/**\n * Reduces an array to a single value from left to right.\n *\n * @example\n *\n * ```ts\n * const words = ['Ada', 'Lovelace'] as const;\n *\n * const totalLength = Arr.foldl(words, (acc, word) => acc + word.length, 0);\n *\n * const concat = Arr.foldl<string | number, string>(\n * (acc, value) => `${acc}-${value}`,\n * 'items',\n * )(words);\n *\n * assert.isTrue(totalLength === 11);\n *\n * assert.isTrue(concat === 'items-Ada-Lovelace');\n * ```\n */\nexport function foldl<const Ar extends readonly unknown[], P>(\n array: Ar,\n callbackfn: (\n previousValue: P,\n currentValue: Ar[number],\n currentIndex: ArrayIndex<Ar>,\n ) => P,\n initialValue: P,\n): P;\n\nexport function foldl<E, P>(\n callbackfn: (\n previousValue: P,\n currentValue: E,\n currentIndex: SizeType.Arr,\n ) => P,\n initialValue: P,\n): (array: readonly E[]) => P;\n\nexport function foldl<E, P>(\n ...args:\n | readonly [\n array: readonly E[],\n callbackfn: (\n previousValue: P,\n currentValue: E,\n currentIndex: SizeType.Arr,\n ) => P,\n initialValue: P,\n ]\n | readonly [\n callbackfn: (\n previousValue: P,\n currentValue: E,\n currentIndex: SizeType.Arr,\n ) => P,\n initialValue: P,\n ]\n): P | ((array: readonly E[]) => P) {\n switch (args.length) {\n case 3: {\n const [array, callbackfn, initialValue] = args;\n\n return array.reduce(\n (prev, curr, index) => callbackfn(prev, curr, asUint32(index)),\n initialValue,\n );\n }\n\n case 2: {\n const [callbackfn, initialValue] = args;\n\n return (array) => foldl(array, callbackfn, initialValue);\n }\n }\n}\n\n/**\n * Reduces an array to a single value from right to left.\n *\n * @example\n *\n * ```ts\n * const numbers = [1, 2, 3] as const;\n *\n * const subtractRight = Arr.foldr(numbers, (acc, value) => acc - value, 0);\n *\n * const joinFromRight = Arr.foldr<number, string>(\n * (acc, value) => `${acc}${value}`,\n * '',\n * )(numbers);\n *\n * assert.isTrue(subtractRight === -6);\n *\n * assert.isTrue(joinFromRight === '321');\n * ```\n */\nexport function foldr<const Ar extends readonly unknown[], P>(\n array: Ar,\n callbackfn: (\n previousValue: P,\n currentValue: Ar[number],\n currentIndex: ArrayIndex<Ar>,\n ) => P,\n initialValue: P,\n): P;\n\nexport function foldr<E, P>(\n callbackfn: (\n previousValue: P,\n currentValue: E,\n currentIndex: SizeType.Arr,\n ) => P,\n initialValue: P,\n): (array: readonly E[]) => P;\n\nexport function foldr<E, P>(\n ...args:\n | readonly [\n array: readonly E[],\n callbackfn: (\n previousValue: P,\n currentValue: E,\n currentIndex: SizeType.Arr,\n ) => P,\n initialValue: P,\n ]\n | readonly [\n callbackfn: (\n previousValue: P,\n currentValue: E,\n currentIndex: SizeType.Arr,\n ) => P,\n initialValue: P,\n ]\n): P | ((array: readonly E[]) => P) {\n switch (args.length) {\n case 3: {\n const [array, callbackfn, initialValue] = args;\n\n return array.reduceRight(\n (prev, curr, index) => callbackfn(prev, curr, asUint32(index)),\n initialValue,\n );\n }\n\n case 2: {\n const [callbackfn, initialValue] = args;\n\n return (array) => foldr(array, callbackfn, initialValue);\n }\n }\n}\n\n/**\n * Calculates the sum of numbers in an array.\n *\n * @example\n *\n * ```ts\n * const numbers = [1, 2, 3, 4] as const;\n *\n * const negatives = [3, -2, 5] as const;\n *\n * const total = Arr.sum(numbers);\n *\n * const totalNegatives = Arr.sum(negatives);\n *\n * assert.isTrue(total === 10);\n *\n * assert.isTrue(totalNegatives === 6);\n * ```\n */\nexport function sum(array: readonly []): 0;\n\nexport function sum<N extends number>(array: readonly [N]): N;\n\nexport function sum(array: readonly Uint[]): Uint;\n\nexport function sum(array: readonly Int[]): Int;\n\nexport function sum(array: readonly number[]): number;\n\nexport function sum(array: readonly number[]): number {\n return array.reduce((prev, curr) => prev + curr, 0);\n}\n\n/**\n * Calculates the sum of values in an array by applying a mapping function to each element.\n *\n * @example\n *\n * ```ts\n * const numbers = [\n * { value: 1 },\n * { value: 2 },\n * { value: 3 },\n * { value: 4 },\n * ] as const;\n *\n * const negatives = [{ value: 3 }, { value: -2 }, { value: 5 }] as const;\n *\n * const total = Arr.sumBy(numbers, (item) => item.value);\n *\n * const totalNegatives = Arr.sumBy(negatives, (item) => item.value);\n *\n * assert.isTrue(total === 10);\n *\n * assert.isTrue(totalNegatives === 6);\n * ```\n */\nexport function sumBy(array: readonly [], mapFn: (item: unknown) => number): 0;\n\nexport function sumBy<N extends Uint, E>(\n array: readonly E[],\n mapFn: (item: E) => N,\n): Uint;\n\nexport function sumBy<N extends Int, E>(\n array: readonly E[],\n mapFn: (item: E) => N,\n): Int;\n\nexport function sumBy<N extends number, E>(\n array: readonly E[],\n mapFn: (item: E) => N,\n): number;\n\nexport function sumBy<N extends number, E>(\n array: readonly E[],\n mapFn: (item: E) => N,\n): number {\n return array.reduce((prev, curr) => prev + mapFn(curr), 0);\n}\n\n/**\n * Joins array elements into a string.\n *\n * @example\n *\n * ```ts\n * const numbers = [1, 2, 3] as const;\n *\n * const defaultSeparator = Arr.join(numbers);\n *\n * const hyphenSeparated = Arr.join(numbers, '-');\n *\n * assert.deepStrictEqual(defaultSeparator, Result.ok('1,2,3'));\n *\n * assert.deepStrictEqual(hyphenSeparated, Result.ok('1-2-3'));\n * ```\n */\nexport function join(\n array: readonly unknown[],\n separator?: string,\n): Result<string, Error>;\n\nexport function join(\n separator?: string,\n): (array: readonly unknown[]) => Result<string, Error>;\n\nexport function join(\n ...args:\n | readonly [array: readonly unknown[], separator?: string]\n | readonly [separator?: string]\n):\n | Result<string, Error>\n | ((array: readonly unknown[]) => Result<string, Error>) {\n switch (args.length) {\n case 0:\n return (array) => joinImpl(array, undefined);\n\n case 1: {\n const [arg] = args;\n\n if (isString(arg) || isUndefined(arg)) {\n return (array) => joinImpl(array, arg);\n }\n\n return joinImpl(arg, undefined);\n }\n\n case 2: {\n const [array, separator] = args;\n\n return joinImpl(array, separator);\n }\n }\n}\n\nconst joinImpl = (\n array: readonly unknown[],\n separator: string | undefined,\n): Result<string, Error> => {\n try {\n const result = array.join(separator);\n\n return Result.ok(result);\n } catch (error) {\n return Result.err(\n isError(error) ? error : new Error(unknownToString(error)),\n );\n }\n};\n\n/**\n * Alias for `foldl`.\n *\n * @see {@link foldl}\n */\nexport const reduce = foldl;\n\n/**\n * Alias for `foldr`.\n *\n * @see {@link foldr}\n */\nexport const reduceRight = foldr;\n"],"names":["Optional.none","Optional.some","Result.ok","Result.err"],"mappings":";;;;;;;;;;;;;;;;;;;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f,KAAA,EACA,SAAA,KAC0B;AAC1B,EAAA,IAAI;AACF,IAAA,MAAM,MAAA,GAAS,KAAA,CAAM,IAAA,CAAK,SAAS,CAAA;AAEnC,IAAA,OAAOC,GAAU,MAAM,CAAA;AAAA,EACzB,SAAS,KAAA,EAAO;AACd,IAAA,OAAOC,GAAO;AAAA,MACZ,OAAA,CAAQ,KAAK,CAAA,GAAI,KAAA,GAAQ,IAAI,KAAA,CAAM,eAAA,CAAgB,KAAK,CAAC;AAAA,KAC3D;AAAA,EACF;AACF,CAAA;AAOO,MAAM,MAAA,GAAS;AAOf,MAAM,WAAA,GAAc;;;;"}
|
|
1
|
+
{"version":3,"file":"array-utils-reducing-value.mjs","sources":["../../../src/array/impl/array-utils-reducing-value.mts"],"sourcesContent":["import { isError } from '@sindresorhus/is';\nimport { type Int, type NonEmptyTuple, type Uint } from 'ts-type-forge';\nimport { IMap } from '../../collections/index.mjs';\nimport { Optional, Result } from '../../functional/index.mjs';\nimport { isString, isUndefined } from '../../guard/index.mjs';\nimport { asUint32, Num, Uint32 } from '../../number/index.mjs';\nimport { unknownToString } from '../../others/index.mjs';\nimport {\n type ArrayIndex,\n type MapSetKeyType,\n type SizeType,\n type Some,\n} from '../../types.mjs';\nimport { isNonEmpty } from './array-utils-validation.mjs';\n\n/**\n * Finds the minimum value in an array.\n *\n * @example\n *\n * ```ts\n * const values = [5, 3, 9] as const;\n *\n * const empty: readonly number[] = [] as const;\n *\n * const smallest = Arr.min(values);\n *\n * const none = Arr.min(empty);\n *\n * const custom = Arr.min(values, (a, b) => b - a);\n *\n * assert.deepStrictEqual(smallest, Optional.some(3));\n *\n * assert.deepStrictEqual(none, Optional.none);\n *\n * assert.deepStrictEqual(custom, Optional.some(9));\n * ```\n */\nexport function min<const Ar extends readonly number[]>(\n array: Ar,\n // If the array elements are numbers, comparator is optional.\n comparator?: (x: Ar[number], y: Ar[number]) => number,\n): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;\n\nexport function min<const Ar extends readonly unknown[]>(\n array: Ar,\n comparator: (x: Ar[number], y: Ar[number]) => number,\n): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;\n\nexport function min<E extends number>(\n array: readonly E[],\n comparator?: (x: E, y: E) => number,\n): Optional<E> {\n if (!isNonEmpty(array)) {\n return Optional.none;\n }\n\n const cmp = comparator ?? ((x, y) => Num.from(x) - Num.from(y));\n\n return Optional.some(\n array.reduce(\n (currentMin, curr) => (cmp(curr, currentMin) < 0 ? curr : currentMin),\n array[0],\n ),\n );\n}\n\n/**\n * Finds the maximum value in an array.\n *\n * @example\n *\n * ```ts\n * const values = [5, 3, 9] as const;\n *\n * const largest = Arr.max(values);\n *\n * const reversed = Arr.max(values, (a, b) => b - a);\n *\n * assert.deepStrictEqual(largest, Optional.some(9));\n *\n * assert.deepStrictEqual(reversed, Optional.some(3));\n * ```\n */\nexport function max<const Ar extends readonly number[]>(\n array: Ar,\n // If the array elements are numbers, comparator is optional.\n comparator?: (x: Ar[number], y: Ar[number]) => number,\n): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;\n\nexport function max<const Ar extends readonly unknown[]>(\n array: Ar,\n comparator: (x: Ar[number], y: Ar[number]) => number,\n): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;\n\nexport function max<E extends number>(\n array: readonly E[],\n comparator?: (x: E, y: E) => number,\n): Optional<E> {\n const cmp = comparator ?? ((x, y) => Num.from(x) - Num.from(y));\n\n // Find max by finding min with an inverted comparator\n return min(array, (x, y) => -cmp(x, y));\n}\n\n/**\n * Finds the element with the minimum mapped value.\n *\n * @example\n *\n * ```ts\n * const users = [\n * { id: 1, visits: 10 },\n * { id: 2, visits: 3 },\n * { id: 3, visits: 5 },\n * ] as const;\n *\n * const leastVisits = Arr.minBy(users, (user) => user.visits);\n *\n * const custom = Arr.minBy(\n * users,\n * (user) => user.visits,\n * (a, b) => b - a,\n * );\n *\n * assert.deepStrictEqual(leastVisits, Optional.some({ id: 2, visits: 3 }));\n *\n * assert.deepStrictEqual(custom, Optional.some({ id: 1, visits: 10 }));\n * ```\n */\nexport function minBy<const Ar extends readonly unknown[]>(\n array: Ar,\n // If the array elements are mapped to numbers, comparator is optional.\n comparatorValueMapper: (value: Ar[number]) => number,\n): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;\n\nexport function minBy<const Ar extends readonly unknown[], V>(\n array: Ar,\n comparatorValueMapper: (value: Ar[number]) => V,\n comparator: (x: V, y: V) => number,\n): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;\n\nexport function minBy<E, V>(\n array: readonly E[],\n comparatorValueMapper: (value: E) => V,\n comparator?: (x: V, y: V) => number,\n): Optional<E> {\n return min(array, (x, y) =>\n comparator === undefined\n ? Num.from(comparatorValueMapper(x)) - Num.from(comparatorValueMapper(y))\n : comparator(comparatorValueMapper(x), comparatorValueMapper(y)),\n );\n}\n\n/**\n * Finds the element with the maximum mapped value.\n *\n * @example\n *\n * ```ts\n * const projects = [\n * { id: 'a', stars: 10 },\n * { id: 'b', stars: 30 },\n * { id: 'c', stars: 20 },\n * ] as const;\n *\n * const mostStars = Arr.maxBy(projects, (project) => project.stars);\n *\n * const smallestStars = Arr.maxBy(\n * projects,\n * (project) => project.stars,\n * (a, b) => b - a,\n * );\n *\n * assert.deepStrictEqual(mostStars, Optional.some({ id: 'b', stars: 30 }));\n *\n * assert.deepStrictEqual(\n * smallestStars,\n * Optional.some({ id: 'a', stars: 10 }),\n * );\n * ```\n */\nexport function maxBy<const Ar extends readonly unknown[]>(\n array: Ar,\n // If the array elements are mapped to numbers, comparator is optional.\n comparatorValueMapper: (value: Ar[number]) => number,\n): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;\n\nexport function maxBy<const Ar extends readonly unknown[], V>(\n array: Ar,\n comparatorValueMapper: (value: Ar[number]) => V,\n comparator: (x: V, y: V) => number,\n): Ar extends NonEmptyTuple<unknown> ? Some<Ar[number]> : Optional<Ar[number]>;\n\nexport function maxBy<E, V>(\n array: readonly E[],\n comparatorValueMapper: (value: E) => V,\n comparator?: (x: V, y: V) => number,\n): Optional<E> {\n return max(array, (x, y) =>\n comparator === undefined\n ? Num.from(comparatorValueMapper(x)) - Num.from(comparatorValueMapper(y))\n : comparator(comparatorValueMapper(x), comparatorValueMapper(y)),\n );\n}\n\n/**\n * Counts the number of elements that satisfy a predicate.\n *\n * @example\n *\n * ```ts\n * const words = ['Ada', 'Grace', 'Linus'] as const;\n *\n * const longWords = Arr.count(words, (word) => word.length > 4);\n *\n * const withCurried = Arr.count<string>((word) => word.includes('a'))(words);\n *\n * assert.isTrue(longWords === 2);\n *\n * assert.isTrue(withCurried === 2);\n * ```\n */\nexport function count<const Ar extends readonly unknown[]>(\n array: Ar,\n predicate: (value: Ar[number], index: ArrayIndex<Ar>) => boolean,\n): SizeType.Arr;\n\nexport function count<E>(\n predicate: (value: E, index: SizeType.Arr) => boolean,\n): (array: readonly E[]) => SizeType.Arr;\n\nexport function count<E>(\n ...args:\n | readonly [\n array: readonly E[],\n predicate: (value: E, index: SizeType.Arr) => boolean,\n ]\n | readonly [predicate: (value: E, index: SizeType.Arr) => boolean]\n): SizeType.Arr | ((array: readonly E[]) => SizeType.Arr) {\n switch (args.length) {\n case 2:\n return countImpl(...args);\n\n case 1:\n return (array) => countImpl(array, ...args);\n }\n}\n\nconst countImpl = <E,>(\n array: readonly E[],\n predicate: (value: E, index: SizeType.Arr) => boolean,\n): SizeType.Arr =>\n array.reduce<Uint32>(\n (acc, curr, index) =>\n predicate(curr, asUint32(index)) ? Uint32.add(acc, 1) : acc,\n asUint32(0),\n );\n\n/**\n * Groups elements by a key and counts the elements in each group.\n *\n * @example\n *\n * ```ts\n * const words = ['Ada', 'Grace', 'Alan', 'Barbara'] as const;\n *\n * const counts = Arr.countBy(words, (word) => word.at(0));\n *\n * assert.deepStrictEqual(counts.get('A'), Optional.some(2));\n *\n * assert.deepStrictEqual(counts.get('G'), Optional.some(1));\n *\n * assert.deepStrictEqual(counts.get('B'), Optional.some(1));\n * ```\n */\nexport function countBy<\n const Ar extends readonly unknown[],\n G extends MapSetKeyType,\n>(\n array: Ar,\n grouper: (value: Ar[number], index: ArrayIndex<Ar>) => G,\n): IMap<G, ArrayIndex<Ar>>;\n\nexport function countBy<E, G extends MapSetKeyType>(\n grouper: (value: E, index: SizeType.Arr) => G,\n): (array: readonly E[]) => IMap<G, SizeType.Arr>;\n\nexport function countBy<E, G extends MapSetKeyType>(\n ...args:\n | readonly [\n array: readonly E[],\n grouper: (value: E, index: SizeType.Arr) => G,\n ]\n | readonly [grouper: (value: E, index: SizeType.Arr) => G]\n): IMap<G, SizeType.Arr> | ((array: readonly E[]) => IMap<G, SizeType.Arr>) {\n switch (args.length) {\n case 2:\n return countByImpl(...args);\n\n case 1:\n return (array) => countByImpl(array, ...args);\n }\n}\n\nconst countByImpl = <E, G extends MapSetKeyType>(\n array: readonly E[],\n grouper: (value: E, index: SizeType.Arr) => G,\n): IMap<G, SizeType.Arr> => {\n const mut_groups = new Map<G, SizeType.Arr>();\n\n for (const [index, e] of array.entries()) {\n const key = grouper(e, asUint32(index));\n\n const curr = mut_groups.get(key) ?? 0;\n\n mut_groups.set(key, asUint32(curr + 1));\n }\n\n return IMap.create(mut_groups);\n};\n\n/**\n * Reduces an array to a single value from left to right.\n *\n * @example\n *\n * ```ts\n * const words = ['Ada', 'Lovelace'] as const;\n *\n * const totalLength = Arr.foldl(words, (acc, word) => acc + word.length, 0);\n *\n * const concat = Arr.foldl<string | number, string>(\n * (acc, value) => `${acc}-${value}`,\n * 'items',\n * )(words);\n *\n * assert.isTrue(totalLength === 11);\n *\n * assert.isTrue(concat === 'items-Ada-Lovelace');\n * ```\n */\nexport function foldl<const Ar extends readonly unknown[], P>(\n array: Ar,\n callbackfn: (\n previousValue: P,\n currentValue: Ar[number],\n currentIndex: ArrayIndex<Ar>,\n ) => P,\n initialValue: P,\n): P;\n\nexport function foldl<E, P>(\n callbackfn: (\n previousValue: P,\n currentValue: E,\n currentIndex: SizeType.Arr,\n ) => P,\n initialValue: P,\n): (array: readonly E[]) => P;\n\nexport function foldl<E, P>(\n ...args:\n | readonly [\n array: readonly E[],\n callbackfn: (\n previousValue: P,\n currentValue: E,\n currentIndex: SizeType.Arr,\n ) => P,\n initialValue: P,\n ]\n | readonly [\n callbackfn: (\n previousValue: P,\n currentValue: E,\n currentIndex: SizeType.Arr,\n ) => P,\n initialValue: P,\n ]\n): P | ((array: readonly E[]) => P) {\n switch (args.length) {\n case 3:\n return foldlImpl(...args);\n\n case 2:\n return (array) => foldlImpl(array, ...args);\n }\n}\n\nconst foldlImpl = <E, P>(\n array: readonly E[],\n callbackfn: (\n previousValue: P,\n currentValue: E,\n currentIndex: SizeType.Arr,\n ) => P,\n initialValue: P,\n): P =>\n array.reduce(\n (prev, curr, index) => callbackfn(prev, curr, asUint32(index)),\n initialValue,\n );\n\n/**\n * Reduces an array to a single value from right to left.\n *\n * @example\n *\n * ```ts\n * const numbers = [1, 2, 3] as const;\n *\n * const subtractRight = Arr.foldr(numbers, (acc, value) => acc - value, 0);\n *\n * const joinFromRight = Arr.foldr<number, string>(\n * (acc, value) => `${acc}${value}`,\n * '',\n * )(numbers);\n *\n * assert.isTrue(subtractRight === -6);\n *\n * assert.isTrue(joinFromRight === '321');\n * ```\n */\nexport function foldr<const Ar extends readonly unknown[], P>(\n array: Ar,\n callbackfn: (\n previousValue: P,\n currentValue: Ar[number],\n currentIndex: ArrayIndex<Ar>,\n ) => P,\n initialValue: P,\n): P;\n\nexport function foldr<E, P>(\n callbackfn: (\n previousValue: P,\n currentValue: E,\n currentIndex: SizeType.Arr,\n ) => P,\n initialValue: P,\n): (array: readonly E[]) => P;\n\nexport function foldr<E, P>(\n ...args:\n | readonly [\n array: readonly E[],\n callbackfn: (\n previousValue: P,\n currentValue: E,\n currentIndex: SizeType.Arr,\n ) => P,\n initialValue: P,\n ]\n | readonly [\n callbackfn: (\n previousValue: P,\n currentValue: E,\n currentIndex: SizeType.Arr,\n ) => P,\n initialValue: P,\n ]\n): P | ((array: readonly E[]) => P) {\n switch (args.length) {\n case 3:\n return foldrImpl(...args);\n\n case 2:\n return (array) => foldrImpl(array, ...args);\n }\n}\n\nconst foldrImpl = <E, P>(\n array: readonly E[],\n callbackfn: (\n previousValue: P,\n currentValue: E,\n currentIndex: SizeType.Arr,\n ) => P,\n initialValue: P,\n): P =>\n array.reduceRight(\n (prev, curr, index) => callbackfn(prev, curr, asUint32(index)),\n initialValue,\n );\n\n/**\n * Calculates the sum of numbers in an array.\n *\n * @example\n *\n * ```ts\n * const numbers = [1, 2, 3, 4] as const;\n *\n * const negatives = [3, -2, 5] as const;\n *\n * const total = Arr.sum(numbers);\n *\n * const totalNegatives = Arr.sum(negatives);\n *\n * assert.isTrue(total === 10);\n *\n * assert.isTrue(totalNegatives === 6);\n * ```\n */\nexport function sum(array: readonly []): 0;\n\nexport function sum<N extends number>(array: readonly [N]): N;\n\nexport function sum(array: readonly Uint[]): Uint;\n\nexport function sum(array: readonly Int[]): Int;\n\nexport function sum(array: readonly number[]): number;\n\nexport function sum(array: readonly number[]): number {\n return array.reduce((prev, curr) => prev + curr, 0);\n}\n\n/**\n * Calculates the sum of values in an array by applying a mapping function to each element.\n *\n * @example\n *\n * ```ts\n * const numbers = [\n * { value: 1 },\n * { value: 2 },\n * { value: 3 },\n * { value: 4 },\n * ] as const;\n *\n * const negatives = [{ value: 3 }, { value: -2 }, { value: 5 }] as const;\n *\n * const total = Arr.sumBy(numbers, (item) => item.value);\n *\n * const totalNegatives = Arr.sumBy(negatives, (item) => item.value);\n *\n * assert.isTrue(total === 10);\n *\n * assert.isTrue(totalNegatives === 6);\n * ```\n */\nexport function sumBy(array: readonly [], mapFn: (item: unknown) => number): 0;\n\nexport function sumBy<N extends Uint, E>(\n array: readonly E[],\n mapFn: (item: E) => N,\n): Uint;\n\nexport function sumBy<N extends Int, E>(\n array: readonly E[],\n mapFn: (item: E) => N,\n): Int;\n\nexport function sumBy<N extends number, E>(\n array: readonly E[],\n mapFn: (item: E) => N,\n): number;\n\nexport function sumBy<N extends number, E>(\n array: readonly E[],\n mapFn: (item: E) => N,\n): number {\n return array.reduce((prev, curr) => prev + mapFn(curr), 0);\n}\n\n/**\n * Joins array elements into a string.\n *\n * @example\n *\n * ```ts\n * const numbers = [1, 2, 3] as const;\n *\n * const defaultSeparator = Arr.join(numbers);\n *\n * const hyphenSeparated = Arr.join(numbers, '-');\n *\n * assert.deepStrictEqual(defaultSeparator, Result.ok('1,2,3'));\n *\n * assert.deepStrictEqual(hyphenSeparated, Result.ok('1-2-3'));\n * ```\n */\nexport function join(\n array: readonly unknown[],\n separator?: string,\n): Result<string, Error>;\n\nexport function join(\n separator?: string,\n): (array: readonly unknown[]) => Result<string, Error>;\n\nexport function join(\n ...args:\n | readonly [array: readonly unknown[], separator?: string]\n | readonly [separator?: string]\n):\n | Result<string, Error>\n | ((array: readonly unknown[]) => Result<string, Error>) {\n switch (args.length) {\n case 0:\n return (array) => joinImpl(array, undefined);\n\n case 1: {\n const [arg] = args;\n\n if (isString(arg) || isUndefined(arg)) {\n return (array) => joinImpl(array, arg);\n }\n\n return joinImpl(arg, undefined);\n }\n\n case 2: {\n const [array, separator] = args;\n\n return joinImpl(array, separator);\n }\n }\n}\n\nconst joinImpl = (\n array: readonly unknown[],\n separator: string | undefined,\n): Result<string, Error> => {\n try {\n const result = array.join(separator);\n\n return Result.ok(result);\n } catch (error) {\n return Result.err(\n isError(error) ? error : new Error(unknownToString(error)),\n );\n }\n};\n\n/**\n * Alias for `foldl`.\n *\n * @see {@link foldl}\n */\nexport const reduce = foldl;\n\n/**\n * Alias for `foldr`.\n *\n * @see {@link foldr}\n */\nexport const reduceRight = foldr;\n"],"names":["Optional.none","Optional.some","Result.ok","Result.err"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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
predicate
|
|
49
|
-
);
|
|
50
|
-
return foundIndex === -1 ? none : (
|
|
51
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
52
|
-
some(array[foundIndex])
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
case 1: {
|
|
56
|
-
const [predicate] = args;
|
|
57
|
-
return (array) => find(array, predicate);
|
|
58
|
-
}
|
|
44
|
+
case 2:
|
|
45
|
+
return findImpl(...args);
|
|
46
|
+
case 1:
|
|
47
|
+
return (array) => findImpl(array, ...args);
|
|
59
48
|
}
|
|
60
49
|
}
|
|
50
|
+
const findImpl = (array, predicate) => {
|
|
51
|
+
const foundIndex = array.findIndex(
|
|
52
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
53
|
+
predicate
|
|
54
|
+
);
|
|
55
|
+
return foundIndex === -1 ? none : (
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
57
|
+
some(array[foundIndex])
|
|
58
|
+
);
|
|
59
|
+
};
|
|
61
60
|
function findLast(...args) {
|
|
62
61
|
switch (args.length) {
|
|
63
|
-
case 2:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
predicate
|
|
68
|
-
);
|
|
69
|
-
return foundIndex === -1 ? none : (
|
|
70
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
71
|
-
some(array[foundIndex])
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
case 1: {
|
|
75
|
-
const [predicate] = args;
|
|
76
|
-
return (array) => findLast(array, predicate);
|
|
77
|
-
}
|
|
62
|
+
case 2:
|
|
63
|
+
return findLastImpl(...args);
|
|
64
|
+
case 1:
|
|
65
|
+
return (array) => findLastImpl(array, ...args);
|
|
78
66
|
}
|
|
79
67
|
}
|
|
68
|
+
const findLastImpl = (array, predicate) => {
|
|
69
|
+
const foundIndex = array.findLastIndex(
|
|
70
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
71
|
+
predicate
|
|
72
|
+
);
|
|
73
|
+
return foundIndex === -1 ? none : (
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
75
|
+
some(array[foundIndex])
|
|
76
|
+
);
|
|
77
|
+
};
|
|
80
78
|
function findIndex(...args) {
|
|
81
79
|
switch (args.length) {
|
|
82
|
-
case 2:
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
87
|
-
predicate
|
|
88
|
-
)
|
|
89
|
-
).map((idx) => idx >= 0 ? asUint32(idx) : -1).value;
|
|
90
|
-
}
|
|
91
|
-
case 1: {
|
|
92
|
-
const [predicate] = args;
|
|
93
|
-
return (array) => findIndex(array, predicate);
|
|
94
|
-
}
|
|
80
|
+
case 2:
|
|
81
|
+
return findIndexImpl(...args);
|
|
82
|
+
case 1:
|
|
83
|
+
return (array) => findIndexImpl(array, ...args);
|
|
95
84
|
}
|
|
96
85
|
}
|
|
86
|
+
const findIndexImpl = (array, predicate) => pipe(
|
|
87
|
+
array.findIndex(
|
|
88
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
89
|
+
predicate
|
|
90
|
+
)
|
|
91
|
+
).map((idx) => idx >= 0 ? asUint32(idx) : -1).value;
|
|
97
92
|
function findLastIndex(...args) {
|
|
98
93
|
switch (args.length) {
|
|
99
|
-
case 2:
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
104
|
-
predicate
|
|
105
|
-
)
|
|
106
|
-
).map((idx) => idx >= 0 ? asUint32(idx) : -1).value;
|
|
107
|
-
}
|
|
108
|
-
case 1: {
|
|
109
|
-
const [predicate] = args;
|
|
110
|
-
return (array) => findLastIndex(array, predicate);
|
|
111
|
-
}
|
|
94
|
+
case 2:
|
|
95
|
+
return findLastIndexImpl(...args);
|
|
96
|
+
case 1:
|
|
97
|
+
return (array) => findLastIndexImpl(array, ...args);
|
|
112
98
|
}
|
|
113
99
|
}
|
|
100
|
+
const findLastIndexImpl = (array, predicate) => pipe(
|
|
101
|
+
array.findLastIndex(
|
|
102
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
103
|
+
predicate
|
|
104
|
+
)
|
|
105
|
+
).map((idx) => idx >= 0 ? asUint32(idx) : -1).value;
|
|
114
106
|
function indexOf(...args) {
|
|
115
107
|
switch (args.length) {
|
|
116
|
-
case 2:
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return
|
|
120
|
-
}
|
|
121
|
-
case 1: {
|
|
122
|
-
const [searchElement] = args;
|
|
123
|
-
return (array) => indexOf(array, searchElement);
|
|
124
|
-
}
|
|
108
|
+
case 2:
|
|
109
|
+
return indexOfImpl(...args);
|
|
110
|
+
case 1:
|
|
111
|
+
return (array) => indexOfImpl(array, ...args);
|
|
125
112
|
}
|
|
126
113
|
}
|
|
114
|
+
const indexOfImpl = (array, searchElement) => {
|
|
115
|
+
const index = array.indexOf(searchElement);
|
|
116
|
+
return index !== -1 ? asUint32(index) : -1;
|
|
117
|
+
};
|
|
127
118
|
function indexOfFrom(...args) {
|
|
128
119
|
switch (args.length) {
|
|
129
|
-
case 3:
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return
|
|
133
|
-
}
|
|
134
|
-
case 2: {
|
|
135
|
-
const [searchElement, fromIndex] = args;
|
|
136
|
-
return (array) => indexOfFrom(array, searchElement, fromIndex);
|
|
137
|
-
}
|
|
120
|
+
case 3:
|
|
121
|
+
return indexOfFromImpl(...args);
|
|
122
|
+
case 2:
|
|
123
|
+
return (array) => indexOfFromImpl(array, ...args);
|
|
138
124
|
}
|
|
139
125
|
}
|
|
126
|
+
const indexOfFromImpl = (array, searchElement, fromIndex) => {
|
|
127
|
+
const index = array.indexOf(searchElement, fromIndex);
|
|
128
|
+
return index !== -1 ? asUint32(index) : -1;
|
|
129
|
+
};
|
|
140
130
|
function lastIndexOf(...args) {
|
|
141
131
|
switch (args.length) {
|
|
142
|
-
case 2:
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return
|
|
146
|
-
}
|
|
147
|
-
case 1: {
|
|
148
|
-
const [searchElement] = args;
|
|
149
|
-
return (array) => lastIndexOf(array, searchElement);
|
|
150
|
-
}
|
|
132
|
+
case 2:
|
|
133
|
+
return lastIndexOfImpl(...args);
|
|
134
|
+
case 1:
|
|
135
|
+
return (array) => lastIndexOfImpl(array, ...args);
|
|
151
136
|
}
|
|
152
137
|
}
|
|
138
|
+
const lastIndexOfImpl = (array, searchElement) => {
|
|
139
|
+
const index = array.lastIndexOf(searchElement);
|
|
140
|
+
return index !== -1 ? asUint32(index) : -1;
|
|
141
|
+
};
|
|
153
142
|
function lastIndexOfFrom(...args) {
|
|
154
143
|
switch (args.length) {
|
|
155
|
-
case 3:
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return
|
|
159
|
-
}
|
|
160
|
-
case 2: {
|
|
161
|
-
const [searchElement, fromIndex] = args;
|
|
162
|
-
return (array) => lastIndexOfFrom(array, searchElement, fromIndex);
|
|
163
|
-
}
|
|
144
|
+
case 3:
|
|
145
|
+
return lastIndexOfFromImpl(...args);
|
|
146
|
+
case 2:
|
|
147
|
+
return (array) => lastIndexOfFromImpl(array, ...args);
|
|
164
148
|
}
|
|
165
149
|
}
|
|
150
|
+
const lastIndexOfFromImpl = (array, searchElement, fromIndex) => {
|
|
151
|
+
const index = array.lastIndexOf(searchElement, fromIndex);
|
|
152
|
+
return index !== -1 ? asUint32(index) : -1;
|
|
153
|
+
};
|
|
166
154
|
|
|
167
155
|
export { find, findIndex, findLast, findLastIndex, indexOf, indexOfFrom, lastIndexOf, lastIndexOfFrom };
|
|
168
156
|
//# sourceMappingURL=array-utils-search.mjs.map
|