+
+let (group_by_post: ('a -> bool) -> 'a list -> ('a list * 'a) list * 'a list)=
+ fun f xs ->
+ let rec aux_filter grouped_acc acc = function
+ | [] ->
+ List.rev grouped_acc, List.rev acc
+ | x::xs ->
+ if f x
+ then
+ aux_filter ((List.rev acc,x)::grouped_acc) [] xs
+ else
+ aux_filter grouped_acc (x::acc) xs
+ in
+ aux_filter [] [] xs
+
+let _ = example
+ (group_by_post (fun x -> x = 3) [1;1;3;2;3;4;5;3;6;6;6] =
+ ([([1;1],3);([2],3);[4;5],3], [6;6;6]))
+