3 ms·
Yes, although transducers are more general than iterators. Iterators model lazy series from which you must 'pull' elements. Transducers can also be used with e
by rob_smallshire 11y ago
Yes, although transducers are more general than iterators. Iterators model lazy series from which you must 'pull' elements. Transducers can also be used with elements that are 'pushed', such as events coming from channels, or whatever. Essentially they decouple the transformation from the mechanisms by which input elements arrive and result elements are received, whilst still allowing separate transformations to be composed into more complex composite transformations.
- sametmax 11y agoThat's what I was saying : this is from somebody not knowing Python. Generators have a "send()" method to push data in it. We have yield from to delegate to sub coroutines. And generators can be classes for more advanced behaviors. All this lib does is to make something that already exists in the language, in a heavier and slower way.
- danidiaz 11y ago> Generators have a "send()" method to push data in it. What would be the pythonic way of "mapping over" the inputs that are sent into a generator, or performing grouping operations on those inputs? For example, how to transform a generator that expects to be sent sets of strings into a generator that simply accepts a flat stream of strings?
- rob_smallshire 11y agoYou could use the python-transducer library <https://github.com/sixty-north/python-transducers> https://github.com/sixty-north/python-transducers> I mentioned in my other comments to do this. It supports using the same transducers with iterables and push-event coroutine generators.
- sametmax 11y agoYou don't, you chain small generators. Compositions of generators transforming data is the key.