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