clojure-dev

oλv 2024-08-06T20:34:41.681659Z

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.

exitsandman 2024-08-06T20:37:35.659999Z

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) 2024-08-06T20:37:46.724609Z

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

1
Alex Miller (Clojure team) 2024-08-06T20:38:15.643389Z

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

👍 1
exitsandman 2024-08-06T20:46:42.932279Z

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) 2024-08-06T20:59:29.271519Z

so you want to put on the front?

Alex Miller (Clojure team) 2024-08-06T21:02:09.064979Z

use cons?

Alex Miller (Clojure team) 2024-08-06T21:02:53.599009Z

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

exitsandman 2024-08-06T21:08:54.797289Z

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) 2024-08-06T21:16:20.472029Z

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