fosskers / cl-transducers

Transducers: Ergonomic, efficient data processing
https://fosskers.github.io/cl-transducers/
GNU Lesser General Public License v3.0
100 stars 4 forks source link

Generic `concatenate` and `flatten` #5

Open fosskers opened 5 months ago

fosskers commented 5 months ago

This PR enables concatenate and flatten to accept streams of things that aren't just lists. For now I've expanded this to include vectors, which implicitly supports strings as well.

(transduce #'concatenate
           #'cons (list (cl:vector 1 2 3) (cl:list 4 5 6) (cl:vector 7 8 9)))

yields

(1 2 3 4 5 6 7 8 9)
simendsjo commented 4 months ago

Solves my issue, but looks like a game of Whac-A-Mole. It should preferably work on all kinds of inputs, not hardcoded to just list and vector. But it's an improvement :+1: Could a generic method be created for determining if which reducer should be used?

fosskers commented 4 months ago

Could a generic method be created for determining if which reducer should be used?

I'll look into this. It occurs to me that many (all?) of the foo-transduce functions may initialise themselves the same way, and then call their inner reducers.

fosskers commented 4 months ago

Let's revisit this after I'm back. Thanks for your patience.