Skip to main content
Module

x/rimbu/common/mod.ts

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
import * as rimbu from "https://deno.land/x/rimbu@0.13.1/common/mod.ts";

Classes

A base class that can be used to easily create AsyncReducer instances.

A custom error instance.

A base class that can be used to easily create Reducer instances.

Variables

Returns an AsyncReducer that takes boolean values and outputs true if all input values are true, and false otherwise.

A Reducer that calculates the average of all given numberic input values.

Returns an AsyncReducer that remembers the amount of input items provided.

Returns an AsyncReducer that remembers the first input value.

Returns an AsyncReducer that remembers the first input value for which the given pred function returns true.

Returns an AsyncReducer that outputs true if no input values are received, false otherwise.

Returns an AsyncReducer that remembers the last input value.

Returns an AsyncReducer that remembers the last input value for which the given pred function returns true.

Returns a Reducer that remembers the maximum value of the numberic inputs.

Returns a Reducer that remembers the maximum value of the inputs using the given compFun to compare input values

Returns a Reducer that remembers the minimum value of the numberic inputs.

Returns a Reducer that remembers the minimum value of the inputs using the given compFun to compare input values

Returns an AsyncReducer that outputs true if one or more input values are received, false otherwise.

Returns an AsyncReducer that takes boolean values and outputs true if one or more input values are true, and false otherwise.

A Reducer that calculates the product of all given numeric input values.

A Reducer that sums all given numeric input values.

Indicates, when returned from a collect function, to skip the value.

An Eq instance that uses Object.is to determine if two objects are equal.

Returns a Reducer that takes boolean values and outputs true if all input values are true, and false otherwise.

A Reducer that calculates the average of all given numberic input values.

Returns a Reducer that remembers the amount of input items provided.

Returns a Reducer that remembers the first input value.

Returns a Reducer that remembers the first input value for which the given pred function returns true.

Returns a Reducer that outputs true if no input values are received, false otherwise.

Returns a Reducer that remembers the last input value.

Returns a Reducer that remembers the last input value for which the given pred function returns true.

Returns a Reducer that remembers the maximum value of the numberic inputs.

Returns a Reducer that remembers the maximum value of the inputs using the given compFun to compare input values

Returns a Reducer that remembers the minimum value of the numberic inputs.

Returns a Reducer that remembers the minimum value of the inputs using the given compFun to compare input values

Returns a Reducer that outputs true if one or more input values are received, false otherwise.

Returns a Reducer that takes boolean values and outputs true if one or more input values are true, and false otherwise.

A Reducer that calculates the product of all given numeric input values.

A Reducer that sums all given numeric input values.

Functions

Returns the value or promised value contained in an AsyncOptLazy instance of type T.

Returns the value contained in an AsyncOptLazy instance of type T as a promise.

Returns an AsyncReducer that combines multiple input reducers by providing input values to all of them and collecting the outputs in an array.

Returns an AsyncReducer that combines multiple input reducers by providing input values to all of them and collecting the outputs in the shape of the given object.

Returns an AsyncReducer that outputs false as long as the given elem has not been encountered in the input values, true otherwise.

Returns an AsyncReducer with the given options:

Returns an AsyncReducer of which the input, state, and output types are the same.

Returns an AsyncReducer of which the state and output types are the same.

Returns an AsyncReducer that ouputs true as long as all input values satisfy the given pred, false otherwise.

Returns a Reducer that joins the given input values into a string using the given options.

Returns a Reducer that ouputs false as long as no input value satisfies given pred, true otherwise.

Returns an AsyncReducer that collects received input values in an array, and returns a copy of that array as an output value when requested.

Returns a AsyncReducer that collects received input tuples into a mutable JS Map, and returns a copy of that map when output is requested.

Returns an AsyncReducer that collects 2-tuples containing keys and values into a plain JS object, and returns a copy of that object when output is requested.

Returns an AsyncReducer that collects received input values into a mutable JS Set, and returns a copy of that map when output is requested.

Returns a Comp instance that compares any value using default comparison functions. For Iterables and objects, their elements are compared recursively.

Returns a Comp instance that compares any value using default comparison functions, but never recursively compares Iterables or objects. In those cases, it will use the stringComp instance.

Returns a Comp instance that compares any value using default comparison functions. For Iterables and objects, their elements are compared only one level deep for performance and to avoid infinite recursion.

Returns a Comp instance converts values to string with JSON.stringify, and orders the resulting string naturally.

Returns a any Comp instance that orders any according to their toString values.

Returns a default bigint Comp instance that orders bigint numbers naturally.

Returns a default boolean Comp instance that orders booleans according to false < true.

Returns a Comp instance that orders objects with a valueOf method according to the given valueComp instance for the valueOf values.

Returns a Date Comp instance that orders Dates according to their .valueOf value.

Returns the default Comp instance, which is the Comp.anyDeepComp() instance.

Returns a Comp instance the reverses the order of the given comp instance.

Returns a Comp instance for Iterable objects that orders the Iterables by comparing the elements with the given itemComp Comp instance.

Returns a default number Comp instance that orders numbers naturally.

Returns a Comp instance for objects that orders the object keys according to the given keyComp, and then compares the corresponding values using the given valueComp. Objects are then compared as follows: starting with the smallest key of either object:

  • if only one of the objects has the key, the object with the key is considered to be larger than the other
  • if both objects have the key, the values are compared with valueComp. If the values are not equal, this result is returned.

Returns a Comp instance that compares strings in a case-insensitive way.

Returns a string Comp instance that orders strings according to their indexed char codes.

Returns a Comp instance that compares strings based on the string's localeCompare method.

Returns an Eq equality instance thet will return true when the given comp comparable instance returns 0.

Returns a Comp instance that extends the given comp instance with the capability to handle null values, where null is considered to be smaller than any other value, and equal to another null.

