Fuzion Logo
fuzion-lang.dev — The Fuzion Language Portal
»

group_map_reduce

Sequence.group_map_reduce

(K 
type
:
property.orderable, B 
type
, key_f Unary K Sequence.T, f Unary B Sequence.T, reduce_f Binary B B B)
 => 
container.Map K B
[Contains abstract features]
group elements using key_f and
reduce elements within a group by first applying f and then using reduce_f to reduce

example: count occurrences of letters, numbers and other characters

values array codepoint := ["A", "1", "b", "?", "X", "4"]

classify (c codepoint) String => c.is_ascii_letter ? "letter" : c.is_ascii_digit ? "digit" : "other"

values.group_map_reduce String i32 classify (_->1) (+)

=> {(digit => 2), (letter => 3), (other => 1)}

Type Parameters

type of the keys
type of the values in the result
0.094dev (2025-06-18 15:08:51 GIT hash 89cffc23ae669b0898a5564fefbf793fcb8e5ca7 built by fridi@fzen)