import { Maybe } from 'monet'; /** * Flattens an array using a mapping function that returns a new array. * @param fn - the mapper function * @returns the mapped and flattened array * ```typescript * pipe( * ['ab','cd'], * Arrays.flatMap(string => string.split('')) // -> ['a','b','c','d'] * ); * ``` */ export declare function flatMap(fn: (val: T, index: number, arr: T[]) => R[]): (array: T[]) => R[]; /** * Flattens an array to a specified depth, defaulting to 1. * @alias flatten * @param depth [1] - the depth to flatten the array * @returns the flattened array * ```typescript * pipe( * [[1,2,3],[4,5,6]], * Arrays.flat() // -> [1,2,3,4,5,6] * ); * ``` */ export declare function flat(depth?: 1): (array: T[][]) => T[]; export declare function flat(depth: 2): (array: T[][][]) => T[]; export declare function flat(depth: 3): (array: T[][][][]) => T[]; export declare function flat(depth: 4): (array: T[][][][][]) => T[]; export declare function flat(depth: 5): (array: T[][][][][][]) => T[]; export declare function flat(depth: number): (array: T[]) => R[]; /** * Reduces the array into a value using an accumulator function starting with the first value in the array. * @param fn - the accumulator function accepting the accumulated value, the current value, the index and the array * @returns the accumulated value * ```typescript * pipe( * [1,2,3], * Arrays.reduce((sum, value) => sum + value) // -> 6 * ); * ``` */ export declare function reduce(fn: (accumulator: T, current: T, index: number, arr: T[]) => T): (array: T[]) => T; /** * Reduces the array into a value using an accumulator function starting with the result of an initial value function. * @param fn - the accumulator function accepting the accumulated value, the current value, the index and the array * @param initialValueFactory - a function to generate the initial value * @returns the accumulated value * ```typescript * pipe( * [1,2,3], * Arrays.reduce((sum, value) => sum + value, () => 4) // -> 10 * ); * ``` */ export declare function reduce(fn: (accumulator: O, current: I, index: number, arr: I[]) => O, initialValueFactory?: () => O): (array: I[]) => O; /** * Reduces the array into a value using an accumulator function starting with the last value in the array. * @param fn - the accumulator function accepting the accumulated value, the current value, the index and the array * @returns the accumulated value * ```typescript * pipe( * [1,2,3], * Arrays.reduce((sum, value) => sum + value) // -> 6 * ); * ``` */ export declare function reduceRight(fn: (accumulator: T, current: T, index: number, arr: T[]) => T): (array: T[]) => T; /** * Reduces the array (from last to first) into a value using an accumulator function starting with the result of an initial value function. * @param fn - the accumulator function accepting the accumulated value, the current value, the index and the array * @param initialValueFactory - a function to generate the initial value * @returns the accumulated value * ```typescript * pipe( * [1,2,3], * Arrays.reduce((sum, value) => sum + value, () => 4) // -> 10 * ); * ``` */ export declare function reduceRight(fn: (accumulator: O, current: I, index: number, arr: I[]) => O, initialValueFactory?: () => O): (array: I[]) => O; /** * Gets the element of an array at the specified index. For negative indices, it will index from the end of the array. * @param index - the index of the element to get, or a function that returns an index * @returns a Some of the element if it exists or a None if it does not * ```typescript * pipe( * ['a','b'], * Arrays.get(2) // -> None * ); * * pipe( * [1,2,3], * Arrays.get(-1) // -> Some(3) * ); * ``` */ export declare function get(index: number | ((arr: T[]) => number)): (array: T[]) => Maybe; /** * Gets the first element of an array. * @returns a Some of the first element of the array if it exists or a None if it does not * ```typescript * pipe( * [1,2,3], * Arrays.getFirst() // -> Some(1) * ); * ``` */ export declare function getFirst(noArg?: never): (array: T[]) => Maybe; /** * Gets the last element of an array. * @returns a Some of the last element of the array if it exists or a None if it does not * ```typescript * pipe( * ['a','b','c'], * Arrays.getLast() // -> Some('c') * ); * ``` */ export declare function getLast(noArg?: never): (array: T[]) => Maybe; /** * Gets the length of the array. * @returns the length of the array * ```typescript * pipe( * [1,2,3], * Arrays.size() // -> 3 * ); * ``` */ export declare function size(noArg?: never): (array: T[]) => number; /** * Finds the first element matching the given predicate. * @returns a Some if such an element exists or a None if it does not * ```typescript * pipe( * [4,5,6,7], * Arrays.find(num => num % 3 === 0) // -> Some(6) * ); * ``` */ export declare function find(fn: (val: T, index: number, arr: T[]) => boolean): (array: T[]) => Maybe; /** * Immutably reverse an array. * @returns the reversed array * ```typescript * pipe( * [1,2,3], * Arrays.reverse() // -> [3,2,1] * ); * ``` */ export declare function reverse(noArg?: never): (array: T[]) => T[]; /** * Immutably sorts an array with an optional sorter function. * @param fn - the function to sort with * @returns the sorted array * ```typescript * pipe( * [4,1,3,2], * Arrays.sort() // -> [1,2,3,4] * ); * ``` */ export declare function sort(fn?: (a: T, b: T) => number): (array: T[]) => T[]; /** * Maps an array using a mapper function. * @param fn - the mapper function * @returns the mapped array * ```typescript * pipe( * ['ab','cde'], * Arrays.map(str => str.length) // -> [2,3] * ); * ``` */ export declare const map: (fn: (val: T, index: number, arr: T[]) => R) => (array: T[]) => R[]; /** * Filters an array using a predicate function. * @param fn - the predicate function * @returns the filtered array * ```typescript * pipe( * [1,2,3,4,5], * Arrays.filter(num => num < 4) // -> [1,2,3] * ); * ``` */ export declare const filter: (fn: (val: T, index: number, arr: T[]) => boolean) => (array: T[]) => T[]; /** * Checks if an array contains an element matching the given predicate. * @param fn - the predicate function * @returns whether or not the array contains such an element * ```typescript * pipe( * [1,2,3,4,5], * Arrays.some(num => num === 3) // -> true * ); * ``` */ export declare const some: (fn: (val: T, index: number, arr: T[]) => boolean) => (array: T[]) => boolean; /** * Checks whether or not every element in an array matches the given predicate. * @param fn - the predicate function * @returns whether or not every element in the array matches the predicate * ```typescript * pipe( * ['a','b','c'], * Arrays.every(str => str.length === 1) // -> true * ); * ``` */ export declare const every: (fn: (val: T, index: number, arr: T[]) => boolean) => (array: T[]) => boolean; /** * Executes a function for each element in an array. * @param fn - the function to execute for each element * ```typescript * pipe( * [1,2,3], * Arrays.forEach(val => console.log(val)) // logs: 1, 2, 3 * ); * ``` */ export declare const forEach: (fn: (val: T, index: number, arr: T[]) => any) => (array: T[]) => void; /** * Concatenates one or more arrays with a given array. * @param arrays - one or more array to add to the array * @returns the concatenated array * ```typescript * pipe( * [1,2], * Arrays.concat([3,4], [5,6]) // -> [1,2,3,4,5,6] * ); * ``` */ export declare const concat: (...arrays: T[][]) => (array: T[]) => T[]; /** * Joins an array with an optional separator. * @param separator - the string to use to join the array values * @returns the joined string * ```typescript * pipe( * ['a','b','c'], * Arrays.join(',') // -> 'a,b,c' * ); * ``` */ export declare const join: (separator?: string | undefined) => (array: T[]) => string; /** * Creates an array from an array-like object. * @param arrayLike - An array-like object to convert to an array * @returns the created array */ export declare const from: { (arrayLike: ArrayLike): T[]; (arrayLike: ArrayLike, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; (iterable: Iterable | ArrayLike): T[]; (iterable: Iterable | ArrayLike, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; }; /** * Checks if the given object is an array. * @param arg - the object to check * @returns whether or not the object is an array * ```typescript * pipe( * [1,2,3], * Arrays.isArray() // -> true * ) * ``` */ export declare const isArray: (noArg?: undefined) => (arg: any) => arg is any[]; /** * Returns a new array from a set of elements. * @param items - A set of elements to include in the new array object. * @returns the created array */ export declare const of: (...items: T[]) => T[]; export { flat as flatten };