Skip to content

feat: implement each and when block statements#52

Merged
alvinreal merged 1 commit intomainfrom
fix/issue-23
Feb 22, 2026
Merged

feat: implement each and when block statements#52
alvinreal merged 1 commit intomainfrom
fix/issue-23

Conversation

@alvinreal
Copy link
Owner

Summary

Implements each and when block statements as specified in #23.

New Operations

each .path { ... } — Iterate over array elements, apply block to each

each .items { rename .x -> .y }
each .items { set .total = .price * .qty }
each .groups { each .members { rename .old -> .new } }

when <condition> { ... } — Conditional block execution

when .type == "admin" { set .perms = "all" }
each .users { when .role == "admin" { set .elevated = true } }

Behavior

  • each: applies all statements in the block to every array element
  • each on non-array: returns error
  • each on empty array: no-op
  • Nested each: fully supported for deeply nested structures
  • when true: block is applied to the value
  • when false: block is skipped, value unchanged
  • Multiple when: all evaluated independently in sequence
  • when inside each: per-element conditional logic

Tests (11 integration tests)

  • each_rename_in_elements — Rename in every element
  • each_computed_fields — Computed fields per element
  • each_on_non_array_error — Error on non-array
  • each_multiple_operations — Multiple ops in block
  • nested_each — Nested each blocks
  • each_empty_array — Empty array no-op
  • when_condition_true — Block applied
  • when_condition_false — Block skipped
  • multiple_when_blocks — Independent evaluation
  • when_inside_each — Conditional inside iteration
  • each_with_when_conditional_per_element — Per-element conditional

Fixes #23

- Add each statement: iterate over array elements, apply block to each
  - Supports nested each blocks for deeply nested arrays
  - Errors on non-array targets
  - No-op on empty arrays
- Add when statement: conditional block execution
  - Block applied when condition is truthy, skipped when falsy
  - Multiple when blocks evaluate independently
  - Supports nesting: when inside each for per-element conditionals
- Add parser support for block syntax with { } delimiters
- Add 11 integration tests covering all TDD scenarios

Fixes #23
@alvinreal alvinreal merged commit 3ab9ca7 into main Feb 22, 2026
6 checks passed
@github-actions github-actions bot mentioned this pull request Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mapping: each and when blocks

1 participant