This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FutureTask<Integer> f = new FutureTask<Integer>(() -> { | |
| Thread.sleep(2000); | |
| return 21; | |
| }); | |
| new Thread(f).start(); | |
| Observable<Integer> values = Observable.from(f); | |
| Subscription subscription = values.subscribe( | |
| v -> System.out.println("Received: " + v), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Integer[] is = {1,2,3}; | |
| Observable<Integer> values = Observable.from(is); | |
| Subscription subscription = values.subscribe( | |
| v -> System.out.println("Received: " + v), | |
| e -> System.out.println("Error: " + e), | |
| () -> System.out.println("Completed") | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Observable<Integer> values = Observable.range(0,10); | |
| Subscription oddNumbers = values | |
| .filter(v -> v % 2 == 0) | |
| .subscribe( | |
| v -> System.out.println(v), | |
| e -> System.out.println("Error: " + e), | |
| () -> System.out.println("Completed") | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Observable<Integer> values = Observable.create(o -> { | |
| o.onNext(1); | |
| o.onNext(1); | |
| o.onNext(2); | |
| o.onNext(3); | |
| o.onNext(2); | |
| o.onCompleted(); | |
| }); | |
| Subscription subscription = values |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Observable<Integer> values = Observable.range(0, 5); | |
| Subscription first2 = values | |
| .take(2) | |
| .subscribe( | |
| v -> System.out.println(v), | |
| e -> System.out.println("Error: " + e), | |
| () -> System.out.println("Completed") | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Observable<Long> values = Observable.interval(100, TimeUnit.MILLISECONDS); | |
| Subscription subscription = values | |
| .takeWhile(v -> v < 2) | |
| .subscribe( | |
| v -> System.out.println(v), | |
| e -> System.out.println("Error: " + e), | |
| () -> System.out.println("Completed") | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Observable<Integer> values = Observable.range(0, 2); | |
| Subscription subscription = values | |
| .exists(i -> i > 2) | |
| .subscribe( | |
| v -> System.out.println(v), | |
| e -> System.out.println("Error: " + e), | |
| () -> System.out.println("Completed") | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class PrintSubscriber extends Subscriber{ | |
| private final String name; | |
| public PrintSubscriber(String name) { | |
| this.name = name; | |
| } | |
| @Override | |
| public void onCompleted() { | |
| System.out.println(name + ": Completed"); | |
| } | |
| @Override |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Observable<Integer> values = Observable.range(0, 3); | |
| values | |
| .subscribe(new PrintSubscriber("Values")); | |
| values | |
| .count() | |
| .subscribe(new PrintSubscriber("Count")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Observable<String> values = Observable.just( | |
| "first", | |
| "second", | |
| "third", | |
| "forth", | |
| "fifth", | |
| "sixth" | |
| ); | |
| values.groupBy(word -> word.charAt(0)) |
OlderNewer