This library is in flux. APIs may change without notice. Generated from source on 3/14/2026.

Taps

LESSON IN METAPROGRAMMING: This file implements event observation as a

taps.kz

Koru Standard Library: Event Taps ================================== LESSON IN METAPROGRAMMING: This file implements event observation as a compile-time AST transformation. Taps are not a language primitive - they're built using the same transform system available to any Koru library. THE TRANSFORMATION: Before: event() | branch b |> next_step(b.data) After: event() | branch b |> tap_call(b) |> next_step(b.data) That's it. A void call is inserted at the front of the continuation chain. The binding `b` remains in scope. The optimizer sees no difference between tap calls and regular calls - they're just steps in the flow. USAGE: ~import "$std/taps" // Concrete source + branch (has payload access) ~tap(source: myEvent, destination: *) | result r |> log(data: r.value) // Metatype branch (required for wildcard sources) ~tap(source: *, destination: *) | Profile p |> profiler(p)
// ============================================================================
// TAP TRANSFORM
// ============================================================================
// When the compiler encounters ~tap(...), this transform:
// 1. Parses the source/destination patterns
// 2. Walks the program AST finding matching transitions
// 3. Wraps matching continuations with the tap's void call
// 4. Removes the tap declaration (it compiled away)
~[keyword|comptime|transform]pub event tap {
    expr: Expression,
    invocation: *const Invocation,
    item: *const Item,
    program: *const Program,
    allocator: std.mem.Allocator
}
| transformed { program: *const Program }