Uploaded image for project: 'Clojure'
  1. CLJ-1858

Transducer for partition-all with step

    Details

    • Type: New Feature
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects versions: Release 1.7
    • Fix versions: None
    • Labels:
    • Patch:
      Code

      Description

      The docs for partition-all[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 [] (partition-all 2 1) [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?

      [1]: http://clojuredocs.org/clojure.core/partition-all

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              alex+import import
            • Votes:
              1 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated: