Skip to content

Instantly share code, notes, and snippets.

@natdempk
Created June 27, 2017 01:49
Show Gist options
  • Save natdempk/0d226f1e15bee697c231d0ee0d9d3484 to your computer and use it in GitHub Desktop.
Save natdempk/0d226f1e15bee697c231d0ee0d9d3484 to your computer and use it in GitHub Desktop.
import com.google.common.collect.ImmutableList;
import io.reactivex.Observable;
import io.reactivex.schedulers.Schedulers;
import java.util.concurrent.ExecutionException;
import java.util.stream.Stream;
public class TestMain {
public static void main(String[] args) throws ExecutionException, InterruptedException {
Stream<Integer> ints = ImmutableList.of(1, 2, 3, 4, 5, 6)
.stream().map(i -> {
System.out.println("emitting:" + i);
return i;
});
Long count = Observable.fromIterable(() -> ints.iterator())
.observeOn(Schedulers.computation())
.map(x -> x + 1)
.observeOn(Schedulers.io())
.doOnNext(System.out::println)
.observeOn(Schedulers.computation())
.count()
.blockingGet();
System.out.println("count: " + count);
}
}
emitting:1
emitting:2
emitting:3
emitting:4
2
emitting:5
emitting:6
3
4
5
6
7
count: 6
Process finished with exit code 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment