Fork me on GitHub
#clojure-dev
<
2024-08-06
oλv20:08:41

partition-all is documented to produce list partitions, but the transducer arity produces vector partitions. There’s already an issue about this from 2018: https://ask.clojure.org/index.php/3830/partition-docstring-should-mention-returns-vectors-transducer By now this it’s probably too late to change the behaviour, so I think it should be documented that the transducer arity produces vectors.

exitsandman20:08:35

IMO there is a case to be made that the issue here is that the transducer arity isn't documented well enough.

Alex Miller (Clojure team)20:08:46

this was an intentional choice (we carried it into the new partitionv-all)

til 1
Alex Miller (Clojure team)20:08:15

so not planning to change the behavior, but updating the doc makes sense

👍 1
exitsandman20:08:42

still, it is a bit of a strange behavior.

(->> xs (partition-all 2) (mapv #(conj % y)))
for instance doesn't convert well into transducers, requiring a seq to avoid the vector's conj behavior.
(into [] (comp (partition-all 2)
               (map #(conj (seq %) y)))
   xs)          

Alex Miller (Clojure team)20:08:29

so you want to put on the front?

Alex Miller (Clojure team)21:08:53

(into [] (comp (partition-all 2) (map #(cons y %))) xs)

exitsandman21:08:54

yes I know -in fact, I'd probably cons from the beginning given that it communicates I'm working with a seq abstracton - just digging for a case where this makes a difference

Alex Miller (Clojure team)21:08:20

given that this was added 9 years ago and I'm not aware of anyone else filing an issue about it, I don't think it's too common