/// Split a list into chunks using the specified separator /// This takes a list and returns a list of lists (chunks) /// that represent individual groups, separated by the given /// separator 'v' let splitBy v list = let yieldRevNonEmpty list = if list = [] then [] else [List.rev list] let rec loop groupSoFar list = seq { match list with | [] -> yield! yieldRevNonEmpty groupSoFar | head::tail when head = v -> yield! yieldRevNonEmpty groupSoFar yield! loop [] tail | head::tail -> yield! loop (head::groupSoFar) tail } loop [] list |> List.ofSeq // The following uses 0 as a separator let nums = [0;1;2;0;1;3;0;4;5;0] splitBy 0 nums