group-by ( seq quot: ( elt -- key ) -- groups )


Vocabulary
grouping.extras

Inputs
seqa sequence
quota quotation with stack effect ( elt -- key )


Outputs
groupsa new assoc


Word description
Groups consecutive elements by the key received by applying quot to each element in the sequence.

Examples
USING: grouping.extras unicode.data prettyprint sequences strings ; "THis String Has CasE!" [ category ] group-by [ last >string ] { } map-as .
{ "TH" "is" " " "S" "tring" " " "H" "as" " " "C" "as" "E" "!" }

USING: grouping.extras prettyprint sequences strings ; { "apple" "anchovy" "banana" "anise" "bagel" "bratwurst" } [ first 1string ] group-by .
V{ { "a" V{ "apple" "anchovy" } } { "b" V{ "banana" } } { "a" V{ "anise" } } { "b" V{ "bagel" "bratwurst" } } }


See also
collect-by

Definition