Kotlinz guides
These guides explain how Kotlinz is put together and how to use it. Every Kotlin sample compiles against the current API and its check(...) assertions hold. New to Kotlinz? Start with Getting started. The guides are also published on the project website, next to the generated API reference.
Reading order
- Higher-kinded types and conventions: the
K1/Tencoding,narrow, instance interfaces vs. member and companion helpers, how monoids are passed asClass<M>, and instance values forEq/Order/Show/Hash. Read this first; everything else builds on it. - Type classes: the hierarchy and a coverage matrix of which data type implements which class.
- Functor, Applicative, Monad (and Comonad), including
Apply,FlatMapand indexed monads - Selective applicative functors
- Foldable and Traversable, including
Foldable1,Traversable1,BifoldableandBitraversable - Align and Filterable:
Semialign,Align,Zip,Filterable,Witherable - Errors and MTL-style classes:
MonadError,MonadReader,MonadState,MonadWriter,MonadCont,MonadIO,MonadTrans,MFunctorand lifted instances - Eq, Order, Show and Hash
- Contravariant functors:
Contravariant,Divisible,Decidable - Bifunctor, Profunctor and Arrow
- Distributive and Representable
- Functor, Applicative, Monad (and Comonad), including
- Data types:
Identity,Maybe,Either,Try,Validated,Ior,Eval,IO,Reader,Writer,State,IndexedState,RWS,Cont,Select,ListK,NonEmptyList,Tuple2,Twin,Const, functions and functor combinators. - Data structures:
LazyList,Chain,Tree,NonEmptySet,NonEmptyMap,ListZipper. - Effects:
IO,Resource,Ref,Parser,Gen,Logic. - Monad comprehension (
fx): do-notation with coroutines,fxReplay, and caveats. - Monad transformers:
MaybeT,EitherT,IorT,IdentityT,ReaderT,WriterT,StateT,IndexedStateT,RWST,AccumT,ContT,SelectT,ListT,LogicT,FreeT. - Monoids and algebraic structures: monoids,
CommutativeMonoid,Group,Band,Monus,Semiring,Ring,Field, lattices,MonoidOf/SemigroupOf. - Optics:
Iso,Lens,Prism,Optional,Traversal,Getter,Fold,Setter. - Comonads:
Store,Env,Traced,Cofree,Densityand the comonad transformers. - Automata and folds:
Moore,Mealy,Fold,Cokleisli. - Category theory: natural transformations, adjunctions, Yoneda / Coyoneda, Codensity, Kan extensions, Day convolution,
Free/FreeAp/Freer/FreeSelective,FreeCategory/FreeArrow, and recursion schemes overFix,MuandNu.
Known limitations at a glance
narrowis an unchecked cast, andK1is invariant, so type arguments sometimes need to be spelled out (details).- Some
<DataType>Applicativeinterfaces do not extend the matching functor; use theMonadinstance where anApplicativeis required (details). - Generic monoid classes (
FirstMonoid<A>,MaxMonoid<A>,EndoMonoid<A>, ...) need an uncheckedClasscast (details). Alternativeomitssome/many, which do not terminate under strict evaluation.ArrowLoopfeedback is lazy:looptakes an arrow overPair<A, () -> D>, and its only instance isKleisliover aMonadFix(details).- Recursion schemes and long
fxblocks are not stack-safe;MonadRec(Identity,Eval,State) andFree.foldMapinto aMonadRecare. IOandEvalbindchains are not trampolined.