Java Code Examples for io.reactivex.Observable.range()

The following are Jave code examples for showing how to use range() of the io.reactivex.Observable class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: reactive-demo   File: reactive1.java   Source Code and License Vote up 6 votes
@Test
public void test2() {
    List<String> words = Arrays.asList(
            "the",
            "quick",
            "brown",
            "fox",
            "jumps",
            "over",
            "the",
            "lazy",
            "dog"
    );

    Observable<Integer> range = Observable.range(1, Integer.MAX_VALUE);
    Observable.fromIterable(words)
            .flatMap(word -> Observable.fromArray(word.split("")))
            .sorted()
            .distinct()
            .zipWith(range, (word, line) -> line + ":" + word)
            .subscribe(System.out::println);
}
 
Example 2
Project: reactive-demo   File: reactive.java   Source Code and License Vote up 6 votes
@Test
    public void testReactive() {
        Observable.just("Hello", "World")
                .subscribe(System.out::println);
        List<String> words = Arrays.asList(
                "the",
                "quick",
                "brown",
                "fox",
                "jumps",
                "over",
                "the",
                "lazy",
                "dog"
        );

        Observable<String> wordsObs = Observable.fromIterable(words);
        wordsObs.subscribe(System.out::println);

        Observable<Integer> range = Observable.range(1, Integer.MAX_VALUE);
//        range.subscribe(System.out::println);

        wordsObs.zipWith(range, (word, row) -> String.format("%2d. %s", row, word))
                .subscribe(System.out::println);

        wordsObs.flatMap(word -> Observable.fromArray(word.split("")))
                .sorted()
                .distinct()
                .zipWith(range, (word, row) -> String.format("%2d. %s", row, word))
                .subscribe(System.out::println);
    }
 
Example 3
Project: reactive-demo   File: reactive.java   Source Code and License Vote up 6 votes
@Test
public void test2() {
    List<String> words = Arrays.asList(
            "the",
            "quick",
            "brown",
            "fox",
            "jumps",
            "over",
            "the",
            "lazy",
            "dog"
    );

    Observable<Integer> range = Observable.range(1, Integer.MAX_VALUE);
    Observable.fromIterable(words)
            .flatMap(word -> Observable.fromArray(word.split("")))
            .sorted()
            .distinct()
            .zipWith(range, (word, row) -> String.format("%2d. %s", row, word))
            .subscribe(System.out::println);


}
 
Example 4
Project: reactive-demo   File: reactive.java   Source Code and License Vote up 6 votes
@Test
public void test8() {
    List<String> words = Arrays.asList(
            "the",
            "quick",
            "brown",
            "fox",
            "jumps",
            "over",
            "the",
            "lazy",
            "dog"
    );
    Observable<String> wordsObs = Observable.fromIterable(words)
            .flatMap(word -> Observable.fromArray(word.split("")));
    wordsObs.subscribe(System.out::println);

    Observable<Integer> range = Observable.range(1, Integer.MAX_VALUE);

    wordsObs
            .distinct()
            .sorted()
            .zipWith(range, (word, row) -> row + ":" + word)

            .subscribe(System.out::println);
}
 
Example 5
Project: reactive-demo   File: reactive.java   Source Code and License Vote up 6 votes
@Test
public void test12() {
    List<String> words = Arrays.asList(
            "the",
            "quick",
            "brown",
            "fox",
            "jumps",
            "over",
            "the",
            "lazy",
            "dog"
    );
    Observable<Integer> range = Observable.range(1, Integer.MAX_VALUE);
    Observable.fromIterable(words)
            .flatMap(word -> Observable.fromArray(word.split("")))
            .sorted()
            .distinct()
            .zipWith(range, (word, row)->row + ":" + word)
            .subscribe(System.out::println);
}
 
Example 6
Project: Learning-RxJava   File: Ch4_13.java   Source Code and License Vote up 5 votes
public static void main(String[] args) {
    Observable<String> source1 =
            Observable.just("Alpha", "Beta", "Gamma", "Delta",
                    "Epsilon");
    Observable<Integer> source2 = Observable.range(1, 6);
    Observable.zip(source1, source2, (s, i) -> s + "-" + i)
            .subscribe(System.out::println);
}
 
Example 7
Project: Learning-RxJava   File: Ch8_10.java   Source Code and License Vote up 5 votes
public static void main(String[] args) {
    Observable<Integer> source = Observable.range(1, 1000);
    source.toFlowable(BackpressureStrategy.BUFFER)
            .observeOn(Schedulers.io())
            .subscribe(System.out::println);
    sleep(10000);
}
 
Example 8
Project: Learning-RxJava   File: Ch2_24.java   Source Code and License Vote up 5 votes
public static void main(String[] args) {
        Observable<Integer> source = Observable.range(start, count);
        source.subscribe(i -> System.out.println("Observer 1: " + i));
//modify count
        count = 10;
        source.subscribe(i -> System.out.println("Observer 2: " + i));
    }
 
Example 9
Project: code-examples-android-expert   File: lessonC_BooleanLogicAndErrorHandling.java   Source Code and License Vote up 5 votes
/**
 * OK, it's time for a challenge! Given the range below and what we've
 * learned of rxjava so far, how can we produce an mSum equal to 19?? Hint:
 * Use a Predicate to filter all values small then 9 and use the reduce operator to combine the emitted values
 */
@Test
public void filterAndReduceShouldResultIn19() {
	Observable<Integer> range = Observable.range(1, 10);
	// TODO use range and reduce on range and subscribe testObservable to it
	assertThat(testObservable.values().get(0)).isEqualTo(19);
}
 
