Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fun/combinable.ts

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

Combinable is a structure that can be combine two fixed values. Some examples of Combinable are Array.combine, addition for numbers, or merging of two structs by combining their internal values.

Functions

Create a combinable that always returns the given value, ignoring anything that it is combineenated with.

Get the "Dual" of an existing Combinable. This effectively reverses the order of the input combinable's application. For example, the dual of the "first" combinable is the "last" combinable. The dual of (boolean, ||) is itself.

Get an Combinable over A that always returns the first parameter supplied to combine (confusingly this is actually the last parameter since combine is in curried form).

Create a Combinable from a Combine and an init function.

Given a Combinable, create a function that will iterate through an array of values and combine them. This is not much more than Array.fold(combine).

Create a combinable that works like Array.join, inserting middle between every two values that are combineenated. This can have some interesting results.

Get an Combinable over A that always returns the last parameter supplied to combine (confusingly this is actually the first parameter since combine is in curried form).

Create a combinable fron an instance of Sortable that returns that maximum for the type being ordered. This Combinable functions identically to max from Sortable.

Create a combinable fron an instance of Sortable that returns that minimum for the type being ordered. This Combinable functions identically to min from Sortable.

Get a Combinable from a struct of combinables. The resulting combinable will operate over similar shaped structs applying the input combinables applying each based on its position,

Get a Combinable from a tuple of combinables. The resulting combinable will operate over tuples applying the input combinables applying each based on its position,

Interfaces

Combinable is a structure that allows the combination of two concrete values of A into a single value of A. In other functional libraries this is called a Semigroup.

Type Aliases

A type for Combinable over any, useful as an extension target for functions that take any Combinable and do not need to unwrap the type.

The Combine function in a Combinable.

A type level unwrapper, used to pull the inner type from a Combinable.