Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Rosetta code: Split an array into chunks

by stefan k (Curate)
on Sep 27, 2010 at 08:42 UTC ( #862165=note: print w/replies, xml ) Need Help??


in reply to Rosetta code: Split an array into chunks

Clojure?
(defn pm-chunk [data chsize] (apply str (interleave (map #(apply str (interpose " " %)) (partition chsize chsize nil data)) (repeat \newline))))
Then use it at the REPL:
user=> (print (pm-chunk ["a" "bb" "c" "d" "e" "f" "g" "h"] 3)) a bb c d e f g h
Please note that the rather ugly "apply str" at the top is necessary to fulfil the perlish requirements. Usually you'd stop at creating the right sequence, which is achieved after the call to interleave.

Regards... stefan k
you begin bashing the string with a +42 regexp of confusion

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://862165]
help
Chatterbox?
LanX was googling for Kirchenhügel ... till he realized someone is translating Church-Hill to German... (slapping forhead)
[erix]: ha :) (confusion)++
[erix]: just trying to keep you alert ;)
[erix]: just FYI, that link also mentioned the interesting word Hellweg
[erix]: but that's probably a known word to you guys

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2017-12-12 16:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (335 votes). Check out past polls.

    Notices?