1 つの整数だけでなく、整数の seq に基づいて seq を分割するより慣用的な方法は何でしょうか?
これが私の実装です:
(defn partition-by-seq
"Return a lazy sequence of lists with a variable number of items each
determined by the n in ncoll. Extra values in coll are dropped."
[ncoll coll]
(let [partition-coll (mapcat #(repeat % %) ncoll)]
(->> coll
(map vector partition-coll)
(partition-by first)
(map (partial map last)))))
次に(partition-by-seq [2 3 6] (range))
、 が得られ((0 1) (2 3 4) (5 6 7 8 9 10))
ます。