ForEach and blocks¶
New in 1.4
The | ForEach operator and {} block syntax are part of the new
parser.
ForEach (|)¶
The | operator applies a mapping rule to every element of an ARRAY,
returning a new ARRAY:
Read left-to-right: take :codes (an array), drop any "." elements, then
cast each remaining element to INT, producing a new array :int_codes.
| and => compose freely:
Use(:f1, :f2, :f3, :f4)[4] # collect 4 fields into an ARRAY
=> RemoveItem(".") # drop placeholder elements
| AsInt() # cast each remaining element
=> :year_of_birth # store the resulting array
Blocks ({})¶
A block groups multiple rule chains that share a scope:
{
:raw => UsagiMap("a.csv") => :ua
:raw => VocabMap("ICD10") => :vm
Selector(:ua, "!=", NULL, :ua, :vm)
}
All chains inside the block see the same field environment, and the block's final value is the chain's overall output.
See Arrays and New Mode for the underlying ARRAY type and
the array-aware rules.