Effect's Types

The functional abstractions in @effect/data can be broadly divided into two categories.

  • Abstractions For Concrete Types - These abstractions define properties of concrete types, such as number and string, as well as ways of combining those values.
  • Abstractions For Parameterized Types - These abstractions define properties of parameterized types such as ReadonlyArray and Option and ways of combining them.

Standard TypeScript Types

Strings

ModuleNameGivenTo
EquivalencestringEquivalence<string>
OrderstringOrder<string>
SemigroupstringSemigroup<string>
MonoidstringMonoid<string>
PredicateisStringRefinement<unknown, string>
StringEquivalenceEquivalence<string>
StringOrderOrder<string>
StringSemigroupSemigroup<string>
StringMonoidMonoid<string>
StringisStringRefinement<unknown, string>

Numbers

ModuleNameGivenTo
EquivalencenumberEquivalence<number>
OrdernumberOrder<number>
BoundednumberBounded<number>
SemigroupnumberSumSemigroup<number>
SemigroupnumberMultiplySemigroup<number>
MonoidnumberSumMonoid<number>
MonoidnumberMultiplyMonoid<number>
PredicateisNumberRefinement<unknown, number>
NumberEquivalenceEquivalence<number>
NumberOrderOrder<number>
NumberSemigroupSumSemigroup<number>
NumberSemigroupMultiplySemigroup<number>
NumberSemigroupMaxSemigroup<number>
NumberSemigroupMinSemigroup<number>
NumberMonoidSumMonoid<number>
NumberMonoidMultiplyMonoid<number>
NumberMonoidMaxMonoid<number>
NumberMonoidMinMonoid<number>
NumberisNumberRefinement<unknown, number>

Booleans

ModuleNameGivenTo
EquivalencebooleanEquivalence<boolean>
OrderbooleanOrder<boolean>
SemigroupbooleanAnySemigroup<boolean>
SemigroupbooleanAllSemigroup<boolean>
MonoidbooleanAnyMonoid<boolean>
MonoidbooleanAllMonoid<boolean>
PredicateisBooleanRefinement<unknown, boolean>
BooleanEquivalenceEquivalence<boolean>
BooleanOrderOrder<boolean>
BooleanbooleanAnySemigroup<boolean>
BooleanbooleanAllSemigroup<boolean>
BooleanbooleanAnyMonoid<boolean>
BooleanbooleanAllMonoid<boolean>
BooleanisBooleanRefinement<unknown, boolean>

Bigints

ModuleNameGivenTo
EquivalencebigintEquivalence<bigint>
OrderbigintOrder<bigint>
SemigroupbigintSumSemigroup<bigint>
SemigroupbigintMultiplySemigroup<bigint>
MonoidbigintSumMonoid<bigint>
MonoidbigintMultiplyMonoid<bigint>
PredicateisBigintRefinement<unknown, bigint>
BigintEquivalenceEquivalence<bigint>
BigintOrderOrder<bigint>
BigintSemigroupSumSemigroup<bigint>
BigintSemigroupMultiplySemigroup<bigint>
BigintMonoidSumMonoid<bigint>
BigintMonoidMultiplyMonoid<bigint>
BigintisBigintRefinement<unknown, bigint>

Symbols

ModuleNameGivenTo
EquivalencesymbolEquivalence<symbol>
PredicateisSymbolRefinement<unknown, symbol>
SymbolisSymbolRefinement<unknown, symbol>

Tuples

This section covers the various modules and combinators that work with tuples.

