Core API Interfaces: Quick Reference

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.

What You'll Learn

  • 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

The Monad Hierarchy

                    ┌──────────┐
                    │  Functor │  map
                    └────┬─────┘
                         │
                    ┌────┴─────┐
                    │Applicative│  of, ap
                    └────┬─────┘
                         │
          ┌──────────────┼──────────────┐
          │              │              │
    ┌─────┴─────┐  ┌─────┴─────┐  ┌─────┴─────┐
    │   Monad   │  │Alternative│  │ Selective │
    │  flatMap  │  │ orElse    │  │  select   │
    └─────┬─────┘  └───────────┘  └───────────┘
          │
    ┌─────┴─────┐
    │MonadError │  raiseError, handleErrorWith
    └───────────┘
Type ClassKey Method(s)PurposeWhen to UseDocs
FunctormapTransform values inside a containerYou need to apply A -> B to a wrapped valueFunctor
Applicativeof, ap, map2Combine independent computationsValidation with error accumulation; combining unrelated resultsApplicative
Alternativeempty, orElseChoice and fallback semanticsFallback chains; parser combinators; trying multiple sourcesAlternative
Selectiveselect, whenS, ifSConditional effects with static structureFeature flags; config-based branching where both branches are known upfrontSelective
MonadflatMapSequence dependent computationsEach step's effect depends on the previous step's resultMonad
MonadErrorraiseError, handleErrorWithTyped error handling within monadic workflowsRaising and recovering from domain-specific errorsMonadError
MonadZerozeroFiltering in monadic chainsGuard clauses in for-comprehensions (when())MonadZero

Data Aggregation Type Classes

Type ClassKey Method(s)PurposeWhen to UseDocs
SemigroupcombineAssociatively merge two values of the same typeTelling Validated how to accumulate errorsSemigroup and Monoid
Monoidcombine, emptySemigroup with an identity elementFolding collections (needs a starting value for empty cases)Semigroup and Monoid

Structure-Iterating Type Classes

Type ClassKey Method(s)PurposeWhen to UseDocs
FoldablefoldMapReduce a structure to a summary valueSumming, counting, concatenating, or aggregating any collectionFoldable and Traverse
Traversetraverse, sequenceAIterate with effects, then flip the structure inside-outValidating every item in a list; batch fetching with error collectionFoldable and Traverse

Dual-Parameter Type Classes

Type ClassKey Method(s)PurposeWhen to UseDocs
Profunctorlmap, rmap, dimapTransform both input (contravariant) and output (covariant)Adapting functions to different input/output formats; optics foundationProfunctor
Bifunctorbimap, first, secondTransform both parameters of a two-parameter type (both covariant)Mapping over both sides of Either, Tuple2, Validated, or WriterBifunctor

Core HKT Abstraction

  • 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.

See Also


Previous: Introduction Next: Functor