Class Comprehensions
DO macro.
The macro runs at SEMANTIC_ANALYSIS, before type checking, so it
cannot know the carrier's bind-method name and cannot emit it directly. Instead it
emits Comprehensions.bind(carrier) { x -> ... } calls; this class resolves
the carrier-specific method at runtime (dynamic Groovy), while the
groovy.typecheckers.MonadicChecker type-checking extension specialises this
one signature under @CompileStatic.
This is runtime support invoked from generated bytecode, hence its placement in
core alongside the rest of the Groovy runtime; the DO macro and the type
checker are compile-time only and remain in their optional modules.
Participation is resolved first-match-wins:
- standard allow-list (
MonadicCarrierRegistry); - structural (
flatMap/mappresent); @Monadicopt-in (matched by simple name; honoursbind/mapoverrides).
Surface generosity: the carrier's bind method may accept a Function or a
Closure; the closure is adapted to whichever the target declares. Monad
laws are not enforced — structural participation, algebraic-law obligation
on the implementer (the @Reducer/@Associative treatment).
- Since:
- 6.0.0
-
Method Summary
-
Method Details
-
bind
Bind (flatMap-shaped):carrier.<bind>(x -> fn(x))wherefnyields the same carrier. -
map
Map:carrier.<map>(x -> fn(x))wherefnyields a plain value.
-