mapMaybe.scp (590B)
1 !export mapMaybe 2 -- Map each list element to an optional value and keep only present values. 3 -- Input: list; state: mapper descriptor. The mapper runs once per element 4 -- with its own initial state, returning leaf (skip) or stem value (keep). 5 -- A fork does not match either arm and fails; worker failures propagate. 6 -- Present leaf is retained and the original list order is preserved. 7 consumer mapMaybe 8 [] @ _ => [] 9 [x | xs] @ mapper => call mapper x as optional in 10 match optional of ( 11 leaf => recur xs @ mapper 12 | stem value => [value | recur xs @ mapper])