ModuleNameGivenTo
Equivalencetuple[Equivalence<A>, Equivalence<B>, ...]Equivalence<readonly [A, B, ...]>
Ordertuple[Order<A>, Order<B>, ...]Order<readonly [A, B, ...]>
Semigrouptuple[Semigroup<A>, Semigroup<B>, ...]Semigroup<[A, B, ...]>
Monoidtuple[Monoid<A>, Monoid<B>, ...]Monoid<[A, B, ...]>
SemiProductnonEmptyTuple[F<A>, F<B>, ...] (cannot be empty)F<[A, B, ...]>
Producttuple[F<A>, F<B>, ...]F<[A, B, ...]>
Eithertuple[Either<E1, A>, Either<E2, B>, ...]Either<E1 | E2 | ..., [A, B, ...]>
Optiontuple[Option<A>, Option<B>, ...]Option<[A, B, ...]>
Predicatetuple[Predicate<A>, Predicate<B>, ...]Predicate<readonly [A, B, ...]>
Thesetuple[These<E1, A>, These<E2, B>, ...]These<E1 | E2 | ..., [A, B, ...]>
TuplegetEquivalence[Equivalence<A>, Equivalence<B>, ...]Equivalence<readonly [A, B, ...]>
TuplegetOrder[Order<A>, Order<B>, ...]Order<readonly [A, B, ...]>
TuplegetSemigroup[Semigroup<A>, Semigroup<B>, ...]Semigroup<[A, B, ...]>
TuplegetMonoid[Monoid<A>, Monoid<B>, ...]Monoid<[A, B, ...]>
TuplenonEmptyProduct[F<A>, F<B>, ...] (cannot be empty)F<[A, B, ...]>
Tupleproduct[F<A>, F<B>, ...]F<[A, B, ...]>

Arrays

This section covers the various modules and combinators that work with arrays.

ModuleNameGivenTo
EquivalencearrayEquivalence<A>Equivalence<ReadonlyArray<A>>
OrderarrayOrder<A>Order<ReadonlyArray<A>>
SemigrouparrayASemigroup<Array<A>>
SemigroupreadonlyArrayASemigroup<ReadonlyArray<A>>
MonoidarrayAMonoid<Array<A>>
MonoidreadonlyArrayAMonoid<ReadonlyArray<A>>
ReadonlyArraygetSemigroupASemigroup<ReadonlyArray<A>>
ReadonlyArraygetMonoidAMonoid<ReadonlyArray<A>>

Structs

This section covers the various modules and combinators that work with structs.

ModuleNameGivenTo
Equivalencestruct{ a: Equivalence<A>, b: Equivalence<B>, ... }Equivalence<{ a: A, b: B, ... }>
Orderstruct{ a: Order<A>, b: Order<B>, ... }Order<{ a: A, b: B, ... }>
Semigroupstruct{ a: Semigroup<A>, b: Semigroup<B>, ... }Semigroup<{ a: A, b: B, ... }>
Monoidstruct{ a: Monoid<A>, b: Monoid<B>, ... }Monoid<{ a: A, b: B, ... }>
SemiProductnonEmptyStruct{ a: F<A>, b: F<B>, ... } (cannot be empty)F<{ a: A, b: B, ... }>
Productstruct{ a: F<A>, b: F<B>, ... }F<{ a: A, b: B, ... }>
Eitherstruct{ a: Either<E1, A>, b: Either<E2, B>, ... }Either<E1 | E2 | ..., { a: A, b: B }>
Optionstruct{ a: Option<A>, b: Option<B>, ... }Option<{ a: A, b: B }>
Predicatestruct{ a: Predicate<A>, b: Predicate<B>, ... }Predicate<Readonly<{ a: A, b: B }>>
Thesestruct{ a: These<E1, A>, b: These<E2, B>, ... }These<E1 | E2 | ..., { a: A, b: B }>
StructgetEquivalence{ a: Equivalence<A>, b: Equivalence<B>, ... }Equivalence<{ a: A, b: B, ... }>
StructgetOrder{ a: Order<A>, b: Order<B>, ... }Order<{ a: A, b: B, ... }>
StructgetSemigroup{ a: Semigroup<A>, b: Semigroup<B>, ... }Semigroup<{ a: A, b: B, ... }>
StructgetMonoid{ a: Monoid<A>, b: Monoid<B>, ... }Monoid<{ a: A, b: B, ... }>
StructnonEmptyProduct{ a: F<A>, b: F<B>, ... } (cannot be empty)F<{ a: A, b: B, ... }>
Structproduct{ a: F<A>, b: F<B>, ... }F<{ a: A, b: B, ... }>

