Home > Blockchain >  How to get data from Flowable to another Flowable?
How to get data from Flowable to another Flowable?

Time:12-16

I have 2 Flowables (one which is giving me VelocityNed items, and other which I written to consume items from first one); the thing is I don't know how to make the second one right, since I still not feel sure with RxJava

my Flowable code:

private Flowable<Float> getIAS(Flowable<VelocityNed> velocityNed) {
        Flowable<Float> flowable = Flowable.create(emitter->{
            velocityNed.subscribeWith(new DisposableSubscriber<VelocityNed>() {
                @Override public void onNext(VelocityNed v) {
                    float valueToEmit = (float)Math.sqrt(Math.pow(v.getDownMS(),2) Math.pow(v.getEastMS(),2) Math.pow(v.getNorthMS(),2));
                    //how to emit this
                }
                @Override public void one rror(Throwable t) {
                    t.printStackTrace();
                }
                @Override public void onComplete() {
                    emitter.onComplete();
                    this.dispose();
                }         
            });
        }, BackpressureStrategy.BUFFER);
        return flowable;
    }

CodePudding user response:

You don't need to create a Flowable manually just to transform the emissions. You can do originalFlowable.map(element -> { transform element however you want }).

In your case it would be something like:

Flowable<Float> flowable = velocityNed.map(v -> {
    (float)Math.sqrt(Math.pow(v.getDownMS(),2) Math.pow(v.getEastMS(),2) Math.pow(v.getNorthMS(),2));           
})
  • Related