Operator - Transforn one Observable to another.
Map
1. Basic Calculation
-----------------------------------------------------------
import io.reactivex.Observable;
public class HomeClass {
public static void main(String[] args){
fakeUserInputWithMap().subscribe(System.out::println);
}
public static Observable<Integer> fakeUserInputWithMap(){
return Observable.just(1, 2, 3, 4).
map(x -> x*10);
}
}
2. Random Number
----------------------------------------------------------
import io.reactivex.Observable;
import java.util.Random;
public class HomeClass {
public static void main(String[] args){
fakeUserInputWithMapRandom().subscribe(System.out::println);
}
public static Observable<Integer> fakeUserInputWithMapRandom(){
Random random = new Random();
return Observable.just(1, 2, 3, 4).
map(x -> random.nextInt(20));
}
}
No comments:
Post a Comment