Records

This section covers the various modules and combinators that work with records.

ModuleNameGivenTo
EquivalencerecordEquivalence<A>Equivalence<ReadonlyRecord<A>>
ReadonlyRecordgetkey: string, ReadonlyRecord<A>Option<A>
ReadonlyRecordreplaceOptionkey: string, B, ReadonlyRecord<A>Option<Record<string, A | B>>
ReadonlyRecordmodifyOptionkey: string, A => B, ReadonlyRecord<A>Option<Record<string, A | B>>

Concrete Types

Note: members are in bold.

Bounded

A type class used to name the lower limit and the upper limit of a type.

Extends:

  • Order
NameGivenTo
maxBoundA
minBoundA
reverseBounded<A>Bounded<A>
clampAA

Equivalence

Equivalence defines a binary relation that is reflexive, symmetric, and transitive. In other words, it defines a notion of equivalence between values of a certain type. These properties are also known in mathematics as an "equivalence relation".

NameGivenTo
strictAEquivalence<A>
tuple[Equivalence<A>, Equivalence<B>, ...]Equivalence<[A, B, ...]>
arrayEquivalence<A>Equivalence<A[]>
struct{ a: Equivalence<A>, b: Equivalence<B>, ... }Equivalence<{ a: A, b: B, ... }>
recordEquivalence<A>Equivalence<{ readonly [x: string]: A }>
getSemigroupASemigroup<Equivalence<A>>
getMonoidAMonoid<Equivalence<A>>
contramapEquivalence<A>, B => AEquivalence<B>

Monoid

A Monoid is a Semigroup with an identity. A Monoid is a specialization of a Semigroup, so its operation must be associative. Additionally, x |> combine(empty) == empty |> combine(x) == x. For example, if we have Monoid<String>, with combine as string concatenation, then empty = "".

Extends:

  • Semigroup
NameGivenTo
emptyA
combineAllIterable<A>A
reverseMonoid<A>Monoid<A>
tuple[Monoid<A>, Monoid<B>, ...]Monoid<[A, B, ...]>
struct{ a: Monoid<A>, b: Monoid<B>, ... }Monoid<{ a: A, b: B, ... }>
minBounded<A>Monoid<A>
maxBounded<A>Monoid<A>

Order

The Order type class is used to define a total ordering on some type A. An order is defined by a relation <=, which obeys the following laws:

  • either x <= y or y <= x (totality)
  • if x <= y and y <= x, then x == y (antisymmetry)
  • if x <= y and y <= z, then x <= z (transitivity)

The truth table for compare is defined as follows:

x <= yx >= yOrdering
truetrue0corresponds to x == y
truefalse< 0corresponds to x < y
falsetrue> 0corresponds to x > y

By the totality law, x <= y and y <= x cannot be both false.

NameGivenTo
compareA, AOrdering
reverseOrder<A>Order<A>
contramapOrder<A>, B => AOrder<B>
getSemigroupSemigroup<Order<A>>
getMonoidMonoid<Order<A>>
tuple[Order<A>, Order<B>, ...]Order<[A, B, ...]>
lessThanA, Aboolean
greaterThanA, Aboolean
lessThanOrEqualToA, Aboolean
greaterThanOrEqualToA, Aboolean
minA, Aboolean
maxA, Aboolean
clampA, AA
betweenAboolean

Semigroup

A Semigroup is any set A with an associative operation (combine):

x |> combine(y) |> combine(z) == x |> combine(y |> combine(z))

NameGivenTo
combineA, AA
combineManyA, Iterable<A>A
reverseSemigroup<A>Semigroup<A>
tuple[Semigroup<A>, Semigroup<B>, ...]Semigroup<[A, B, ...]>
struct{ a: Semigroup<A>, b: Semigroup<B>, ... }Semigroup<{ a: A, b: B, ... }>
minOrder<A>Semigroup<A>
maxOrder<A>Semigroup<A>
constantASemigroup<A>
intercalateA, Semigroup<A>Semigroup<A>
firstSemigroup<A>
lastSemigroup<A>

