3 ms·
I'm glad Clojure has top-level support for this operation... it's quite flexible too, and the presence of partition-all makes it explicit what you should expect
by Jach 13y ago
I'm glad Clojure has top-level support for this operation... it's quite flexible too, and the presence of partition-all makes it explicit what you should expect if the sequence doesn't evenly partition.
user=> (partition 3 [1 2 3 4 5 6])
((1 2 3) (4 5 6))
user=> (partition 3 [1 2 3 4 5 6 7])
((1 2 3) (4 5 6))
user=> (partition-all 3 [1 2 3 4 5 6 7])
((1 2 3) (4 5 6) (7))
user=> (partition 3 3 (repeat 0) [1 2 3 4 5 6 7])
((1 2 3) (4 5 6) (7 0 0))
- iamgopal 13y agocan you measure the speed and post it here ?
- anaphor 13y agoHaskell also has it in the Data.List.Split library, which is handy, although it's easy to define yourself. λ> chunksOf 3 [1..12] [[1,2,3],[4,5,6],[7,8,9],[10,11,12]]
- phpnode 13y agoFAO: iamgopal - your account has been dead for over a year for no discernible reason, only people with showdead on can see your posts.