feat: add collection functions, string interpolation, and if()#53
Merged
feat: add collection functions, string interpolation, and if()#53
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 keysvalues(.obj)— Returns array of map valuesunique(.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 fieldConditional:
if(condition, then_value, else_value)— Ternary conditionalType checking:
is_array(.field)— Returns true/falseString Interpolation
Strings can now contain
{expr}for inline evaluation:{}remain as regular string literals{}\{for literal bracesTests (17 integration tests)
keys_of_map,values_of_map— Map introspectionunique_array— Deduplicationfirst_and_last,first_and_last_empty— Array element accesssum_integers,sum_floats— Numeric aggregationgroup_by_field— Grouping objectsif_true_branch,if_false_branch— Conditionalis_array_true,is_array_false— Type checkingstring_interpolation_basic,string_interpolation_multiple— Basic interpolationstring_interpolation_with_expression— Arithmetic in interpolationstring_no_interpolation_plain— Plain strings unaffectedstring_interpolation_with_function— Function calls in interpolationFixes #24