Skip to main content

Module util

Module util 

Source
Expand description

Shared helpers used across eval / vm:

  • cmp_vals: total ordering on Val (null < bool < num < str < arr < obj), used by sort, min, max, top-N, distinct. Unlike PartialOrd, this never returns None — it uses a lexicographic fallback when types are incomparable, which is essential for heap-based partial sorts.
  • add_vals / num_op: numeric widening + arithmetic dispatch shared by the tree-walker and the VM so both semantics match.
  • val_key: canonical string key for grouping / dedup.
  • flatten_val / zip_arrays / cartesian / deep_merge: array / object combinators reused by builtins.
  • val_str / val_to_string: coercion helpers for string methods and CSV emission.

Functions§

add_vals
cartesian
cmp_vals
deep_merge
deep_merge_concat
Deep-merge where arrays concatenate instead of replace. Used by the ...** spread operator. Objects recurse, arrays concat, scalars rhs-wins.
field_exists_nested
flatten_val
is_truthy
kind_matches
num_op
obj2
Build a Val::Obj with two string-key entries (common pattern for itertools output).
val_float
val_int
val_key
val_str
val_to_key
Canonical string key for use in HashSets / dedup (never allocates for Str).
val_to_string
vals_eq
zip_arrays