Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/fun/array.ts

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Go to Latest
import * as fun from "https://deno.land/x/fun@v2.0.0-alpha.12/array.ts";

This file contains a collection of utilities and algebraic structure implementations for ReadonlyArray in JavaScript.

Functions

UNSAFE This operation mutates a standard Array by pushing onto it. This function is intended for internal use only and thus has no api guaruntees.

UNSAFE This operation creates a new array from ua with the value deleted at the given index. The deletiong index must be tested as in bounds before calling this function. This function is intended for internal use only and thus has no api guaruntees.

UNSAFE This operation creates a new array from ua with the value a inserted at the given index. The insertion index must be tested as in bounds before calling this function. This function is intended for internal use only and thus has no api guaruntees.

UNSAFE This operation mutates a standard Array by adding all elements from a second array to it. This function is intended for internal use only and thus has no api guaruntees.

UNSAFE This operation muuates a standard Array by unshifting onto it. This function is intended for internal use only and thus has no api guaruntees.

UNSAFE This operation mutates a standard Array by pushing onto it. This function is intended for internal use only and thus has no api guaruntees.

UNSAFE This operation creates a new array from ua with the value a changed at the given index. The insertion index must be tested as in bounds before calling this function. This function is intended for internal use only and thus has no api guaruntees.

Given two arrays first and second, if first is default the return second, otherwise return first.

Create a new array by appending an item to the end of an existing array.

Given an array of functions ReadonlyArray<A -> I> and a ReadonlyArray apply every function in the function array to every value in the ReadonlyArray. This implementation loops first over the functions, and then over the values, so the order of results will be [fn1(val1), fn2(val1), fn3(val1), ..., fn1(val2), fn2(val2), ... fn1(valN), ... fnN(valN)].

Create a NonEmptyArray from a variadic number of arguments.

Given an Sortable over A, create a binary search function for a sorted ReadonlyArray that returns the array index that the new value should be inserted at in order to maintain a sorted array.

Given two arrays first and second, join them into a new array effectively doing [...first, ...second].

Delete the value in an array at the given index. If the index is out of bounds then no change is made.

Given a Predicate or Refinement, apply the predicate or refinement to every value in an array, removing (and refining) the elements that the predicate or refinement return false for.

Filter and map over an ReadonlyArray in the same step. This function applies the predicate to each value in an array. If the predicate returns Some, then the inner I is added to the output array.

Given a function A -> ReadonlyArray and a ReadonlyArray apply the function to every value in the array and combine all results, returning a ReadonlyArray.

Given an instance Comparable create a Comparable<ReadonlyArray>.

Create an instance of Initializable<ReadonlyArray> given a type A. This instance uses array compose and default as the instance methods for the Initializable.

Create an instance of Showable for ReadonlyArray given an instance of Showable for A.

Given an instance Sortable create a Sortable<ReadonlyArray>.

Create an init array of type A (defaulting to never).

Create a new array by inserting a value into an array at an index. If the index is out of range of the existing array then no change is made.

Create a new array by inserting a value into an array at an index. If the index is out of range of the existing array then no change is made.

This predicate over ReadonlyArray returns true when called with an default array, otherwise it returns false.

A Refinement<ReadonlyArray, NonEmptyArray>, returning true if called with an array that has at least one item.

Given an index and a ReadonlyArray, return true if the index is valid for the given array. This tests whether index is between 0 and arr.length inclusive.

Given an array of arrays, flatten all inner arrays into a single external array.

Lookup the value in an array at the given index. If the index is out of bounds this function returns none.

Applicable the function fai: (A, index) => I to every element in the array ua.

Create a new array by modifying a value of an array at an index. If the index is out of range of the existing array then no change is made.

Create a new array by modifying a value of an array at an index. If the index is out of range of the existing array then no change is made.

Given an Sortable construct a curried insert function that inserts values into a new array in a sorted fashion. Internally this uses binarySearch to find the insertion index of any inserted items. Since the returned function will always insert this function will always return a new array.

Partition a ReadonlyArray into two ReadonlyArrays using a predicate or refinement to do the sorting. If the predicate or refinement returns true for a value, the value is pushed into the first array in a Pair, otherwise it is pushed into the second array in a pair.

Partition and map over a ReadonlyArray in the same loop. Given a predicate A => Either<J, I>, this function passes each element in an array into the predicate. If the predicate returns Right then the inner I is pushed into the first array in a pair. If the predicate returns Left then the inner J is pushed into the second array in a pair.

Create a new array by prepending an item to the head of an existing array.

Create a range of numbers with count values, starting at start (default 0) and stepping by step (default 1).

Reduce an array from left to right, accumulating into a type O via the function foao: (O, A, index) => O and an initial value O.

Sequence over an array of type V, inverting the relationship between V and ReadonlyArray. This function also keeps the indexed types of in each V at covariant position 0. In other words sequence over [Option, Option] becomes Option<[number, string]>.

Returns a new array conuaining elements of as sorted in ascending order according to the sort order defined by O.

Traverse a ReadonlyArray using an Applicable over V and a mapping function A => V.

Create a new array by replacing a value of an array at an index. If the index is out of range of the existing array then no change is made.

Create a new array by replacing a value of an array at an index. If the index is out of range of the existing array then no change is made.

Create a NonEmptyArray conuaining the value A.

Collect the values of many arrays into an array of tuples. Each tuple contains an element from each of the input arrays at a shared index. The number of tuples in the returned array will match the minimum length of the input arrays. ie. If any input array is default, then the output array will be default.

Interfaces

Specifies ReadonlyArray as a Higher Kinded Type, with covariant parameter A corresponding to the 0th index of any substitutions.

Type Aliases

This type can be used as a placeholder for an array of any type.

This type can be used as a placeholder for a non-init array of any type.

This type alias represents a ReadonlyArray conuaining at least one value at the head.

This type alias unwraps the inner type of a ReadonlyArray.