Category Archives: RxJava

RxJava .reduce()

Observable.from(new Integer[]{1,2,3,4,5}) .reduce(new Func2<Integer, Integer, Integer>() { @Override public Integer call(Integer t1, Integer t2) { return t1+t2; } }).subscribe(new Action1<Integer>() { @Override public void call(Integer t) { // t = 15 } });

Also posted in Java | Leave a comment

Observable.zip()

public interface Api {   @GET("x") Observable<X> getX();   @GET("y") Observable<Y> getY();   } Observable.zip(api.getX(), api.getY(), new Func2<X, Y, Pair>() { @Override public Pair call(X x, Y y) { return new Pair(x, y); } }).subscribe(new Action1<Pair>() { @Override public void call(Pair pair) { // you got pair ;) } });

Also posted in Java, Retrofit | Leave a comment

RxJava – Observable.interval()

package rxjava;   import java.util.Random; import java.util.concurrent.TimeUnit;   import rx.Observable; import rx.Observer; import rx.functions.Func1; import rx.schedulers.Schedulers;   public class RxInterval {   private final Random random = new Random();   public RxInterval() {   Observable<Integer> observable = Observable .interval(5, TimeUnit.SECONDS) /** * startWith() * do Observable dodawany jest element startowy, który emitowy jest przed pierwszym [...]

Also posted in Java | Leave a comment