1. just

just one sequence 생성

import RxSwift

func example(of description: String, action: ()->Void){
    print("\\n--- Example of:\\(description)---")
    action()
}
example(of: "just"){
    let one = 1
    let two = 2
    let tree = 3
    
    _ = Observable<Int>.just(one).subscribe{
        let sub = $0
        print(sub)
    }
    
    Observable<[Int]>.just([one,tree,two]).subscribe{
        let sub = $0
        print($0)
    }
}
/* 출력
--- Example of:just---
next(1)
completed
next([1, 3, 2])
completed*/

2. OF

여러개의 이벤트를 방출 → 타입추론 하지만 타입은 1개로 통일해야 오류가 안남

example(of: "of") {
    let one = 1
    let two = 2
    let tree = 3
    
    Observable.of(one,two,tree).subscribe{
        print($0)
    }
    Observable.of([one,two,tree]).subscribe{
        print($0)
    }
    
    //타입을 맞추지 않으면 애러가 발생
    Observable.of(one,"two",tree).subscribe{
        print($0)
    }
}

/*
출력
--- Example of:of---
next(1)
next(2)
next(3)
completed
next([1, 2, 3])
completed
*/

3. from

어레이만 들어올 수 있으며 어레이에 요소를 하나씩 방출해줌

example(of: "from") {
    Observable.from([1,2,4,5,3]).subscribe{
        print($0)
    }
    Observable.from([1,"2","3"]).subscribe{
        print($0)
    }
}
/*
출력
--- Example of:from---
next(1)
next(2)
next(4)
next(5)
next(3)
completed
next(1)
next(2)
next(3)
completed
*/

배열안에 타입이 달라도 코드가 죽지는 않는다.

4. Create

클로저 형식으로 다양한 값을 생성 할 수 있다고 한다. onNext, onCompleted, onError …

DisposeBag은 쓰레기통이라고함 메모리 누수 방지 차원에서 있는다고 하는데

아직 자세히 모르겠음

example(of: "CREATE") {
    let disposeBag = DisposeBag()
    
    let observable = Observable<String>.create { (observer)-> Disposable in
        observer.onNext("1")
        observer.onCompleted()
        observer.onNext("?")
        
        return Disposables.create()
    }
    observable.subscribe{print($0)}.disposed(by: disposeBag)
    
}
/*
--- Example of:CREATE---
next(1)
completed
*/