Skip to content

Type classes ​

All type classes live under com.github.kotlinz.kotlinz.type. They are interfaces over a type-constructor tag (see Higher-kinded types), and every instance is a public interface named <DataType><TypeClass> that you instantiate with object : MaybeMonad {}. The exceptions are Eq, Order, Show and Hash, which are ordinary interfaces over a value type (see Eq, Order, Show and Hash).

Guides ​

GuideType classes
Functor, Applicative, MonadInvariant, Functor, Pointed, Apply, Applicative, ApplicativeOps, FlatMap, Monad, MonadOps, Alternative, MonadPlus, MonadZip, MonadRec, MonadFix, IxFunctor, IxPointed, IxApplicative, IxMonad, Copointed, Comonad
SelectiveSelective, MonadSelective
Foldable and TraversableFoldable, Traversable, Foldable1, Traversable1, Bifoldable, Bitraversable
Align, Zip, Filterable and WitherableSemialign, Align, Zip, Filterable, Witherable
Errors and MTL-style classesApplicativeError, MonadError, MonadReader, MonadState, MonadWriter, MonadTrans, MFunctor, MonadIO, MonadCont, MonadLogic, lifted instances
Eq, Order, Show and HashEq, Order, Show, Hash
Contravariant functorsContravariant, Divisible, Decidable
Bifunctor, Profunctor and ArrowBifunctor, Profunctor, Strong, Choice, Closed, Traversing, Wander, Cochoice, Costrong, Compose, Category, Arrow, ArrowChoice, ArrowApply, ArrowLoop
Distributive and RepresentableDistributive, Representable

ComonadTrans, ComonadStore, ComonadEnv and ComonadTraced are covered in Comonads; Adjunction and NaturalTransformation in Category theory; Semigroup, Monoid, CommutativeMonoid, Group, Band, Monus, Semiring, Ring, Field and the lattices in Monoids and algebraic structures.

Hierarchy ​

text
Invariant ─┬─ Functor ─┬─ Apply ─┬─ Applicative (+ Pointed) ─┬─ Monad (+ FlatMap) ─┬─ MonadPlus (+ Alternative) ─ MonadLogic
           │           │         │                           │                     ├─ MonadZip, MonadRec, MonadFix, MonadOps
           │           │         │                           │                     ├─ MonadError (+ ApplicativeError)
           │           │         │                           │                     ├─ MonadReader, MonadState, MonadWriter
           │           │         │                           │                     ├─ MonadTrans, MonadIO, MonadCont
           │           │         │                           │                     └─ MonadSelective (+ Selective)
           │           │         │                           ├─ Selective
           │           │         │                           ├─ Alternative
           │           │         │                           └─ ApplicativeOps, ApplicativeError
           │           │         └─ FlatMap
           │           ├─ Traversable (+ Foldable) ─┬─ Traversable1 (+ Foldable1)
           │           │                            └─ Witherable (+ Filterable)
           │           ├─ Filterable
           │           ├─ Semialign ─┬─ Align
           │           │             └─ Zip
           │           ├─ Comonad (+ Copointed) ─ ComonadTrans, ComonadStore, ComonadEnv, ComonadTraced
           │           ├─ Distributive
           │           └─ Representable
           └─ Contravariant ─ Divisible ─ Decidable

Foldable ─ Foldable1
Bifunctor ─┐
Bifoldable ┴─ Bitraversable
MFunctor
IxFunctor ─ IxApplicative (+ IxPointed) ─ IxMonad
Profunctor ─┬─ Strong ─┐
            ├─ Choice ─┴─ Traversing (uses Wander)
            ├─ Closed
            ├─ Cochoice
            └─ Costrong
Compose ─ Category ─ Arrow ─┬─ ArrowChoice
                            ├─ ArrowApply
                            └─ ArrowLoop
Eq ─┬─ Order
    └─ Hash
Show

Coverage ​

Instances provided for each data type (✓). F/A/M = Functor / Applicative / Monad, Fo/Tr = Foldable / Traversable, Co = Comonad, EOSH = Eq, Order, Show, Hash factories. Types marked with * need a Class<M> for a Monoid or Semigroup (see Higher-kinded types).

Core data types ​

See Data types.

