We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7fc552e commit a4afe0fCopy full SHA for a4afe0f
Stdlib/Data/List/Base.juvix
@@ -285,3 +285,16 @@ transpose {A} : (listOfLists : List (List A)) -> List (List A)
285
| nil := nil
286
| (xs :: nil) := listMap λ{x := x :: nil} xs
287
| (xs :: xss) := zipWith (::) xs (transpose xss);
288
+
289
+--- 𝒪(𝓃). Groups a ;List; given a predicate
290
+group {A} : (break : A -> A -> Bool) -> List A -> List (List A)
291
+ | _ nil := nil
292
+ | break (x :: xs) :=
293
+ let
294
+ go : List A -> List (List A) -> Pair A (List A) -> List (List A)
295
+ | nil acc _ := acc
296
+ | (x :: xs) acc (prev, prevs) :=
297
+ if
298
+ | break prev x := go xs acc (x, prev :: prevs)
299
+ | else := go xs ((prev :: prevs) :: acc) (x, nil);
300
+ in go xs nil (x, nil);
0 commit comments