The hkj-api module contains the heart of the Higher-Kinded-J library: a set of interfaces that define the core functional programming abstractions. This page provides a quick-reference lookup for all type classes, their key operations, and when to use them.
A concise overview of every type class in the library
The key method(s) each type class provides
When to reach for each abstraction
Links to the detailed documentation for each type class
┌──────────┐
│ Functor │ map
└────┬─────┘
│
┌────┴─────┐
│Applicative│ of, ap
└────┬─────┘
│
┌──────────────┼──────────────┐
│ │ │
┌─────┴─────┐ ┌─────┴─────┐ ┌─────┴─────┐
│ Monad │ │Alternative│ │ Selective │
│ flatMap │ │ orElse │ │ select │
└─────┬─────┘ └───────────┘ └───────────┘
│
┌─────┴─────┐
│MonadError │ raiseError, handleErrorWith
└───────────┘
Type Class Key Method(s) Purpose When to Use Docs
FunctormapTransform values inside a container You need to apply A -> B to a wrapped value Functor
Applicativeof, ap, map2Combine independent computations Validation with error accumulation; combining unrelated results Applicative
Alternativeempty, orElseChoice and fallback semantics Fallback chains; parser combinators; trying multiple sources Alternative
Selectiveselect, whenS, ifSConditional effects with static structure Feature flags; config-based branching where both branches are known upfront Selective
MonadflatMapSequence dependent computations Each step's effect depends on the previous step's result Monad
MonadErrorraiseError, handleErrorWithTyped error handling within monadic workflows Raising and recovering from domain-specific errors MonadError
MonadZerozeroFiltering in monadic chains Guard clauses in for-comprehensions (when()) MonadZero
Type Class Key Method(s) Purpose When to Use Docs
SemigroupcombineAssociatively merge two values of the same type Telling Validated how to accumulate errors Semigroup and Monoid
Monoidcombine, emptySemigroup with an identity element Folding collections (needs a starting value for empty cases) Semigroup and Monoid
Type Class Key Method(s) Purpose When to Use Docs
FoldablefoldMapReduce a structure to a summary value Summing, counting, concatenating, or aggregating any collection Foldable and Traverse
Traversetraverse, sequenceAIterate with effects, then flip the structure inside-out Validating every item in a list; batch fetching with error collection Foldable and Traverse
Type Class Key Method(s) Purpose When to Use Docs
Profunctorlmap, rmap, dimapTransform both input (contravariant) and output (covariant) Adapting functions to different input/output formats; optics foundation Profunctor
Bifunctorbimap, first, secondTransform both parameters of a two-parameter type (both covariant) Mapping over both sides of Either, Tuple2, Validated, or Writer Bifunctor
Kind<F, A> -- The foundational interface that emulates a higher-kinded type. It represents a type F that is generic over a type A. For example, Kind<ListKind.Witness, String> represents a List<String>. This interface is the common currency for all functional abstractions in the library.
Previous: Introduction
Next: Functor