[Haskell-beginners] Haskell equivalent to Clojure's partition fn

Karl Voelker karl at karlv.net
Sat Jul 25 17:42:48 UTC 2015


On Sat, Jul 25, 2015, at 10:30 AM, Timothy Washington wrote:
> Is there a Haskell equivalent to Clojure's partition[1] function? I'm
> particularly interested in the stepwise feature, where we can select a
> certain `n` size of the list, then step `m` and take again.

This is a great use case for a type-based search engine. Luckily, we
have some of those!

Here is a search that matches your question, I think:

http://hayoo.fh-wedel.de/?query=Int+-%3E+Int+-%3E+%5Ba%5D+-%3E+%5B%5Ba%5D%5D

At this moment, there is one result, which appears to be exactly the
thing you want. Unfortunately, it's an auxiliary function of a music
theory package, which you may not want to install for that one function.

There's a package called "split" that contains a bunch of useful tools
for splitting lists. It doesn't  have exactly what you want, but it does
have a function called "chop" that will get you most of the way there:

http://hackage.haskell.org/package/split-0.2.2/docs/Data-List-Split.html#v:chop

-Karl


Links:

  1. http://clojuredocs.org/clojure.core/partition
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150725/95db832e/attachment.html>


More information about the Beginners mailing list