tap when clause filtering

○ Planned This feature is planned but not yet implemented.

Feature: Tap when-clause filtering

Code

// ============================================================================
// VERIFIED REGRESSION TEST - DO NOT MODIFY WITHOUT DISCUSSION
// ============================================================================
// Test 504: Tap when clause filtering
// Tests that tap `when` clauses generate conditional code
//
// The `when` clause in tap definitions filters which events trigger the tap:
// - `~tap(foo -> *) | branch b when b.flag |> handler(...)` generates:
//     if (b.flag) { handler(...); }
//
// This test verifies:
// - Only entities with has_damage=true trigger handle_damage
// - Entities 1 and 3 (has_damage=false) are filtered out
// - Entities 2 and 4 (has_damage=true) trigger the tap handler

~import "$std/io"
~import "$std/control"
~import "$std/taps"

const std = @import("std");

const Entity = struct {
    id: u32,
    health: i32,
    has_damage: bool,
};

// Producer event - broadcasts entities
~pub event process_entity { e: Entity }
| entity { e: Entity }

~proc process_entity {
    return .{ .entity = .{ .e = e } };
}

// TAP: Should ONLY fire when entity has damage
// BUG: The `when ent.e.has_damage` is completely ignored
~tap(process_entity -> *)
| entity ent when ent.e.has_damage |> handle_damage(e: ent.e)

~event handle_damage { e: Entity }
~proc handle_damage {
    std.debug.print("DAMAGE on Entity {d}!\n", .{ e.id });
}

// Test entities - 2 with damage, 2 without
const entities = [_]Entity{
    .{ .id = 1, .health = 100, .has_damage = false },  // Should NOT trigger
    .{ .id = 2, .health = 80, .has_damage = true },    // Should trigger
    .{ .id = 3, .health = 50, .has_damage = false },   // Should NOT trigger
    .{ .id = 4, .health = 30, .has_damage = true },    // Should trigger
};

~event noop {}
~proc noop {}

~event print_done {}
~proc print_done {
    std.debug.print("Done!\n", .{});
}

~for(&entities)
| each e |> process_entity(e: e)
    | entity _ |> noop()
| done |> print_done()
input.kz

Expected Output

DAMAGE on Entity 2!
DAMAGE on Entity 4!
Done!