Functional array operations providing immutable transformations, type-safe operations, and integration with fp-ts type class system.
Array implements various type class instances for generic operations.
/**
* Monoid instance for Array (concatenation)
* @returns Monoid instance where concat combines arrays and empty is []
*/
function getMonoid<A>(): Monoid<Array<A>>;
/**
* Equality instance for Array
* @param E - Equality instance for element type
* @returns Equality instance that compares arrays element-wise
*/
function getEq<A>(E: Eq<A>): Eq<Array<A>>;
/**
* Show instance for Array
* @param S - Show instance for element type
* @returns Show instance that displays array contents
*/
function getShow<A>(S: Show<A>): Show<Array<A>>;
/**
* Ordering instance for Array (lexicographic ordering)
* @param O - Ordering instance for element type
* @returns Ordering instance for arrays
*/
function getOrd<A>(O: Ord<A>): Ord<Array<A>>;Usage Examples:
import { getMonoid, getEq, getShow } from "fp-ts/lib/Array";
import { eqNumber } from "fp-ts/lib/Eq";
import { showNumber } from "fp-ts/lib/Show";
// Monoid operations
const M = getMonoid<number>();
const combined = M.concat([1, 2], [3, 4]); // [1, 2, 3, 4]
const empty = M.empty; // []
// Equality testing
const EqArray = getEq(eqNumber);
const isEqual = EqArray.equals([1, 2, 3], [1, 2, 3]); // true
// Show instance
const ShowArray = getShow(showNumber);
const displayed = ShowArray.show([1, 2, 3]); // "[1, 2, 3]"Create and manipulate arrays with type safety.
/**
* Empty array constant
*/
const empty: Array<never>;
/**
* Create array with single element
* @param a - Element to wrap in array
* @returns Array containing single element
*/
function of<A>(a: A): Array<A>;
/**
* Create array by applying function to indices
* @param n - Number of elements to create
* @param f - Function that maps index to element
* @returns Array with n elements created by f
*/
function makeBy<A>(n: number, f: (i: number) => A): Array<A>;
/**
* Create array by repeating element
* @param n - Number of repetitions
* @param a - Element to repeat
* @returns Array with n copies of a
*/
function replicate<A>(n: number, a: A): Array<A>;
/**
* Create array containing range of integers
* @param start - Start value (inclusive)
* @param end - End value (inclusive)
* @returns Array of integers from start to end
*/
function range(start: number, end: number): Array<number>;Transform arrays while preserving immutability.
/**
* Map function over array elements
* @param f - Transformation function
* @returns Function that maps over array
*/
function map<A, B>(f: (a: A) => B): (fa: Array<A>) => Array<B>;
/**
* Map with index information
* @param f - Transformation function receiving element and index
* @returns Function that maps over array with indices
*/
function mapWithIndex<A, B>(f: (i: number, a: A) => B): (fa: Array<A>) => Array<B>;
/**
* Flat map (chain) operation
* @param f - Function returning array
* @returns Function that flat maps over array
*/
function chain<A, B>(f: (a: A) => Array<B>): (fa: Array<A>) => Array<B>;
/**
* Flatten nested arrays by one level
* @param mma - Array of arrays
* @returns Flattened array
*/
function flatten<A>(mma: Array<Array<A>>): Array<A>;Filter arrays based on predicates and conditions.
/**
* Filter array elements based on predicate
* @param predicate - Function to test elements
* @returns Function that filters array
*/
function filter<A>(predicate: Predicate<A>): (fa: Array<A>) => Array<A>;
function filter<A, B extends A>(refinement: Refinement<A, B>): (fa: Array<A>) => Array<B>;
/**
* Filter with index information
* @param predicate - Function to test elements with index
* @returns Function that filters array with indices
*/
function filterWithIndex<A>(predicate: (i: number, a: A) => boolean): (fa: Array<A>) => Array<A>;
/**
* Partition array into two arrays based on predicate
* @param predicate - Function to test elements
* @returns Function that returns object with left and right arrays
*/
function partition<A>(predicate: Predicate<A>): (fa: Array<A>) => Separated<Array<A>, Array<A>>;
function partition<A, B extends A>(refinement: Refinement<A, B>): (fa: Array<A>) => Separated<Array<A>, Array<B>>;Access and search for elements in arrays.
/**
* Get array length
* @param fa - Array to measure
* @returns Number of elements
*/
function size<A>(fa: Array<A>): number;
/**
* Check if array is empty
* @param fa - Array to check
* @returns true if array has no elements
*/
function isEmpty<A>(fa: Array<A>): boolean;
/**
* Check if array is non-empty
* @param fa - Array to check
* @returns true if array has elements
*/
function isNonEmpty<A>(fa: Array<A>): fa is NonEmptyArray<A>;
/**
* Get element at index safely
* @param i - Index to access
* @returns Function that returns Option of element at index
*/
function lookup<A>(i: number, fa: Array<A>): Option<A>;
/**
* Alias for lookup (get element at index safely)
* @param i - Index to access
* @param fa - Array to access
* @returns Option of element at index
*/
function index<A>(i: number, fa: Array<A>): Option<A>;
/**
* Check if index is out of bounds
* @param i - Index to check
* @param fa - Array to check against
* @returns true if index is out of bounds
*/
function isOutOfBound<A>(i: number, fa: Array<A>): boolean;
/**
* Get first element
* @param fa - Array to access
* @returns Option of first element
*/
function head<A>(fa: Array<A>): Option<A>;
/**
* Get last element
* @param fa - Array to access
* @returns Option of last element
*/
function last<A>(fa: Array<A>): Option<A>;
/**
* Get all elements except first
* @param fa - Array to process
* @returns Option of tail array
*/
function tail<A>(fa: Array<A>): Option<Array<A>>;
/**
* Get all elements except last
* @param fa - Array to process
* @returns Option of init array
*/
function init<A>(fa: Array<A>): Option<Array<A>>;Find elements in arrays based on various criteria.
/**
* Find first element matching predicate
* @param predicate - Function to test elements
* @returns Function that returns Option of found element
*/
function find<A>(predicate: Predicate<A>): (fa: Array<A>) => Option<A>;
function find<A, B extends A>(refinement: Refinement<A, B>): (fa: Array<A>) => Option<B>;
/**
* Find first element matching predicate with index
* @param predicate - Function to test elements with index
* @returns Function that returns Option of found element
*/
function findWithIndex<A>(predicate: (i: number, a: A) => boolean): (fa: Array<A>) => Option<A>;
/**
* Find index of first element matching predicate
* @param predicate - Function to test elements
* @returns Function that returns Option of found index
*/
function findIndex<A>(predicate: Predicate<A>): (fa: Array<A>) => Option<number>;
/**
* Find last element matching predicate
* @param predicate - Function to test elements
* @returns Function that returns Option of found element
*/
function findLast<A>(predicate: Predicate<A>): (fa: Array<A>) => Option<A>;
/**
* Check if any element matches predicate
* @param predicate - Function to test elements
* @returns Function that returns boolean
*/
function some<A>(predicate: Predicate<A>): (fa: Array<A>) => boolean;
/**
* Check if all elements match predicate
* @param predicate - Function to test elements
* @returns Function that returns boolean
*/
function every<A>(predicate: Predicate<A>): (fa: Array<A>) => boolean;Modify array structure and content.
/**
* Reverse array elements
* @param fa - Array to reverse
* @returns Array with elements in reverse order
*/
function reverse<A>(fa: Array<A>): Array<A>;
/**
* Sort array using comparison function
* @param O - Ordering instance for element type
* @returns Function that sorts array
*/
function sort<A>(O: Ord<A>): (fa: Array<A>) => Array<A>;
/**
* Insert element at index
* @param i - Index to insert at
* @param a - Element to insert
* @returns Function that inserts element
*/
function insertAt<A>(i: number, a: A): (fa: Array<A>) => Option<Array<A>>;
/**
* Update element at index
* @param i - Index to update
* @param a - New element value
* @returns Function that updates element
*/
function updateAt<A>(i: number, a: A): (fa: Array<A>) => Option<Array<A>>;
/**
* Delete element at index
* @param i - Index to delete
* @returns Function that deletes element
*/
function deleteAt<A>(i: number): (fa: Array<A>) => Option<Array<A>>;
/**
* Modify element at index using function
* @param i - Index to modify
* @param f - Function to transform element
* @returns Function that modifies element
*/
function modifyAt<A>(i: number, f: Endomorphism<A>): (fa: Array<A>) => Option<Array<A>>;Extract portions of arrays.
/**
* Take first n elements
* @param n - Number of elements to take
* @returns Function that takes elements
*/
function takeLeft<A>(n: number): (fa: Array<A>) => Array<A>;
/**
* Take last n elements
* @param n - Number of elements to take
* @returns Function that takes elements from end
*/
function takeRight<A>(n: number): (fa: Array<A>) => Array<A>;
/**
* Take elements while predicate holds from left
* @param predicate - Predicate to test elements
* @returns Function that takes elements while predicate is true
*/
function takeLeftWhile<A>(predicate: Predicate<A>): (fa: Array<A>) => Array<A>;
function takeLeftWhile<A, B extends A>(refinement: Refinement<A, B>): (fa: Array<A>) => Array<B>;
/**
* Drop first n elements
* @param n - Number of elements to drop
* @returns Function that drops elements
*/
function dropLeft<A>(n: number): (fa: Array<A>) => Array<A>;
/**
* Drop last n elements
* @param n - Number of elements to drop
* @returns Function that drops elements from end
*/
function dropRight<A>(n: number): (fa: Array<A>) => Array<A>;
/**
* Drop elements while predicate holds from left
* @param predicate - Predicate to test elements
* @returns Function that drops elements while predicate is true
*/
function dropLeftWhile<A>(predicate: Predicate<A>): (fa: Array<A>) => Array<A>;
/**
* Split array at index
* @param n - Index to split at
* @returns Function that returns tuple of [before, after]
*/
function splitAt<A>(n: number): (fa: Array<A>) => [Array<A>, Array<A>];
/**
* Split array while predicate holds
* @param predicate - Predicate to test elements
* @returns Function that returns object with init and rest arrays
*/
function spanLeft<A>(predicate: Predicate<A>): (fa: Array<A>) => { init: Array<A>; rest: Array<A> };
function spanLeft<A, B extends A>(refinement: Refinement<A, B>): (fa: Array<A>) => { init: Array<B>; rest: Array<A> };
/**
* Split array into chunks of specified size
* @param n - Size of each chunk
* @returns Function that chunks array
*/
function chunksOf<A>(n: number): (fa: Array<A>) => Array<Array<A>>;Operations treating arrays as sets.
/**
* Remove duplicate elements
* @param E - Equality instance for element type
* @returns Function that removes duplicates
*/
function uniq<A>(E: Eq<A>): (fa: Array<A>) => Array<A>;
/**
* Union of two arrays (unique elements from both)
* @param E - Equality instance for element type
* @returns Function that computes union
*/
function union<A>(E: Eq<A>): (xs: Array<A>) => (ys: Array<A>) => Array<A>;
/**
* Intersection of two arrays (elements in both)
* @param E - Equality instance for element type
* @returns Function that computes intersection
*/
function intersection<A>(E: Eq<A>): (xs: Array<A>) => (ys: Array<A>) => Array<A>;
/**
* Difference of two arrays (elements in first but not second)
* @param E - Equality instance for element type
* @returns Function that computes difference
*/
function difference<A>(E: Eq<A>): (xs: Array<A>) => (ys: Array<A>) => Array<A>;Reduce arrays to single values.
/**
* Left fold with initial value
* @param b - Initial accumulator value
* @param f - Folding function
* @returns Function that folds array from left
*/
function reduce<A, B>(b: B, f: (b: B, a: A) => B): (fa: Array<A>) => B;
/**
* Left fold with index information
* @param b - Initial accumulator value
* @param f - Folding function with index
* @returns Function that folds array from left with indices
*/
function reduceWithIndex<A, B>(b: B, f: (i: number, b: B, a: A) => B): (fa: Array<A>) => B;
/**
* Right fold with initial value
* @param b - Initial accumulator value
* @param f - Folding function
* @returns Function that folds array from right
*/
function reduceRight<A, B>(b: B, f: (a: A, b: B) => B): (fa: Array<A>) => B;
/**
* Right fold with index information
* @param b - Initial accumulator value
* @param f - Folding function with index
* @returns Function that folds array from right with indices
*/
function reduceRightWithIndex<A, B>(b: B, f: (i: number, a: A, b: B) => B): (fa: Array<A>) => B;
/**
* Fold with explicit nil and cons cases
* @param onNil - Value to return for empty array
* @param onCons - Function to apply for non-empty array
* @returns Folded value
*/
function fold<A, B>(as: Array<A>, onNil: B, onCons: (head: A, tail: Array<A>) => B): B;
/**
* Fold left with lazy nil case
* @param onNil - Lazy function for empty array
* @param onCons - Function for non-empty array
* @returns Function that folds array
*/
function foldLeft<A, B>(onNil: () => B, onCons: (head: A, tail: Array<A>) => B): (fa: Array<A>) => B;
/**
* Fold right with lazy nil case
* @param onNil - Lazy function for empty array
* @param onCons - Function for non-empty array
* @returns Function that folds array
*/
function foldRight<A, B>(onNil: () => B, onCons: (init: Array<A>, last: A) => B): (fa: Array<A>) => B;
/**
* Scan left (accumulate intermediate results)
* @param b - Initial accumulator value
* @param f - Accumulation function
* @returns Array of intermediate results
*/
function scanLeft<A, B>(as: Array<A>, b: B, f: (b: B, a: A) => B): Array<B>;
/**
* Scan right (accumulate intermediate results)
* @param b - Initial accumulator value
* @param f - Accumulation function
* @returns Array of intermediate results
*/
function scanRight<A, B>(as: Array<A>, b: B, f: (a: A, b: B) => B): Array<B>;// Array is the native JavaScript Array type
// Enhanced with phantom types for fp-ts integration
declare global {
interface Array<T> {
_URI: URI;
_A: T;
}
}
// URI for type-level programming
const URI = 'Array';
type URI = typeof URI;
// Separated type for partition operations
interface Separated<E, A> {
left: E;
right: A;
}