0.29.8 • Published 12 months ago

@effect/typeclass v0.29.8

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

Introduction

Welcome to the documentation for @effect/typeclass, a collection of re-usable typeclasses for the Effect ecosystem.

The functional abstractions in @effect/typeclass 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.

Concrete Types

Members and derived functions

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

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>

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

flowchart TD
    Alternative --> SemiAlternative
    Alternative --> Coproduct
    Applicative --> Product
    Coproduct --> SemiCoproduct
    SemiAlternative --> Covariant
    SemiAlternative --> SemiCoproduct
    SemiApplicative --> SemiProduct
    SemiApplicative --> Covariant
    Applicative --> SemiApplicative
    Chainable --> FlatMap
    Chainable ---> Covariant
    Monad --> FlatMap
    Monad --> Pointed
    Pointed --> Of
    Pointed --> Covariant
    Product --> SemiProduct
    Product --> Of
    SemiProduct --> Invariant
    Covariant --> Invariant
    SemiCoproduct --> Invariant

Members and derived functions

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:

0.29.8

12 months ago

0.29.7

12 months ago

0.29.6

12 months ago

0.29.5

12 months ago

0.29.4

12 months ago

0.29.3

12 months ago

0.29.2

1 year ago

0.29.1

1 year ago

0.29.0

1 year ago

0.24.47

1 year ago

0.24.46

1 year ago

0.24.49

1 year ago

0.24.48

1 year ago

0.24.43

1 year ago

0.24.42

1 year ago

0.24.45

1 year ago

0.24.44

1 year ago

0.24.41

1 year ago

0.24.40

1 year ago

0.24.39

1 year ago

0.24.36

1 year ago

0.24.35

1 year ago

0.24.38

1 year ago

0.24.37

1 year ago

0.25.4

1 year ago

0.24.32

1 year ago

0.25.3

1 year ago

0.24.31

1 year ago

0.25.2

1 year ago

0.24.34

1 year ago

0.25.1

1 year ago

0.24.33

1 year ago

0.25.0

1 year ago

0.24.30

1 year ago

0.25.8

1 year ago

0.25.7

1 year ago

0.25.6

1 year ago

0.25.5

1 year ago

0.24.29

1 year ago

0.24.28

1 year ago

0.24.25

1 year ago

0.24.24

1 year ago

0.24.27

1 year ago

0.24.26

1 year ago

0.24.21

1 year ago

0.24.20

1 year ago

0.24.23

1 year ago

0.24.22

1 year ago

0.24.18

1 year ago

0.24.19

1 year ago

0.26.3

1 year ago

0.26.2

1 year ago

0.26.1

1 year ago

0.26.0

1 year ago

0.27.2

1 year ago

0.27.1

1 year ago

0.27.0

1 year ago

0.27.5

1 year ago

0.27.4

1 year ago

0.27.3

1 year ago

0.28.1

1 year ago

0.28.0

1 year ago

0.24.50

1 year ago

0.24.52

1 year ago

0.24.51

1 year ago

0.28.2

1 year ago

0.24.17

1 year ago

0.24.16

1 year ago

0.24.15

1 year ago

0.24.14

1 year ago

0.24.13

1 year ago

0.24.12

1 year ago

0.24.11

1 year ago

0.24.10

1 year ago

0.24.9

1 year ago

0.24.8

1 year ago

0.24.7

1 year ago

0.24.6

1 year ago

0.24.5

1 year ago

0.24.4

1 year ago

0.24.3

2 years ago

0.24.2

2 years ago

0.24.1

2 years ago

0.23.19

2 years ago

0.24.0

2 years ago

0.23.18

2 years ago

0.23.17

2 years ago

0.23.16

2 years ago

0.23.15

2 years ago

0.23.14

2 years ago

0.23.13

2 years ago

0.23.12

2 years ago

0.23.11

2 years ago

0.23.10

2 years ago

0.23.9

2 years ago

0.23.8

2 years ago

0.23.7

2 years ago

0.23.6

2 years ago

0.23.5

2 years ago

0.23.4

2 years ago

0.23.3

2 years ago

0.23.2

2 years ago

0.23.1

2 years ago

0.23.0

2 years ago

0.22.23

2 years ago

0.22.22

2 years ago

0.22.21

2 years ago

0.22.20

2 years ago

0.22.19

2 years ago

0.22.18

2 years ago

0.22.17

2 years ago

0.22.16

2 years ago

0.22.15

2 years ago

0.22.14

2 years ago

0.22.13

2 years ago

0.22.12

2 years ago

0.22.11

2 years ago

0.22.10

2 years ago

0.22.9

2 years ago

0.22.8

2 years ago

0.22.7

2 years ago

0.22.6

2 years ago

0.22.5

2 years ago

0.22.4

2 years ago

0.22.3

2 years ago

0.22.2

2 years ago

0.22.1

2 years ago

0.22.0

2 years ago

0.21.0

2 years ago

0.20.0

2 years ago

0.19.0

2 years ago

0.19.1

2 years ago

0.18.0

2 years ago

0.17.1

2 years ago

0.17.0

2 years ago

0.16.0

2 years ago

0.15.0

2 years ago

0.14.1

2 years ago

0.14.0

2 years ago

0.13.1

2 years ago

0.13.0

2 years ago

0.12.0

2 years ago

0.11.0

2 years ago

0.10.0

2 years ago

0.9.0

2 years ago

0.8.0

2 years ago

0.7.0

2 years ago

0.6.2

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago