rx java - RxJava - Just vs From -
i'm getting same output when using observable.just vs observable.from in following case:
public void myfunc() { //swap out here , same results,why ? observable.just(1,2,3).subscribe(new subscriber<integer>() { @override public void oncompleted() { log.d("","all done. oncompleted called"); } @override public void onerror(throwable e) { } @override public void onnext(integer integer) { log.d("","here integer:"+integer.intvalue()); } }); }
i thought 'just' suppose emit single item , 'from' emit items in sort of list. whats difference ? noted 'just' , 'from' takes limited amount of arguments. observable.just(1,2,3,4,5,6,7,8,-1,-2) ok observable.just(1,2,3,4,5,6,7,8,-1,-2,-3) fails. same goes from, have wrap in list or array of sorts. i'm curious why cant define unlimited arguments.
update: experimented , saw 'just' not take array structure 'just' takes arguments. 'from' takes collection. following works 'from' not 'just':
public observable myfunc() { integer[] myints = {1,2,3,4,5,6,7,8,-1,-2,9,10,11,12,13,14,15}; return observable.just(myints).flatmap(new func1<integer, observable<boolean>>() { @override public observable<boolean> call(final integer integer) { return observable.create(new observable.onsubscribe<boolean>() { @override public void call(subscriber<? super boolean> subscriber) { if(integer.intvalue()>2){ subscriber.onnext(integer.intvalue()>2); } } }); } }); }
i assuming clear difference then, correct ?
the difference should clearer when @ behaviour of each when pass iterable
(for example list
):
observable.just(somelist)
give 1 emission - list
.
observable.from(somelist)
give n emissions - each item in list.
the ability pass multiple values just
convenience feature; following functionally same:
observable.just(1, 2, 3); observable.from(1, 2, 3);
Comments
Post a Comment