Example 10
Project: Reactive-Programming-With-Java-9   File: Demo_take_no_threading.java   Source Code and License Vote up 5 votes
public static void main(String[] args) {
	// TODO Auto-generated method stub
	Observable<Integer> observable = Observable.range(1, 50);

	observable.take(5).subscribe(new Observer<Integer>() {

		@Override
		public void onComplete() {
			// TODO Auto-generated method stub
			System.out.println(Thread.currentThread().getName() + " finished reading of items");

		}

		@Override
		public void onError(Throwable throwable) {
			// TODO Auto-generated method stub
			System.out.println(Thread.currentThread().getName() + " finished with exception");

		}

		@Override
		public void onNext(Integer value) {
			// TODO Auto-generated method stub
			System.out.println(Thread.currentThread().getName() + " read item:-"+value);

		}

		@Override
		public void onSubscribe(Disposable arg0) {
			// TODO Auto-generated method stub

		}
	});

}
 
Example 11
Project: Reactive-Programming-With-Java-9   File: Demo_zip.java   Source Code and License Vote up 5 votes
public static void main(String[] args) {
	// TODO Auto-generated method stub
	Integer[] numbers = { 1, 2, 13, 34, 12, 10 };
	String[] fruits = { "mango", "pineapple", "apple", "mango", "papaya" };

	Observable<Integer> source1 = Observable.fromArray(numbers);
	Observable<String> source2 = Observable.fromArray(fruits);
	Observable<Integer> source3 = Observable.range(30, 3);
	Observable.zip(source1, source2, source3, (value1, value2, value3) -> {

		return value1 + ":" + value2 + "*" + value3;
	}).subscribe(new Observer<String>() {

		@Override
		public void onComplete() {
			// TODO Auto-generated method stub
			System.out.println("zipping completed successfully");

		}

		@Override
		public void onError(Throwable throwable) {
			// TODO Auto-generated method stub
			throwable.printStackTrace();

		}

		@Override
		public void onNext(String value) {
			// TODO Auto-generated method stub
			System.out.println(value);
		}

		@Override
		public void onSubscribe(Disposable arg0) {
			// TODO Auto-generated method stub

		}
	});
}
 
Example 12
Project: Reactive-Programming-With-Java-9   File: Demo_concat.java   Source Code and License Vote up 5 votes
public static void main(String[] args) {
	// TODO Auto-generated method stub
	Observable source1=	Observable.range(1,5);
	Observable source2=Observable.just(10,20,30);
	Observable.concat(source1,source2).subscribe(new Consumer<Integer>() {

		@Override
		public void accept(Integer value) throws Exception {
			// TODO Auto-generated method stub
			System.out.println(value);
			
		}
	});

}
 
Example 13
Project: Reactive-Programming-With-Java-9   File: Demo_take.java   Source Code and License Vote up 5 votes
public static void main(String[] args) {
	// TODO Auto-generated method stub
	Observable<Integer> observable = Observable.range(10, 9);
	observable.take(3).count().subscribe(item -> System.out.println("emitted " + item + " items"));
	observable.take(3).subscribe(new Observer<Integer>() {

		@Override
		public void onComplete() {
			// TODO Auto-generated method stub
			System.out.println("collected  items successfully");

		}

		@Override
		public void onError(Throwable throwable) {
			// TODO Auto-generated method stub
			throwable.printStackTrace();
		}

		@Override
		public void onNext(Integer value) {
			// TODO Auto-generated method stub
			System.out.println("collected item: " + value);

		}

		@Override
		public void onSubscribe(Disposable disposable) {
			// TODO Auto-generated method stub

		}
	});
}
 
Example 14
Project: reactive-demo   File: reactive.java   Source Code and License Vote up 5 votes
@Test
    public void test() {
        Observable.just("Hello", "World")
                .subscribe(System.out::println);
        List<String> words = Arrays.asList(
                "the",
                "quick",
                "brown",
                "fox",
                "jumps",
                "over",
                "the",
                "lazy",
                "dog"
        );

        Observable.fromIterable(words)
                .subscribe(System.out::println);

        Observable<Integer> range = Observable.range(1, Integer.MAX_VALUE);
//        range.subscribe(System.out::println);

        Observable.fromIterable(words)
                .flatMap(word -> Observable.fromArray(word.split("")))
                .sorted()
                .distinct()
                .zipWith(range, (word, row) -> String.format("%2d. %s", row, word))
                .subscribe(System.out::println);
    }
 
Example 15
Project: Learning-RxJava   File: Ch5_1.java   Source Code and License Vote up 4 votes
public static void main(String[] args) {
    Observable<Integer> threeIntegers = Observable.range(1, 3);
    threeIntegers.subscribe(i -> System.out.println("Observer One: " + i));
    threeIntegers.subscribe(i -> System.out.println("Observer Two: " + i));
}
 
Example 16
Project: Reactive-Programming-With-Java-9   File: DemoRange.java   Source Code and License Vote up 4 votes
public static void main(String[] args) {
	// TODO Auto-generated method stub
	Observable<Integer> observable=Observable.range(10, 5);
	observable.subscribe(number->System.out.println(number));
}
 
Example 17
Project: Reactive-Programming-With-Java-9   File: DemoRange.java   Source Code and License Vote up 4 votes
public static void main(String[] args) {
	// TODO Auto-generated method stub
	Observable<Integer> observable=Observable.range(10, 5);
	observable.subscribe(number->System.out.println(number));
}
 
Example 18
Project: RxJava2-Android-Sample   File: RangeExampleActivity.java   Source Code and License Vote up 4 votes
private Observable<Integer> getObservable() {
    return Observable.range(0, 5);
}