lambda fairy

Splitting a list into chunks with unfoldr

I’m quite fond of the unfoldr function in Haskell. It doesn’t seem well known, which is a shame because I’ve often found it useful.

One of these uses is in splitting a list into chunks of a specified length. Here are some examples of what I’m going for:

And here’s the definition:

(Posted on .)