match
for core
Conditionally run a block on a matched value.
Signature
> match (value) (match_block)
Parameters
value
: value to checkmatch_block
: block to run if check succeeds
Examples
Match on a value in range
> match 3 { 1..10 => 'yes!' }
yes!
Match on a field in a record
> match {a: 100} { {a: $my_value} => { $my_value } }
100
Match with a catch-all
> match 3 { 1 => { 'yes!' }, _ => { 'no!' } }
no!
Match against a list
> match [1, 2, 3] { [$a, $b, $c] => { $a + $b + $c }, _ => 0 }
6
Match against pipeline input
> {a: {b: 3}} | match $in {{a: { $b }} => ($b + 10) }
13