Skip to content

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 ​

  1. Higher-kinded types and conventions: the K1 / T encoding, narrow, instance interfaces vs. member and companion helpers, how monoids are passed as Class<M>, and instance values for Eq / Order / Show / Hash. Read this first; everything else builds on it.
  2. Type classes: the hierarchy and a coverage matrix of which data type implements which class.
  3. 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.
  4. Data structures: LazyList, Chain, Tree, NonEmptySet, NonEmptyMap, ListZipper.
  5. Effects: IO, Resource, Ref, Parser, Gen, Logic.
  6. Monad comprehension (fx): do-notation with coroutines, fxReplay, and caveats.
  7. Monad transformers: MaybeT, EitherT, IorT, IdentityT, ReaderT, WriterT, StateT, IndexedStateT, RWST, AccumT, ContT, SelectT, ListT, LogicT, FreeT.
  8. Monoids and algebraic structures: monoids, CommutativeMonoid, Group, Band, Monus, Semiring, Ring, Field, lattices, MonoidOf / SemigroupOf.
  9. Optics: Iso, Lens, Prism, Optional, Traversal, Getter, Fold, Setter.
  10. Comonads: Store, Env, Traced, Cofree, Density and the comonad transformers.
  11. Automata and folds: Moore, Mealy, Fold, Cokleisli.
  12. Category theory: natural transformations, adjunctions, Yoneda / Coyoneda, Codensity, Kan extensions, Day convolution, Free / FreeAp / Freer / FreeSelective, FreeCategory / FreeArrow, and recursion schemes over Fix, Mu and Nu.

Known limitations at a glance ​

  • narrow is an unchecked cast, and K1 is invariant, so type arguments sometimes need to be spelled out (details).
  • Some <DataType>Applicative interfaces do not extend the matching functor; use the Monad instance where an Applicative is required (details).
  • Generic monoid classes (FirstMonoid<A>, MaxMonoid<A>, EndoMonoid<A>, ...) need an unchecked Class cast (details).
  • Alternative omits some / many, which do not terminate under strict evaluation.
  • ArrowLoop feedback is lazy: loop takes an arrow over Pair<A, () -> D>, and its only instance is Kleisli over a MonadFix (details).
  • Recursion schemes and long fx blocks are not stack-safe; MonadRec (Identity, Eval, State) and Free.foldMap into a MonadRec are.
  • IO and Eval bind chains are not trampolined.

Released under the Apache License 2.0.