F# doesn't come easy to me. The following piece of code is supposed to chunk a list. I have no idea what the problem is. Please help.
let chunk items chunkSize =
let folder = fun state x ->
match state with (reversedResult, reversedChunk) ->
if reversedChunk.Length < chunkSize then
(reversedResult, x::reversedChunk)
else
((reversedChunk |> List.rev)::reversedResult, [x])
let alsmostDone = items |> List.fold folder ([], [])
match alsmostDone with
| (reversedResult, []) -> reversedResult |> List.rev
| (reversedResult, lastReversedChunk) -> (lastReversedChunk |> List.rev)::reversedResult |> List.rev