pescadores/pescador

Mux Feature - Accept iterables (instead of just Streamers), and wrap them in Streamers automatically

Closed this issue · 2 comments

There are many places in the Mux tests where this happens:

>>> a = pescador.Streamer('a')
>>> b = pescador.Streamer('b')
>>> c = pescador.Streamer('c')

>>> mux = pescador.RoundRobinMux([a, b, c])
>>> "".join(list(mux.iterate()))
abc

I believe this could be easily simplified by allowing all Mux to accept iterables, and just automatically wrapping them in a pescador.Streamer, and documenting that this is what will happen if you use it this way. A convenience method, of sorts. That would make the above code possibly:

>>> mux = pescador.RoundRobinMux(['a', 'b', 'c'])
>>> "".join(list(mux.iterate()))
abc

(a trivial example, but I think it gets the point across)

(Discussed briefly in #103)

👍 from me on this. @ejhumphrey ?

This seems like a one-liner change in the base class __init__ method:

self.streamers = streamers

becomes

self.streamers = [s if isinstance(s, Streamer) else Streamer(s) for s in streamers]

This feels consistent with the Streamer base-class behavior of handling iterables and generators in _activate().