fork download
  1. let splitAt n list =
  2. let splitter ((xs, ys), n') c =
  3. if n' < n then
  4. ((c :: xs, ys), n' + 1)
  5. else
  6. ((xs, c :: ys), n' + 1)
  7. List.fold splitter (([], []), 0) list
  8. |> fst
  9. |> (fun (xs, ys) -> (List.rev xs, List.rev ys))
  10.  
  11. printfn "%A" (splitAt 3 [2; 90; 1; 22])
Success #stdin #stdout 0.21s 12680KB
stdin
Standard input is empty
stdout
([2; 90; 1], [22])