Package: org.apache.groovy.runtime

## [Java] Class Comprehensions

- org.apache.groovy.runtime.Comprehensions

-     @Incubating
      public final class Comprehensions
      extends Object

  Runtime bind/map dispatcher for monadic comprehensions — the emit target of the `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:

  1. standard allow-list (MonadicCarrierRegistry);
  2. structural (`flatMap`/`map` present);
  3. `@Monadic` opt-in (matched by simple name; honours `bind`/`map` overrides).
  A configured marker interface is a further opt-in mechanism that is not yet implemented.

  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

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public static Object` | `bind(Object carrier, Closure<?> fn)` Bind (flatMap-shaped): {@code carrier.
    `` | `public static Object` | `map(Object carrier, Closure<?> fn)` Map: {@code carrier.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### public static Object bind(Object carrier, Closure<?> fn)

      Bind (flatMap-shaped): `carrier.<bind>(x -> fn(x))` where `fn` yields the same carrier.

    - #### public static Object map(Object carrier, Closure<?> fn)

      Map: `carrier.<map>(x -> fn(x))` where `fn` yields a plain value.