Returns a Comp instance that extends the given comp instance with the capability to handle undefined values, where undefined is considered to be smaller than any other value, and equal to another undefined.

Returns an Eq instance that checks equality of any values. For composed values (objects and iterables) it will recursively compare the contained values.

Returns an Eq instance that checks equality of any values. For composed values (objects and iterables) it will compare with Object.is.

Returns an Eq instance that considers values equal their JSON.stringify values are equal.

Returns an Eq instance that checks equality of any values. For composed values (objects and iterables) it will enter 1 level, and if again compound values are found, they are compared with Object.is.

Returns an Eq instance that considers strings equal taking the given or default locale into account.

Returns an Eq instance that compares Date objects according to their valueOf value.

Returns the default Eq instance, which is the Eq.anyDeepEq() instance.

Returns an Eq instance that compares Iterables by comparing their elements with the given itemEq Eq instance.

Returns an Eq instance that checks equality of objects containing property values of type V by iteratively applying given valueEq to each of the object's property values.

Returns an Eq instance that considers strings equal regardless of their case.

Returns an Eq instance that considers strings equal when all their charcodes are equal.

Returns an Eq instance for tuples that considers two tuples [A, B] and [C, D] equal if [A, B] equals [C, D], or if [A, B] equals [D, C]

Returns an Eq instance for objects that have a valueOf method. It returns true if the .valueOf values of both given objects are equal.

Throws an Err.ForcedError error when called.

Returns a function that, when called, throws an Err.ForcedError with the given message string.

Returns, given the range IndexRange, a normalized tuple containing the start index, and optionally an end index.

Returns, given the range IndexRange, and a target maximum length, the actual index range. This can be one of three options:

  • 'empty': there are no elements within the range
  • 'all': all elements are within the range
  • [start: number, end: number]: an inclusive range of element indices within the given range

Returns the value contained in an OptLazy instance of type T.

Returns the value contained in an OptLazyOr instance of type T, or the given otherValue if the lazy function returns it.

Simplifies a given range Range input for easier processing, by returning optional start and end ranges including whether they are inclusive or exclusive

Returns a Reducer that combines multiple input reducers by providing input values to all of them and collecting the outputs in an array.

Returns a Reducer that combines multiple input reducers by providing input values to all of them and collecting the outputs in the shape of the given object.

Returns a Reducer that outputs false as long as the given elem has not been encountered in the input values, true otherwise.

Returns a Reducer with the given options:

Returns a Reducer of which the input, state, and output types are the same.

Returns a Reducer of which the state and output types are the same.

Returns a Reducer that ouputs true as long as all input values satisfy the given pred, false otherwise.

Returns a Reducer that joins the given input values into a string using the given options.

Returns a Reducer that ouputs false as long as no input value satisfies given pred, true otherwise.

Returns a Reducer that collects received input values in an array, and returns a copy of that array as an output value when requested.

Returns a Reducer that collects received input tuples into a mutable JS Map, and returns a copy of that map when output is requested.

Returns a Reducer that collects 2-tuples containing keys and values into a plain JS object, and returns a copy of that object when output is requested.

Returns a Reducer that collects received input values into a mutable JS Set, and returns a copy of that map when output is requested.

Returns a new TraverseState instance, using optionally given startIndex as a start index value.

Returns the result of given update parameter, where it can either directly give a new value, or it is a function receiving the given value, and returns a new value.

Interfaces

An object providing methods to compare two values of type K.

The Implementation interface for a Reducer, which also exposes the internal state type.

Utility type to convert some object to a JSON serializable format.

An object used to track the state of a traversal, e.g. a forEach.

Type Aliases

Accepts all arrays with at least one element.

A potentially asynchronous function used in collect methods to collect values from a collection. This is basically a single-pass map and filter.

A potentially lazy and/or asynchronous value of type T.

An AsyncReducer is a stand-alone asynchronous calculation that takes input values of type I, and, when requested, produces an output value of type O.

A function used in collect methods to collect values from a collection. This is basically a single-pass map and filter.

Indicates, when returned from a collect function, to skip the value.

A function returning true if given v1 and v2 should be considered equal.

A flexible range specification for numeric indices. If a start or end is defined, a tuple can be used where the second item is a boolean indicating whether that end is inclusive or exclusive. An IndexRange can have one of the following forms:

  • { amount: number }
  • { start: number }
  • { start: number, amount: number }
  • { start: number, end: number }
  • { start: number, end: [number, boolean] }
  • { start: [number, boolean] }
  • { start: [number, boolean], amount: number }
  • { start: [number, boolean], end: number }
  • { start: [number, boolean], end: [number, boolean] }
  • { end: number }
  • { end: [number, boolean] }

A type that is either a value T or a promise yielding a value of type T.

A potentially lazy value of type T.

A potentially lazy value that, in case of a lazy function, received a default value that it can return.

A range definition for any type of (orderable) value. If a start or end is defined, a tuple can be used where the second item is a boolean indicating whether that end is inclusive (true) or exclusive (false). A Range of type T can have one of the following forms:

  • { end: T }
  • { end: [T, boolean] }
  • { start: T }
  • { start: T, end: T }
  • { start: T, end: [T, boolean] }
  • { start: [T, boolean] }
  • { start: [T, boolean], end: T }
  • { start: [T, boolean], end: [T, boolean] }

A Reducer is a stand-alone calculation that takes input values of type I, and, when requested, produces an output value of type O.

Accepts all types of T and U where T extends U or U extends T.

Accepts all strings with at least one character.

Accepts all types of T and S where S extends T, and results in the lower bound S.

Accepts all types of T and U where T extends U, and result in the upper bound U.

A value of type T, or a function taking a value of type T and returning a new value of type T.