
example(of: "Start with") {
let numbers = Observable.of(2,3,4)
let observable = numbers.startWith(100)
observable.subscribe{
print($0)
}.disposed(by: disposeBag)
}
--- Example of:Start with---
next(100)
next(2)
next(3)
next(4)
completed
2가지 옵저버블의 시퀀스를 합쳐줌

example(of: "Observerble.concet") {
let first = Observable.of(1,2,3,4)
let second = Observable.from([5,6,7])
Observable.concat([first,second]).subscribe{
print($0)
}.disposed(by: disposeBag)
}
--- Example of:Observerble.concet---
next(1)
next(2)
next(3)
next(4)
next(5)
next(6)
next(7)
completed
두 개의 Observalble Sequence를 하나의 Observable Sequence로 합침

example(of: "merge") {
let left = PublishSubject<String>()
let right = PublishSubject<String>()
let source = Observable.of(left.asObserver(), right.asObserver())
source.merge().subscribe{
print($0)
}
var lValue = ["A","B","C"]
var rValue = ["C","D","E"]
repeat{
switch Bool.random() {
case true where !lValue.isEmpty:
left.onNext("Left: " + lValue.removeFirst())
case false where !rValue.isEmpty:
right.onNext("RIGHT: " + rValue.removeFirst())
default:
break
}
}while !lValue.isEmpty || !rValue.isEmpty
left.onCompleted()
right.onCompleted()
}
--- Example of:merge---
next(RIGHT: C)
next(Left: A)
next(RIGHT: D)
next(Left: B)
next(Left: C)
next(RIGHT: E)
completed
하나의 이벤트만 저장 가능했던 Observable sequence를 여러개의 이벤트를 저장하게끔함.
left를 기준으로 right가 나중에 나오면 모든 left에서의 최신 값과 매칭

right의 이벤트가 emit될때 left의 최신 이벤트와 매칭해서 1개의 시퀀스를 생성해줌
example(of: "combineLatest") {
let left = PublishSubject<String>()
let right = PublishSubject<String>()
let observalbe = Observable.combineLatest(left, right) { leftElement, rightElement in
"\\(leftElement) \\(rightElement)"
}
let disposable = observalbe.subscribe(onNext : {value in print(value)})
print(">Sending a value to Left")
left.onNext("hello,")
print(">Sending a value to Left")
left.onNext("hello???,")
print(">Sending a value to right")
right.onNext("world")
print(">Sending another value to. right")
right.onNext("RxSwift")
print(">Sending another value to Left")
left.onNext("Have a good day,")
left.onCompleted()
right.onCompleted()
}
--- Example of:combineLatest---
>Sending a value to Left
>Sending a value to Left
>Sending a value to right
hello???, world
>Sending another value to. right
hello???, RxSwift
>Sending another value to Left
Have a good day, RxSwift

더적은 쪽의 이벤트의 개수에 맞게 짝지어서 연결해 줌
example(of: "ZIP") {
enum Weather{
case cloudy
case rainny
case sunny
}
let left : Observable<Weather> = Observable.of(.sunny,.cloudy,.rainny,.rainny,.cloudy,.cloudy)
let right = Observable.of("KOR","USA","CNA","JPN","TPA")
let observalbe = Observable.zip(left, right) { weather, country in
return "It's \\(weather) in \\(country)"
}
observalbe.subscribe(onNext:{
print($0)
})
}
--- Example of:ZIP---
It's sunny in KOR
It's cloudy in USA
It's rainny in CNA
It's rainny in JPN
It's cloudy in TPA