Data typeFAMFoTrCoEOSHOther
Identity✓✓✓✓✓✓✓Foldable1, Traversable1, MonadZip, MonadRec, MonadFix, Distributive, Representable<Unit>
Maybe✓✓✓✓✓✓Alternative, MonadPlus, MonadFix, Selective, Align, Zip, Witherable
Either<L, _>✓✓✓✓✓✓MonadError<L>, Selective, Bifunctor, Bitraversable, Witherable (monoidal L)
Try✓✓✓✓✓Eq, Show, HashMonadError<Throwable>
Validated<E, _> *✓✓✓Selective, Bifunctor, Bitraversable; error accumulation through Semigroup<E>
Ior<A, _> *✓✓✓✓Bifunctor, Bitraversable
Eval✓✓✓✓MonadRec, MonadFix
Reader<R, _>✓✓✓MonadReader<R>, MonadFix, Distributive, Representable<R>
Writer<W, _> *✓✓✓MonadWriter<W>, Bifunctor
State<S, _>✓✓✓MonadState<S>, MonadRec
IndexedState<I, O, _>✓ (I = O)IxFunctor, IxApplicative, IxMonad
RWS<R, W, S, _> *✓✓✓MonadReader, MonadWriter, MonadState
Cont<R, _>✓✓✓MonadCont
Select<R, _>✓✓✓
ListK✓✓✓✓✓✓Alternative, MonadPlus, MonadZip, Align, Zip, Witherable
NonEmptyList✓✓✓✓✓✓✓Foldable1, Traversable1, Semialign, Zip
Tuple2<S, _> *✓✓✓✓✓✓✓Foldable1, Traversable1, Bifunctor, Bitraversable
Twin✓Representable<Boolean>
Const<C, _> *✓✓Contravariant, Selective
Function0✓✓✓✓MonadFix
Function1<R, _>✓✓✓Category, Arrow, Profunctor, Strong, Choice, Closed, Traversing, Cochoice
Kleisli<F, _, _>Category, Arrow, ArrowChoice, ArrowApply, ArrowLoop (over MonadFix), Profunctor, Strong, Choice
Predicate, Equivalence, ComparisonContravariant, Decidable
Op<R, _>Contravariant, Decidable (needs Monoid<R>)
MonoidOf, SemigroupOfInvariant
Compose<F, G, _>, Product<F, G, _>✓✓✓
Coproduct<F, G, _>✓✓

Data structures, effects and automata ​

See Data structures, Effects and Automata.

Data typeFAMFoTrCoOther
LazyList✓✓✓✓✓Alternative, Align, Zip, Witherable
Chain✓✓✓✓✓Align, Zip, Witherable
Tree✓✓✓✓✓✓Foldable1, Traversable1, Semialign, Zip
NonEmptySet✓Foldable1
NonEmptyMap<K, _>✓✓✓Foldable1, Traversable1, Semialign
ListZipper✓✓✓✓Foldable1, Traversable1
IO✓✓✓MonadError<Throwable>, MonadIO
Resource✓✓✓
Parser✓✓✓Alternative, MonadPlus
Gen✓✓✓
Moore<I, _>✓✓✓Profunctor
Mealy<I, _>✓Category, Arrow, ArrowChoice, Profunctor, Strong
Fold<A, _>✓✓Profunctor
Cokleisli<W, _, _>Category, Arrow, Profunctor

Ref has no instances; its operations return IO.

Monad transformers ​

See Monad transformers and, for the lifted MTL instances, Lifting through transformers. Every transformer is Functor, Applicative, Monad and MonadTrans.

TransformerMFunctorMonadIOOther
MaybeT, EitherT, ReaderT, StateT, WriterT *, IdentityT✓✓native and lifted MonadReader / MonadState / MonadWriter / MonadError
RWST<F, R, W, S, _> *✓✓MonadReader, MonadWriter, MonadState
IorT<F, A, _> *✓✓MonadError<A>
AccumT<F, W, _> *✓✓
ContT<R, F, _>✓MonadCont
ListT<F, _>✓Alternative, MonadPlus
LogicT<F, _>✓Alternative, MonadPlus, MonadLogic
FreeT<F, M, _>✓
SelectT<R, F, _>
IndexedStateT<F, I, O, _>IxFunctor, IxApplicative, IxMonad (not a MonadTrans)

Comonads and category-theory constructs ​

See Comonads and Category theory.

Data typeFAMCoOther
Store, Env, Traced *✓✓ComonadStore / ComonadEnv / ComonadTraced respectively
StoreT, EnvT, TracedT *✓✓ComonadTrans, plus ComonadStore / ComonadEnv / ComonadTraced
Cofree, Density✓✓
CofreeT✓✓ComonadTrans
Day<F, G, _>✓✓✓
Free, Codensity, Freer✓✓✓
FreeAp✓✓
FreeSelective✓✓Selective
FreeCategory, FreeArrowCategory / Arrow
Yoneda, Coyoneda, Ran, Lan✓
Star, Costar, Forget, Taggedprofunctor classes, see Bifunctor, Profunctor and Arrow
Procompose, Cayley, TambaraProfunctor, Strong

Fix, Mu and Nu (fixed points for recursion schemes) have no instances; see Category theory. Profunctor optics (Iso, Lens, Prism, Optional, Traversal, Getter, Fold, Setter) are described in Optics.

Released under the Apache License 2.0.