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

group_map

Sequence.group_map

(K 
type
:
property.orderable, B 
type
, key_f Unary K Sequence.T, f Unary B Sequence.T)
 => 
container.Map K (Sequence B)
[Contains abstract features]
group the elements of this sequence by a key of type and applies function f to all elements

example: group characters by category and add underscores around each character

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 String String classify (x->"_{x}_")

=> {(digit => [_1_, _4_]), (letter => [_A_, _b_, _X_]), (other => [_?_])}

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)