Skip to content

feat: add collection functions, string interpolation, and if()#53

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

feat: add collection functions, string interpolation, and if()#53
alvinreal merged 1 commit intomainfrom
fix/issue-24

Conversation

@alvinreal
Copy link
Owner

Summary

Adds collection functions, string interpolation, conditional function, and type checking as specified in #24.

New Functions

Collection functions:

  • keys(.obj) — Returns array of map keys
  • values(.obj) — Returns array of map values
  • unique(.arr) — Removes duplicates from array (preserves order)
  • first(.arr) / last(.arr) — First/last element (null for empty)
  • sum(.arr) — Sum of numeric array (returns int or float)
  • group_by(.arr, "field") / groupby() — Group array of objects by field

Conditional:

  • if(condition, then_value, else_value) — Ternary conditional

Type checking:

  • is_array(.field) — Returns true/false

String Interpolation

Strings can now contain {expr} for inline evaluation:

set .greeting = "Hello, {.name}!"
set .full = "{.first} {.last}"
set .desc = "Total: {.price * .qty}"
set .msg = "Hi, {lower(.name)}!"
  • Plain strings without {} remain as regular string literals
  • Supports field references, arithmetic, and function calls inside {}
  • Escape with \{ for literal braces

Tests (17 integration tests)

  • keys_of_map, values_of_map — Map introspection
  • unique_array — Deduplication
  • first_and_last, first_and_last_empty — Array element access
  • sum_integers, sum_floats — Numeric aggregation
  • group_by_field — Grouping objects
  • if_true_branch, if_false_branch — Conditional
  • is_array_true, is_array_false — Type checking
  • string_interpolation_basic, string_interpolation_multiple — Basic interpolation
  • string_interpolation_with_expression — Arithmetic in interpolation
  • string_no_interpolation_plain — Plain strings unaffected
  • string_interpolation_with_function — Function calls in interpolation

Fixes #24

- Add collection functions: keys(), values(), unique(), first(), last(),
  sum(), group_by()/groupby()
- Add conditional function: if(condition, then, else)
- Add type checking: is_array()
- Add string interpolation with {expr} syntax in string literals
  - Supports field references, arithmetic, and function calls
  - Plain strings without {} remain as regular string literals
  - Escape \{ to include literal braces
- Add 17 integration tests covering all new features

Fixes #24
@alvinreal alvinreal merged commit 13e7bd7 into main Feb 22, 2026
6 checks passed
@alvinreal alvinreal deleted the fix/issue-24 branch February 22, 2026 02:40
@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: arithmetic, string interpolation, and remaining functions

1 participant