Study Programming/RxJava

RxJava_5.6. Observable.from() vs Observable.just()

네모메모 2020. 5. 24. 12:47
반응형

 

 

Observable 생성 팩토리 메소드 중 닮은 듯 다른 from(), just() 비교


1. Observable.just()

- 최대 10개까지의 아이템을 전달받고 변형과 꺼냄 없이 아이템을 있는 그대로 모두 모아 배열같이 하나로 만들어 1번만 emit한다.

- Observable.just(null); 인 경우, null을 배열 아이템으로 가지는 아이템을 1번 emit한다, ※ 이는 empty Observable이 아님!!

- Ex) Observable.just(new Integer[]{1, 2, 3}) makes one emission with Observer callback as onNext(Integer[] integers) 

- just() 함수 정의를 보면, just() 함수에서 아이템들을 모아 fromArray()를 호출함

 


2. Observable.from~()

 

- 다양한 아이템을 내포할 수 있는 데이터 형태를 전달받고 그 아이템을 하나씩 꺼내 총 N번 emit 한다.
  '다양한 아이템을 내포할 수 있는 데이터 형태' 란?
       : Iterable, Array, Futures(항상 싱글 아이템  emit) 등과 같이 emit할 아이템을 꺼낼 수 있는 형태

- Ex) Observable.fromArray(new Integer[]{1, 2, 3}) makes three emission with Observer callback as onNext(Integer integer)

- RxJava 2.x에는 다양한 from() 함수가 존재 : fromArray(), fromCallable(), fromFuture(), fromIterable(), fromPublisher()

 

 

 

 

 

 

 

END!


스터디 도움 참조 블로그 (References)

- [도서] RxJava 시작하기, 원제 Learning Rxjava, 저자 토마스 닐드| 역자 조승진 |에이콘출판 |2019.07.24

http://book.naver.com/bookdb/book_detail.nhn?bid=12801360

 
- RecativeX just()

http://reactivex.io/documentation/ko/operators/just.html


- RecativeX from()
http://reactivex.io/documentation/ko/operators/from.html


- just() vs from()
https://stackoverflow.com/questions/30819349/rxjava-just-vs-from

 

 

 

반응형