# JS/FP

A pragmatic functional programming library for JavaScript/TypeScript

## Computation with monad(-like) objects

### Computation with one or two values

**Box**: computation with one value

**Pair**: computation with two values

###
*n* values

Computation with **List**: computation with zero, one or more values

**NonEmptyList**: computation with one or more values

### Computation with error handling

**Option**: computation with a value that may be present or absent

**Result**: synchronous computation that may succeed or fail, short-circuits when a failure occurs

**Validated**: like *Result*, but accumulates errors instead of short-circuiting

### Computation with a value and a context

**State**: stateful computation

**Writer**: computation with additional data (used for logging)

#### Writers

**StringWriter**: computation with log entries concatenated to a string

**ListWriter**: computation with log entries concatenated to a **List** instance

### Asynchronous computation

**Future**: asynchronous computation that may succeed or fail (a monadic alternative to Promises)

### High-level computation

**Program**: interpretation of program descriptions

## Functions

**Action**: wrapper around a function with no parameters that enables composition

**Arrow**: wrapper around a function with one or more parameters that enables composition and adaptation of the input

## Combination

### Combination with semigroups

**Semigroup**: a type that supports an associative binary operation

**objectCombination**: a function to create combination schemes for objects based on semigroups

### Combination with monoids

**Monoid**: a semigroup with an identity element

#### Boolean

**All**: combines two booleans using logical AND

**Any**: combines two booleans using logical OR

#### Number

**Min**: combines two numbers, resulting in the smallest of the two

**Max**: combines two numbers, resulting in the largest of the two

**Sum**: combines two numbers, resulting in the sum of the two

**Product**: combines two numbers, resulting in the product of the two

#### Date

**Earliest**: combines two dates, resulting in the earlier of the two

**Latest**: combines two dates, resulting in the later of the two

#### String

**StringConcatenation**: combines two string using concatenation

#### Array

**ArrayConcatenation**: combines two arrays using concatenation

#### List

**ListConcatenation**: combines two lists using concatenation

## Testing

### Equivalence

**Equivalence**: testing of equivalence between two values of the same type

**objectEquivalence**: a function to create equivalence schemes for objects based on member equivalences

**Equalities for basic types**: equalities for string, number, boolean and Date values and arrays of such values

### Order

**Order**: decision on the order of two values

**Ordering**: a type alias for the three possible outcomes (-1, 0 and 1)

### Predicate

**Predicate**: wrapper around predicate functions