Exhaustive folding of a Souther sealed output union at the Clojure boundary.
Souther's match is total: every case of a union is handled. That guarantee is a compile-time
property of the generated code and is lost the moment a value crosses into Clojure, where a
forgotten case just silently falls through. case-of restores it: the generated union interface
is sealed, so its permitted subclasses are known by reflection, and case-of checks -- at macro
expansion -- that the handler map covers exactly those cases before emitting the dispatch.
Exhaustive folding of a Souther sealed output union at the Clojure boundary. Souther's `match` is total: every case of a union is handled. That guarantee is a compile-time property of the generated code and is lost the moment a value crosses into Clojure, where a forgotten case just silently falls through. `case-of` restores it: the generated union interface is sealed, so its permitted subclasses are known by reflection, and `case-of` checks -- at macro expansion -- that the handler map covers exactly those cases before emitting the dispatch.
(case-of union value handlers)Dispatch value to a handler in handlers, a map literal of {CaseClass handler-fn}. Each
handler-fn is called with the value. union is the sealed union class the cases belong to.
At macro-expansion time this verifies that handlers covers exactly the union's permitted
subclasses -- a missing or stray case is a compile error, carrying Souther's match totality
across the boundary.
Dispatch `value` to a handler in `handlers`, a map literal of {CaseClass handler-fn}. Each
handler-fn is called with the value. `union` is the sealed union class the cases belong to.
At macro-expansion time this verifies that `handlers` covers exactly the union's permitted
subclasses -- a missing or stray case is a compile error, carrying Souther's match totality
across the boundary.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 |