]> gitweb.factorcode.org Git - factor.git/commitdiff
grouping.extras: group-by docs: note consecutive behavior and link collect-by
authorAndy Kluger <AndyKluger@gmail.com>
Tue, 2 Apr 2024 16:48:31 +0000 (12:48 -0400)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 2 Apr 2024 17:03:13 +0000 (10:03 -0700)
extra/grouping/extras/extras-docs.factor

index add28a0332f45d5eea839fb2f651420013892e6b..b1e6867f825a2a4599a1437b739b892a3d461e42 100644 (file)
@@ -4,15 +4,22 @@ IN: grouping.extras
 
 HELP: group-by
 { $values { "seq" sequence } { "quot" { $quotation ( elt -- key ) } } { "groups" "a new assoc" } }
-{ $description "Groups the elements by the key received by applying quot to each element in the sequence." }
+{ $description "Groups consecutive elements by the key received by applying quot to each element in the sequence." }
 { $examples
   { $example
     "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\" \"!\" }"
   }
+  { $example
+    "USING: grouping.extras prettyprint sequences strings ;"
+    "{ \"apple\" \"anchovy\" \"banana\" \"anise\" \"bagel\" \"bratwurst\" } [ first 1string ] group-by ."
+    "V{\n    { \"a\" V{ \"apple\" \"anchovy\" } }\n    { \"b\" V{ \"banana\" } }\n    { \"a\" V{ \"anise\" } }\n    { \"b\" V{ \"bagel\" \"bratwurst\" } }\n}"
+  }
 } ;
 
+{ group-by collect-by } related-words
+
 HELP: <n-groups>
 { $values
     { "seq" sequence } { "n" integer }