Git Product home page Git Product logo

Comments (6)

dbrattli avatar dbrattli commented on August 24, 2024

To split a stream in to multiple streams:

from aioreactive.producer import Producer
import aioreactive.producer.operators as ops

xs = Producer.from_iterable(range(10))
odds = xs | ops.filter(lambda x % 2 == 1)
evens = xs | ops.filter(lambda x: x % 2 == 0)
...

Perfectly ok to ask questions in issues.

from aioreactive.

Arttii avatar Arttii commented on August 24, 2024

from aioreactive.

dbrattli avatar dbrattli commented on August 24, 2024

Have a look at this example.

from aioreactive.

Arttii avatar Arttii commented on August 24, 2024

Ha cool, that's exactly what I ended up doing. But a side question, If I have a Producer that comes from an iterator, which is essentially reading an async response. If I fork like this, it seems that each instance of the stream with execute the request and get subsequent values from that. I guess this is the expected behavior right?

from aioreactive.

dbrattli avatar dbrattli commented on August 24, 2024

Yes, that is expected behavior. This is what's called "cold" observables in the Rx world. You can turn them "hot" by publishing. Not a 'publish()' operator in aioreactive yet, but you can simulate it by using an AsyncStream as your sink. Thus you split from the AsyncStream, then you start the from_iterable() using your stream instead of the sink (a stream is also a sink).

Something like:

xs = Producer.from_iterable()

ys = AsyncStream()
odds = ys | ops.filter(lambda x: x % 2 == 1)
evens = ys | ops.filter(lambda x: x % 2 == 0)

await start(odds, FuncSink(mysink))
await start(evens, FuncSink(mysink))
await start(xs, ys)

from aioreactive.

Arttii avatar Arttii commented on August 24, 2024

Ha, cool. I guess an operator like that would have to mimic what the AsyncStreamFactory does for the start? Create the intermediate stream and connect them up together?

from aioreactive.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.