@softwareventures/array
Advanced tools
Comparing version
@@ -50,3 +50,7 @@ import { Comparator } from "@softwareventures/ordered"; | ||
export declare function filterFn<T>(predicate: (element: T, index: number) => boolean): (array: ArrayLike<T>) => T[]; | ||
/** @deprecated This function is confusing, use {@link excludeFirst} instead, | ||
* and invert the predicate. */ | ||
export declare function filterFirst<T>(array: ArrayLike<T>, predicate: (element: T, index: number) => boolean): T[]; | ||
/** @deprecated This function is confusing, use {@link excludeFirstFn} instead, | ||
* and invert the predicate. */ | ||
export declare function filterFirstFn<T>(predicate: (element: T, index: number) => boolean): (array: ArrayLike<T>) => T[]; | ||
@@ -80,4 +84,8 @@ export declare function exclude<T, U>(array: ArrayLike<T | U>, predicate: (element: T | U) => element is T): U[]; | ||
export declare function indexOfFn<T>(value: T): (array: ArrayLike<T>) => number | null; | ||
export declare function lastIndexOf<T>(array: ArrayLike<T>, value: T): number | null; | ||
export declare function lastIndexOfFn<T>(value: T): (array: ArrayLike<T>) => number | null; | ||
export declare function findIndex<T>(array: ArrayLike<T>, predicate: (element: T, index: number) => boolean): number | null; | ||
export declare function findIndexFn<T>(predicate: (element: T, index: number) => boolean): (array: ArrayLike<T>) => number | null; | ||
export declare function findLastIndex<T>(array: ArrayLike<T>, predicate: (element: T, index: number) => boolean): number | null; | ||
export declare function findLastIndexFn<T>(predicate: (element: T, index: number) => boolean): (array: ArrayLike<T>) => number | null; | ||
export declare function find<T, U extends T>(array: ArrayLike<T>, predicate: (element: T) => element is U): U | null; | ||
@@ -87,2 +95,6 @@ export declare function find<T>(array: ArrayLike<T>, predicate: (element: T, index: number) => boolean): T | null; | ||
export declare function findFn<T>(predicate: (element: T, index: number) => boolean): (array: ArrayLike<T>) => T | null; | ||
export declare function findLast<T, U extends T>(array: ArrayLike<T>, predicate: (element: T) => element is U): U | null; | ||
export declare function findLast<T>(array: ArrayLike<T>, predicate: (element: T, index: number) => boolean): T | null; | ||
export declare function findLastFn<T, U extends T>(predicate: (element: T) => element is U): (array: ArrayLike<T>) => U | null; | ||
export declare function findLastFn<T>(predicate: (element: T, index: number) => boolean): (array: ArrayLike<T>) => T | null; | ||
export declare function maximum<T extends string | number | boolean>(array: ArrayLike<T>): T | null; | ||
@@ -92,2 +104,4 @@ export declare function maximum<T>(array: ArrayLike<T>, compare: Comparator<T>): T | null; | ||
export declare function maximumFn<T>(compare: Comparator<T>): (array: ArrayLike<T>) => T | null; | ||
export declare function maximumBy<T>(array: ArrayLike<T>, select: (element: T) => number): T | null; | ||
export declare function maximumByFn<T>(select: (element: T) => number): (array: ArrayLike<T>) => T | null; | ||
export declare function minimum<T extends string | number | boolean>(array: ArrayLike<T>): T | null; | ||
@@ -97,4 +111,7 @@ export declare function minimum<T>(array: ArrayLike<T>, compare: Comparator<T>): T | null; | ||
export declare function minimumFn<T>(compare: Comparator<T>): (array: ArrayLike<T>) => T | null; | ||
export declare function minimumBy<T>(array: ArrayLike<T>, select: (element: T) => number): T | null; | ||
export declare function minimumByFn<T>(select: (element: T) => number): (array: ArrayLike<T>) => T | null; | ||
export declare function sum(array: ArrayLike<number>): number; | ||
export declare function product(array: ArrayLike<number>): number; | ||
export declare function average(array: ArrayLike<number>): number | null; | ||
export declare function and(array: ArrayLike<boolean>): boolean; | ||
@@ -101,0 +118,0 @@ export declare function or(array: ArrayLike<boolean>): boolean; |
75
index.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.removeFn = exports.remove = exports.excludeFirstFn = exports.excludeFirst = exports.excludeNull = exports.excludeFn = exports.exclude = exports.filterFirstFn = exports.filterFirst = exports.filterFn = exports.filter = exports.mapFn = exports.map = exports.prefixMatchFn = exports.prefixMatch = exports.notEqualFn = exports.notEqual = exports.equalFn = exports.equal = exports.dropUntilFn = exports.dropUntil = exports.dropWhileFn = exports.dropWhile = exports.takeUntilFn = exports.takeUntil = exports.takeWhileFn = exports.takeWhile = exports.dropFn = exports.drop = exports.takeFn = exports.take = exports.sliceFn = exports.slice = exports.reverse = exports.notEmpty = exports.empty = exports.only = exports.last = exports.initial = exports.unshiftFn = exports.unshift = exports.pushFn = exports.push = exports.tail = exports.head = exports.first = exports.coerce = exports.isArrayLike = exports.isArray = exports.copy = void 0; | ||
exports.splitFn = exports.split = exports.scanRight1Fn = exports.scanRight1 = exports.scanRightFn = exports.scanRight = exports.scan1Fn = exports.scan1 = exports.scanFn = exports.scan = exports.noneNull = exports.concatMapFn = exports.concatMap = exports.append = exports.prepend = exports.concat = exports.allFn = exports.all = exports.anyFn = exports.any = exports.or = exports.and = exports.product = exports.sum = exports.minimumFn = exports.minimum = exports.maximumFn = exports.maximum = exports.findFn = exports.find = exports.findIndexFn = exports.findIndex = exports.indexOfFn = exports.indexOf = exports.containsFn = exports.contains = exports.foldMapRightFn = exports.foldMapRight = exports.foldMapFn = exports.foldMap = exports.foldRight1Fn = exports.foldRight1 = exports.foldRightFn = exports.foldRight = exports.fold1Fn = exports.fold1 = exports.foldFn = exports.fold = exports.removeFirstFn = exports.removeFirst = void 0; | ||
exports.uniqueByHashFn = exports.uniqueByHash = exports.uniqueByOrderFn = exports.uniqueByOrder = exports.uniqueByEqualityFn = exports.uniqueByEquality = exports.uniqueByIdentity = exports.uniqueFn = exports.unique = exports.groupAdjacentByHashFn = exports.groupAdjacentByHash = exports.groupAdjacentByOrderFn = exports.groupAdjacentByOrder = exports.groupAdjacentByEqualityFn = exports.groupAdjacentByEquality = exports.groupAdjacentByIdentityFn = exports.groupAdjacentByIdentity = exports.groupAdjacentFn = exports.groupAdjacent = exports.groupByOrderWithHashFn = exports.groupByOrderWithHash = exports.groupByEqualityWithHashFn = exports.groupByEqualityWithHash = exports.groupByHashFn = exports.groupByHash = exports.groupByOrderFn = exports.groupByOrder = exports.groupByEqualityFn = exports.groupByEquality = exports.groupByIdentityFn = exports.groupByIdentity = exports.groupFn = exports.group = exports.mapKeyFirstBy = exports.mapKeyByFn = exports.mapKeyBy = exports.keyLastByFn = exports.keyLastBy = exports.keyFirstByFn = exports.keyFirstBy = exports.keyByFn = exports.keyBy = exports.zipFn = exports.zip = exports.partitionUntilFn = exports.partitionUntil = exports.partitionWhileFn = exports.partitionWhile = exports.partitionFn = exports.partition = void 0; | ||
exports.forEachFn = exports.forEach = exports.sortByDescendingFn = exports.sortByDescending = exports.sortByFn = exports.sortBy = exports.sortFn = exports.sort = exports.shuffle = exports.uniqueAdjacentByHashFn = exports.uniqueAdjacentByHash = exports.uniqueAdjacentByOrderFn = exports.uniqueAdjacentByOrder = exports.uniqueAdjacentByEqualityFn = exports.uniqueAdjacentByEquality = exports.uniqueAdjacentByIdentityFn = exports.uniqueAdjacentByIdentity = exports.uniqueAdjacentFn = exports.uniqueAdjacent = exports.uniqueByOrderWithHashFn = exports.uniqueByOrderWithHash = exports.uniqueByEqualityWithHashFn = exports.uniqueByEqualityWithHash = void 0; | ||
exports.concatMapFn = exports.concatMap = exports.append = exports.prepend = exports.concat = exports.allFn = exports.all = exports.anyFn = exports.any = exports.or = exports.and = exports.average = exports.product = exports.sum = exports.minimumByFn = exports.minimumBy = exports.minimumFn = exports.minimum = exports.maximumByFn = exports.maximumBy = exports.maximumFn = exports.maximum = exports.findLastFn = exports.findLast = exports.findFn = exports.find = exports.findLastIndexFn = exports.findLastIndex = exports.findIndexFn = exports.findIndex = exports.lastIndexOfFn = exports.lastIndexOf = exports.indexOfFn = exports.indexOf = exports.containsFn = exports.contains = exports.foldMapRightFn = exports.foldMapRight = exports.foldMapFn = exports.foldMap = exports.foldRight1Fn = exports.foldRight1 = exports.foldRightFn = exports.foldRight = exports.fold1Fn = exports.fold1 = exports.foldFn = exports.fold = exports.removeFirstFn = exports.removeFirst = void 0; | ||
exports.groupAdjacentByOrderFn = exports.groupAdjacentByOrder = exports.groupAdjacentByEqualityFn = exports.groupAdjacentByEquality = exports.groupAdjacentByIdentityFn = exports.groupAdjacentByIdentity = exports.groupAdjacentFn = exports.groupAdjacent = exports.groupByOrderWithHashFn = exports.groupByOrderWithHash = exports.groupByEqualityWithHashFn = exports.groupByEqualityWithHash = exports.groupByHashFn = exports.groupByHash = exports.groupByOrderFn = exports.groupByOrder = exports.groupByEqualityFn = exports.groupByEquality = exports.groupByIdentityFn = exports.groupByIdentity = exports.groupFn = exports.group = exports.mapKeyFirstBy = exports.mapKeyByFn = exports.mapKeyBy = exports.keyLastByFn = exports.keyLastBy = exports.keyFirstByFn = exports.keyFirstBy = exports.keyByFn = exports.keyBy = exports.zipFn = exports.zip = exports.partitionUntilFn = exports.partitionUntil = exports.partitionWhileFn = exports.partitionWhile = exports.partitionFn = exports.partition = exports.splitFn = exports.split = exports.scanRight1Fn = exports.scanRight1 = exports.scanRightFn = exports.scanRight = exports.scan1Fn = exports.scan1 = exports.scanFn = exports.scan = exports.noneNull = void 0; | ||
exports.forEachFn = exports.forEach = exports.sortByDescendingFn = exports.sortByDescending = exports.sortByFn = exports.sortBy = exports.sortFn = exports.sort = exports.shuffle = exports.uniqueAdjacentByHashFn = exports.uniqueAdjacentByHash = exports.uniqueAdjacentByOrderFn = exports.uniqueAdjacentByOrder = exports.uniqueAdjacentByEqualityFn = exports.uniqueAdjacentByEquality = exports.uniqueAdjacentByIdentityFn = exports.uniqueAdjacentByIdentity = exports.uniqueAdjacentFn = exports.uniqueAdjacent = exports.uniqueByOrderWithHashFn = exports.uniqueByOrderWithHash = exports.uniqueByEqualityWithHashFn = exports.uniqueByEqualityWithHash = exports.uniqueByHashFn = exports.uniqueByHash = exports.uniqueByOrderFn = exports.uniqueByOrder = exports.uniqueByEqualityFn = exports.uniqueByEquality = exports.uniqueByIdentity = exports.uniqueFn = exports.unique = exports.groupAdjacentByHashFn = exports.groupAdjacentByHash = void 0; | ||
const nullable_1 = require("@softwareventures/nullable"); | ||
@@ -221,2 +221,4 @@ const ordered_1 = require("@softwareventures/ordered"); | ||
exports.filterFn = filterFn; | ||
/** @deprecated This function is confusing, use {@link excludeFirst} instead, | ||
* and invert the predicate. */ | ||
function filterFirst(array, predicate) { | ||
@@ -240,2 +242,4 @@ const result = []; | ||
exports.filterFirst = filterFirst; | ||
/** @deprecated This function is confusing, use {@link excludeFirstFn} instead, | ||
* and invert the predicate. */ | ||
function filterFirstFn(predicate) { | ||
@@ -355,2 +359,15 @@ return array => filterFirst(array, predicate); | ||
exports.indexOfFn = indexOfFn; | ||
function lastIndexOf(array, value) { | ||
for (let i = array.length - 1; i >= 0; --i) { | ||
if (array[i] === value) { | ||
return i; | ||
} | ||
} | ||
return null; | ||
} | ||
exports.lastIndexOf = lastIndexOf; | ||
function lastIndexOfFn(value) { | ||
return array => lastIndexOf(array, value); | ||
} | ||
exports.lastIndexOfFn = lastIndexOfFn; | ||
function findIndex(array, predicate) { | ||
@@ -365,2 +382,15 @@ const index = nativeFindIndex.call(array, predicate); | ||
exports.findIndexFn = findIndexFn; | ||
function findLastIndex(array, predicate) { | ||
for (let i = array.length - 1; i >= 0; --i) { | ||
if (predicate(array[i], i)) { | ||
return i; | ||
} | ||
} | ||
return null; | ||
} | ||
exports.findLastIndex = findLastIndex; | ||
function findLastIndexFn(predicate) { | ||
return array => findLastIndex(array, predicate); | ||
} | ||
exports.findLastIndexFn = findLastIndexFn; | ||
function find(array, predicate) { | ||
@@ -375,2 +405,16 @@ const index = findIndex(array, predicate); | ||
exports.findFn = findFn; | ||
function findLast(array, predicate) { | ||
for (let i = array.length - 1; i >= 0; --i) { | ||
const element = array[i]; | ||
if (predicate(element, i)) { | ||
return element; | ||
} | ||
} | ||
return null; | ||
} | ||
exports.findLast = findLast; | ||
function findLastFn(predicate) { | ||
return array => findLast(array, predicate); | ||
} | ||
exports.findLastFn = findLastFn; | ||
function maximum(array, compare = ordered_1.compare) { | ||
@@ -396,2 +440,10 @@ return internalMaximum(array, compare); | ||
} | ||
function maximumBy(array, select) { | ||
return maximum(array, (a, b) => (0, ordered_1.compare)(select(a), select(b))); | ||
} | ||
exports.maximumBy = maximumBy; | ||
function maximumByFn(select) { | ||
return array => maximumBy(array, select); | ||
} | ||
exports.maximumByFn = maximumByFn; | ||
function minimum(array, compare = ordered_1.compare) { | ||
@@ -417,2 +469,10 @@ return internalMinimum(array, compare); | ||
} | ||
function minimumBy(array, select) { | ||
return minimum(array, (a, b) => (0, ordered_1.compare)(select(a), select(b))); | ||
} | ||
exports.minimumBy = minimumBy; | ||
function minimumByFn(select) { | ||
return array => minimumBy(array, select); | ||
} | ||
exports.minimumByFn = minimumByFn; | ||
function sum(array) { | ||
@@ -426,2 +486,11 @@ return fold(array, (a, b) => a + b, 0); | ||
exports.product = product; | ||
function average(array) { | ||
if (array.length === 0) { | ||
return null; | ||
} | ||
else { | ||
return sum(array) / array.length; | ||
} | ||
} | ||
exports.average = average; | ||
function and(array) { | ||
@@ -428,0 +497,0 @@ return findIndex(array, element => !element) == null; |
{ | ||
"name": "@softwareventures/array", | ||
"version": "4.6.0", | ||
"version": "4.7.0", | ||
"description": "Pure functional array manipulation and traversal", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
163113
5.71%1484
6.23%