rebellion icon indicating copy to clipboard operation
rebellion copied to clipboard

Grouping, but with a transducer instead of a reducer

Open jackfirth opened this issue 5 years ago • 1 comments

Half-baked idea: an entry? transducer constructor named partitioning that's like grouping, but instead of combining the values for each key using a reducer, it transduces the values for each key using another transducer. Example:

> (transduce (in-hash-entries (hash 'foo "hello" 'bar "world"))
             (partitioning (taking 3))
             #:into into-multidict)
(multidict
   'foo #\h
   'foo #\e
   'foo #\l
   'bar #\w
   'bar #\o
   'bar #\r)

Given a function to turn a reducer into a transducer that only performs the reduction once, grouping becomes a special case of partitioning.

jackfirth avatar Nov 05 '19 03:11 jackfirth

This seems kind of like #347 in disguise. It probably has the same issues related to transducers that insert stuff at the beginning and end of the stream.

jackfirth avatar Nov 13 '19 19:11 jackfirth