Parameterized Types

Parameterized Types Hierarchy


Note: members are in bold.

Alternative

Extends:

  • SemiAlternative
  • Coproduct

Applicative

Extends:

  • SemiApplicative
  • Product
NameGivenTo
liftMonoidMonoid<A>Monoid<F<A>>

Bicovariant

A type class of types which give rise to two independent, covariant functors.

NameGivenTo
bimapF<E1, A>, E1 => E2, A => BF<E2, B>
mapLeftF<E1, A>, E1 => E2F<E2, A>
mapF<A>, A => BF<B>

Chainable

Extends:

  • FlatMap
  • Covariant
NameGivenTo
tapF<A>, A => F<B>F<A>
andThenDiscardF<A>, F<B>F<A>
bindF<A>, name: string, A => F<B>F<A & { [name]: B }>

Contravariant

Contravariant functors.

Extends:

  • Invariant
NameGivenTo
contramapF<A>, B => AF<B>
contramapCompositionF<G<A>>, A => BF<G<B>>
imapcontramapimap

Coproduct

Coproduct is a universal monoid which operates on kinds.

This type class is useful when its type parameter F<_> has a structure that can be combined for any particular type, and which also has a "zero" representation. Thus, Coproduct is like a Monoid for kinds (i.e. parametrized types).

A Coproduct<F> can produce a Monoid<F<A>> for any type A.

Here's how to distinguish Monoid and Coproduct:

  • Monoid<A> allows A values to be combined, and also means there is an "empty" A value that functions as an identity.

  • Coproduct<F> allows two F<A> values to be combined, for any A. It also means that for any A, there is an "zero" F<A> value. The combination operation and zero value just depend on the structure of F, but not on the structure of A.

Extends:

  • SemiCoproduct
NameGivenTo
zeroF<A>
coproductAllIterable<F<A>>F<A>
getMonoidMonoid<F<A>>

Covariant

Covariant functors.

Extends:

  • Invariant
NameGivenTo
mapF<A>, A => BF<B>
mapCompositionF<G<A>>, A => BF<G<B>>
imapmapimap
flapA, F<A => B>F<B>
asF<A>, BF<B>
asUnitF<A>F<void>

Filterable

Filterable<F> allows you to map and filter out elements simultaneously.

NameGivenTo
partitionMapF<A>, A => Either<B, C>[F<B>, F<C>]
filterMapF<A>, A => Option<B>F<B>
compactF<Option<A>>F<A>
separateF<Either<A, B>>[F<A>, F<B>]
filterF<A>, A => booleanF<A>
partitionF<A>, A => boolean[F<A>, F<A>]
partitionMapCompositionF<G<A>>, A => Either<B, C>[F<G<B>>, F<G<C>>]
filterMapCompositionF<G<A>>, A => Option<B>F<G<B>>

FlatMap

NameGivenTo
flatMapF<A>, A => F<B>F<B>
flattenF<F<A>>F<A>
andThenF<A>, F<B>F<B>
composeKleisliArrowA => F<B>, B => F<C>A => F<C>

Foldable

Data structures that can be folded to a summary value.

In the case of a collection (such as ReadonlyArray), these methods will fold together (combine) the values contained in the collection to produce a single result. Most collection types have reduce methods, which will usually be used by the associated Foldable<F> instance.

NameGivenTo
reduceF<A>, B, (B, A) => BB
reduceCompositionF<G<A>>, B, (B, A) => BB
reduceRightF<A>, B, (B, A) => BB
foldMapF<A>, Monoid<M>, A => MM
toReadonlyArrayF<A>ReadonlyArray<A>
toReadonlyArrayWithF<A>, A => BReadonlyArray<B>
reduceKindMonad<G>, F<A>, B, (B, A) => G<B>G<B>
reduceRightKindMonad<G>, F<A>, B, (B, A) => G<B>G<B>
foldMapKindCoproduct<G>, F<A>, (A) => G<B>G<B>

Invariant

Invariant functors.

NameGivenTo
imapF<A>, A => B, B => AF<B>
imapCompositionF<G<A>>, A => B, B => AF<G<B>>
bindToF<A>, name: stringF<{ [name]: A }>
tupledF<A>F<[A]>

Monad

Allows composition of dependent effectful functions.

Extends:

  • FlatMap
  • Pointed

Of

NameGivenTo
ofAF<A>
ofCompositionAF<G<A>>
unitF<void>
DoF<{}>

Pointed

Extends:

  • Covariant
  • Of

Product

Extends:

  • SemiProduct
  • Of
NameGivenTo
productAllIterable<F<A>>F<ReadonlyArray<A>>
tuple[F<A>, F<B>, ...]F<[A, B, ...]>
struct{ a: F<A>, b: F<B>, ... }F<{ a: A, b: B, ... }>

SemiAlternative

Extends:

  • SemiCoproduct
  • Covariant

SemiApplicative

Extends:

  • SemiProduct
  • Covariant
NameGivenTo
liftSemigroupSemigroup<A>Semigroup<F<A>>
apF<A => B>, F<A>F<B>
andThenDiscardF<A>, F<B>F<A>
andThenF<A>, F<B>F<B>
lift2(A, B) => C(F<A>, F<B>) => F<C>
lift3(A, B, C) => D(F<A>, F<B>, F<C>) => F<D>

SemiCoproduct

SemiCoproduct is a universal semigroup which operates on kinds.

This type class is useful when its type parameter F<_> has a structure that can be combined for any particular type. Thus, SemiCoproduct is like a Semigroup for kinds (i.e. parametrized types).

A SemiCoproduct<F> can produce a Semigroup<F<A>> for any type A.

Here's how to distinguish Semigroup and SemiCoproduct:

  • Semigroup<A> allows two A values to be combined.

  • SemiCoproduct<F> allows two F<A> values to be combined, for any A. The combination operation just depends on the structure of F, but not the structure of A.

Extends:

  • Invariant
NameGivenTo
coproductF<A>, F<B>F<A | B>
coproductManyIterable<F<A>>F<A>
getSemigroupSemigroup<F<A>>
coproductEitherF<A>, F<B>F<Either<A, B>>

SemiProduct

Extends:

  • Invariant
NameGivenTo
productF<A>, F<B>F<[A, B]>
productManyF<A>, Iterable<F<A>>F<[A, ...ReadonlyArray<A>]>
productCompositionF<G<A>>, F<G<B>>F<G<[A, B]>>
productManyCompositionF<G<A>>, Iterable<F<G<A>>>F<G<[A, ...ReadonlyArray<A>]>>
nonEmptyTuple[F<A>, F<B>, ...]F<[A, B, ...]>
nonEmptyStruct{ a: F<A>, b: F<B>, ... }F<{ a: A, b: B, ... }>
andThenBindF<A>, name: string, F<B>F<A & { [name]: B }>
productFlattenF<A>, F<B>F<[...A, B]>

Traversable

Traversal over a structure with an effect.

NameGivenTo
traverseApplicative<F>, T<A>, A => F<B>F<T<B>>
traverseCompositionApplicative<F>, T<G<A>>, A => F<B>F<T<G<B>>>
sequenceApplicative<F>, T<F<A>>F<T<A>>
traverseTapApplicative<F>, T<A>, A => F<B>F<T<A>>

TraversableFilterable

TraversableFilterable, also known as Witherable, represents list-like structures that can essentially have a traverse and a filter applied as a single combined operation (traverseFilter).

NameGivenTo
traversePartitionMapApplicative<F>, T<A>, A => F<Either<B, C>>F<[T<B>, T<C>]>
traverseFilterMapApplicative<F>, T<A>, A => F<Option<B>>F<T<B>>
traverseFilterApplicative<F>, T<A>, A => F<boolean>F<T<A>>
traversePartitionApplicative<F>, T<A>, A => F<boolean>F<[T<A>, T<A>]>

Adapted from: