E.g.:
(each-slice 3 [1 2 3 4 5])
; => [[1 2 3] [2 3 4] [3 4 5]]
It would not be hard to write it, but is there a built-in way to do it?
There's no way to do it in a single function call if you want the slices returned as vectors. In two calls, it's still impossible if you really want slices (as created by subvec
); otherwise you could use
(mapv vec (partition 3 1 [1 2 3 4 5]))
to get new regular vectors. Without the mapv vec
, you'd get a seq of seqs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With