Welcome! Please see the About page for a little more info on how this works.

+3 votes
in Transducers by

The docs for partition-all(link: 1) mention that when a coll is not provided, it returns a transducer. This is true for the form (partition-all n), but not true for (partition-all n step). There's no clear way that I can see to combine transducers from core to produce this sort of "sliding window" transducer, i.e.

user=> (into (link: ) (partition-all 2 1) (link: 1 2 3 4 5))
((1 2) (2 3) (3 4) (4 5) (5))

Of course, there's an arity collision between the above hypothesized (partition-all n step) and the concrete, non-transducer-producing (partition-all n coll), which could be resolved by switching on the type of the second argument, or less hackily by providing the functionality in a separate function, e.g. (sliding window-size step-size), or perhaps by some other means.

I implemented this function with reference to the existing (partition-all n) transducer here: https://gist.github.com/nornagon/03b85fbc22b3613087f6

Would it make sense to work on getting something like this into core?

(link: 1): http://clojuredocs.org/clojure.core/partition-all

1 Answer

0 votes
Reference: https://clojure.atlassian.net/browse/CLJ-1858 (reported by alex+import)