Compile-time exhaustiveness checking for Malli :enum schemas.
Provides macros that emit case expressions while verifying at
macro-expansion time that every enum value is handled.
Usage: (def Status [:enum :draft :published :archived])
(enum-case Status status :draft (handle-draft) :published (handle-published) :archived (handle-archived))
If a branch is missing, macro expansion fails with a clear error.
Supports:
(:a :b) exprenum-case*Compile-time exhaustiveness checking for Malli :enum schemas.
Provides macros that emit `case` expressions while verifying at
macro-expansion time that every enum value is handled.
Usage:
(def Status [:enum :draft :published :archived])
(enum-case Status status
:draft (handle-draft)
:published (handle-published)
:archived (handle-archived))
If a branch is missing, macro expansion fails with a clear error.
Supports:
- Var-based schema references (symbol pointing to a def)
- Malli registry lookups (qualified keyword)
- Inline schema literals (vector)
- Grouped match values like `(:a :b) expr`
- Optional default branch via `enum-case*`(check-exhaustiveness schema-form provided-values)Programmatic (non-macro) exhaustiveness check. Returns nil if valid, or a map of {:missing #{...} :extra #{...}} if not.
Useful for building custom tooling or CI checks.
Example: (check-exhaustiveness [:enum :a :b :c] #{:a :b}) ;=> {:missing #{:c}, :extra #{}}
Programmatic (non-macro) exhaustiveness check. Returns nil if valid,
or a map of {:missing #{...} :extra #{...}} if not.
Useful for building custom tooling or CI checks.
Example:
(check-exhaustiveness [:enum :a :b :c] #{:a :b})
;=> {:missing #{:c}, :extra #{}}(enum-case schema-ref expr & clauses)Like case, but verifies at macro-expansion time that every value in
the Malli :enum schema is handled. No default branch is allowed.
schema-ref — a symbol (var name), qualified keyword (registry), or inline vector like [:enum :a :b :c] expr — the expression to dispatch on clauses — value/expr pairs; grouped values like (:a :b) are supported
Example: (def Status [:enum :draft :published :archived])
(enum-case Status status :draft (handle-draft) :published (handle-published) :archived (handle-archived))
Like `case`, but verifies at macro-expansion time that every value in
the Malli :enum schema is handled. No default branch is allowed.
schema-ref — a symbol (var name), qualified keyword (registry), or
inline vector like [:enum :a :b :c]
expr — the expression to dispatch on
clauses — value/expr pairs; grouped values like (:a :b) are supported
Example:
(def Status [:enum :draft :published :archived])
(enum-case Status status
:draft (handle-draft)
:published (handle-published)
:archived (handle-archived))(enum-case* schema-ref expr & clauses)Like enum-case, but allows an optional default (else) branch as the
last form when the clause count is odd.
Still validates that:
Example: (enum-case* Status status :draft (handle-draft) :published (handle-published) (handle-other))
Like `enum-case`, but allows an optional default (else) branch as the
last form when the clause count is odd.
Still validates that:
- Every provided value exists in the enum (no typos)
- If no default is given, all values must be covered
Example:
(enum-case* Status status
:draft (handle-draft)
:published (handle-published)
(handle-other))cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |