Apple์์ ๊ณต๊ฐํ API์ธ Combine. ์ด์ Rx์์ Combine์ผ๋ก ๋ง์ด ๋์ด๊ฐ๋ค๊ณ ํ๋ค. ๋ฌด์์ ํ๋ ๊ฒ์ธ์ง, ์ ์ข์์ง, ๋ฐ๋ก ์จ๋จน๊ธฐ ์ํ ํ์ ๋ฌด์์ด ์๋์ง ์์๋ณธ๋ค.
์์
- Rx์ ์ฌ์ ์ ์๋ฏธ
- Reactive (Observer pattern)
- Functional
- ๊ฐ์ ๋ค๋ฃจ๋ ๋ฐฉ์
- ๊ธฐ์กด
- ์๊ฐ์ด ์ง๋จ์ ๋ฐ๋ผ ๋ณ์ ๊ฐ์ด ๋ณํ๋ค.
- a = 3 โ a = 4
- Rx
- ๊ฐ๋ค์ sequence(stream)
- ์ผ์ข ์ array๋ฅผ ๋ค๋ฃจ๋ ์ฌ๊ณ ๋ฐฉ์
- ๊ธฐ์กด
- ๊ธฐ๋ณธ ํ๋ฆ
- Publisher
- ๊ฐ์ ๋ฐฉ์ถ
- Operator
- Publisher๋ค์ ์กฐํฉ
- Subscriber
- ๋ฐฉ์ถ๋ ๊ฐ์ ๋ฐ์์ ์ฌ์ฉ
- Publisher
class ViewModel {
let text: AnyPublisher<String, Error>
}
class ViewController: UIViewController {
let label = UILabel()
var viewModel = ViewModel()
init() {
self.viewModel.text
.assign(to: \.text, on: label) // label, text์ assignํ๊ฒ ๋ค
}
}
Publisher
๋ฐฉ์ถํ๋ Event ์ข ๋ฅ
- Output Value
- ํน์ ๊ฐ
- ํน์ ๊ฐ์ ํฌํจํ๋ Event (Publisher๊ฐ ๋ ์๋ ์์)
- Successful Complete
- ํน์ Publisher๊ฐ ์ฑ๊ณต์ ์ผ๋ก ๋๋ ๊ฒฝ์ฐ ๋ฐฉ์ถํ๋ ์ด๋ฒคํธ
- โeventโeventโeventโ|โ
- |์ ํด๋นํ๋ ๊ฒ
- Complete์ดํ์๋ ํด๋น Publisher๋ ๊ฐ์ ๋ฐฉ์ถํ ์ ์์
- Complete with Error
- Error๋ฅผ ๋ฐ์ํ์ฌ Publishing์ด ๋๋ ๊ฒฝ์ฐ
- โeventโeventโERRORโ
Publisher์ ์ ์
let publisher: AnyPublisher<ValueType, ErrorType>
publisher๋ type 2๊ฐ์ง๋ฅผ ์ ์ํด์ผ ํ๋ค. ValueType๊ณผ ErrorType์ด๋ค.
Value Type
- output value event
- ์ด๋ ํ ํ์
์ด๋ ๊ฐ๋ฅ
- Int, class, enum
- array, tuple
- publisher (์ฆ publisher์ publisher๋ ๊ฐ๋ฅ, ์๊ฐ๋ณด๋ค ๋ง์ด ์ฐ์)
typealias InnerPublisher = AnyPublisher<Int, InnerError> let outterPublisher = AnyPublisher<InnerPublisher, OutterError>
Error Type
- complete with error event
Swift.Error
๋ฅผ ์ฑํํด์ผ ํจ- complete with Error event ๋ฐฉ์ถ์ ๋ฐ๋์ ์ ํ Error๋ฅผ ์ฌ์ฉํด์ผ ํ๋ค.
- compiler๊ฐ ๋ณด์ฅํ๋ค. (ํ๋ฆฌ๋ฉด ๋น๋ ์๋ฌ)
- Error๋ฅผ ์ฌ์ฉํ์ง ์๋๋ค๋ฉด
Never
๋ ๊ฐ๋ฅ
Publisher ์์ฑ ๋ฐฉ๋ฒ
Notification
let myNotification = Notification.name("MyNotification")
let publisher = NotificationCenter.default.publisher(for: myNotification, object: nil)
ํน์ ์ฝ๋์์ NotificationCenter.default.post()
ํธ์ถ ์๋ง๋ค, ๋ณ์๋ก ์ ์ธํ publisher์์ notification์ด ๋ฐฉ์ถ๋๋ค.
Array, Range
[1, 2, 3].publisher
["a", "b", "c"].publisher
(1...6).publisher
์ฐ๋ฆฌ๊ฐ ๊ธฐ์กด์ ์ฌ์ฉํ๋ ์๋ฃ๊ตฌ์กฐ ๋๋ถ๋ถ์ด publisher๋ฅผ ์ ๊ณตํ๋ค.
Just
Just(3)
Just("abc")
Just๋ฅผ ์ฌ์ฉํ๋ฉด ํด๋น ๊ฐ ํ๋๋ง ๋ฐฉ์ถํ๋ publisher๊ฐ ๋ง๋ค์ด์ง๋ค. publisher๋ฅผ ์กฐํฉํ ๋, ์ค๊ฐ์ค๊ฐ์ ๋ง์ด ์ฌ์ฉ๋๋ค.
Future
let publisher = Future<ValueType, ErrorType> { result in
// write code
// API ํธ์ถ ๋ฑ์ ์์
ํ ์ฑ๊ณต ์ฌ๋ถ์ ๋ฐ๋ผ..
if success {
result(.success(๋ฐฉ์ถํ ๊ฐ))
} else {
result(.failure(error))
}
}
URLSession
URLSession.shared.dataTaskPublisher(for: url)
- url๋ก ๋ถํฐ data๋ฅผ ๋ฐ์์จ ํ ๊ทธ data๋ฅผ ๋ฐฉ์ถํ๋ publisher
- ์ ์์๋ค๊ณผ ๊ฐ์ด ๊ฐ์ ๋ง๋ค์ด๋ด๋ ๊ธฐ์กด library๋ค์ด publisher๋ฅผ ์ ๊ณตํ๋ค.
KVO
- KVO ๋ง์กฑํ๋ class๋ค, ์ฆ NSObject๋ฅผ ์์๋ฐ๋ ๊ฒ๋ค, UIKit์์ ์ ์ํ๋ ๋๋ถ๋ถ์ ๊ฒฝ์ฐ๋ Publisher๋ฅผ ์์ฑํ ์ ์๋ค.
- ๋ชจ๋ property๊ฐ ๋๋ ๊ฒ์ ์๋๋ค.
let view = UIView()
let publisher = view.publisher(for: \.bounds)
Subscriber
- sink
- closure๋ก ์ด๋ค ์ฝ๋๋ ๊ฐ๋ฅํ๋ค.
- assign
- property์ ๊ฐ์ ๋ฃ์ ์ ์๋ค.
- custom subscriber
sink
publisher.sink(
receiveCompletion: { param in // ์ด์ ์ ๋ฐฐ์ด publisher์ completion์ด ๋์ด์ค๋ ๊ฒฝ์ฐ
switch param {
case .finished:
// error ์์ด complete๋ ์ํฉ
case .failure(let error):
// error ๋ฐฉ์ถ๋ ์ํฉ
}
},
receiveValue: { value in // ๊ฐ์ด ๋์ด์ค๋ ๊ฒฝ์ฐ
// value ๋ฐฉ์ถ๋ ์ํฉ
}
)
assign
class MyClass {
var value: Int
}
let myClass = MyClass()
publisher.assign(to: \.value, on: myClass)
Cancellable
- Subscriber๊ฐ release(ํ ๋น ํด์ ๋๋ ๊ฒฝ์ฐ)๋๋ฉด publish๋ ์๋์ผ๋ก ์ค๋จ๋๋ค.
- release๋๋ ์์ ์ ์ผ๋ฐ ๋ณ์์ release ์์ ๊ณผ ๋์ผํ๋ค.
func method() {
let subscriber = publisher.sink(...)
// ๋ฉ์๋ ๋ด์ ์์ ๊ฒฝ์ฐ subscriber๋ ๊ณ์ ๋์ํ๋ค.
}
// ํด๋น ํจ์์ ๋์์ด ๋๋ ๊ฒฝ์ฐ local variable๋ release๋๋ค.
- ํ์ง๋ง ์ด๋ฐ ๊ฒ์ ์ฐ๋ฆฌ๊ฐ ์ํ๋ ๊ฒ์ด ์๋๋ค.
- method์์ returnํ๋๋ผ๋ subscriber๊ฐ ๊ณ์ ๋์ํด์ผ ํ๋ค.
- ๊ณ์ํด์ ๊ฐ์ ๋ฐ์์์ ์ ๋ฐ์ดํธํ๊ธธ ์ํ๊ธฐ ๋๋ฌธ
- ์ด๋ป๊ฒ ํ ์ ์์๊น? ์ด๋ฐ ๊ฒฝ์ฐ ๋ณดํต class์์ member ๋ณ์๋ก ๊ฐ์ง๊ณ ์๋๋ค.
์๋ ์ค๋จ์ ๋ง๋ ๋ฐฉ๋ฒ
class A {
var mySubscriber: AnyCancellable?
func method() {
self.mySubscriber = publisher.sink(...)
// ๋ฉ์๋๋ฅผ ๋ฒ์ด๋๋ release ๋์ง ์์
}
func otherMethod() {
self.mySubscriber?.cancel() // ํน์ ์ํฉ์์ ๋์์ ๋ฉ์ถ๊ณ ์ถ๋ค๋ฉด cancelํ๊ณ ๋์ฒดํจ
}
}
- ๋ชจ๋ subscriber๋ cancellableํ๋ค.
- ํ์ง๋ง ์ด๋ ๊ฒ ํ๋ฉด ์ฌ์ฉํ๋ ๋ชจ๋ Subscriber๋ฅผ ๋ค ๋ค๊ณ ์์ด์ผ ํ๋ค.
- ํน๋ณํ ํน์ Subscriber๋ฅผ cancelํด์ผ ํ๋ ๊ฒฝ์ฐ๊ฐ ์๋๋ผ๋ฉด ๋ณ์๋ก๊น์ง ๋ค๊ณ ์์ ํ์๋ ์๋ค.
Subscriber๋ค์ ํ๋์ ๋ฉค๋ฒ๋ณ์์ ๋ชจ๋ ๋ฃ๊ธฐ
class A {
var subscriptions = Set<AnyCancellable>()
func method() {
let subscriber = publisher.sink(...)
subscriver.store(in: &subscriptions)
}
// class instance๊ฐ release๋๋ฉด ๋ชจ๋ release๋๋ค.
}
์ผ๋ฐ์ ์ธ ์ฝ๋์ ๋ชจ์ต
class A {
var subscriptions = Set<AnyCancellable>()
func someMethod() {
self.viewModel.aPublisher
.operator()
.sink(...)
.store(in: &subscriptions)
}
}
Subject
- ์๋์ผ๋ก ๊ฐ์ ๋ฐฉ์ถ์ํฌ ์ ์๋ publisher
let subject = PassthroughSubject<Int, Error>
subject.sink(...) // Publisher์ ๋ง์ฐฌ๊ฐ์ง๋ก Subscriber ๋ฑ๋ก
subject.send(value) // ๊ฐ ๋ฐฉ์ถ ๊ธฐ๋ฅ ์ถ๊ฐ
PassthroughSubject
- ๋ฐฉ์ถ๋ง ํ๊ณ , ๊ฐ์ ๋ณด๊ดํ์ง ์๋๋ค.
- ์๋ก Subscribe๋๋ ์๊ฐ ๋ณ๋ค๋ฅธ ๋์์ ํ์ง ์๋๋ค.
- ๊ฐ์ ๋ฐฉ์ถํ ํ์๋ ์ ์ฅํ์ง ์๊ณ ๋ฒ๋ฆฐ๋ค.
- ๊ฐ์ ์ ์ฅํ ํ์๊ฐ ์๋ publisher๋ฅผ ์ฌ์ฉํ ๋ ์ฌ์ฉํ๋ค.
- ํน์ ์ ์ฅํ๋ฉด ๋ฌธ์ ์ ์ฌ์ง๊ฐ ์๋ ๊ฒฝ์ฐ ์ฌ์ฉํ๋ค.
CurrentValueSubject
- ๋ง์ง๋ง์ผ๋ก ๋ฐฉ์ถํ๋ ๊ฐ 1๊ฐ๋ฅผ ๋ณด๊ดํ๋ค.
- ์๋ก Subscribe๋ ๋๋ง๋ค ๋ณด๊ดํ๋ ๊ฐ์ ๋ฐฉ์ถํ๋ค.
-
๋ง์ง๋ง์ผ๋ก ๋ฐฉ์ถํ๋ ๊ฐ์ ์๋์ผ๋ก ์ป์ ์๋ ์๋ค.
let subject = CurrentValueSubject<Int, Error>(0) subject.send(๊ฐ1) subject.send(๊ฐ2) let val = subject.value // ์ ์ฅ๋ ๊ฐ์ ์ป์
- ๋ณ์์ฒ๋ผ ์ฌ์ฉํ ์ ์์ผ๋ฉด์ Publisher๋ก ์ฌ์ฉ๋ ๊ฐ๋ฅํ๋ค.
- ํ์ฌ ์ํ๊ฐ์ ์ ์ฅํ๋ ์ฉ๋๋ก ์ข๋ค.
Subject์ ๋จ์
Combine์ ์ ์ด์ ๋ณํํ๋ ๊ฐ๋ค์ sequence๋ฅผ ๋ค๋ฃจ๋ ๋ฐฉ๋ฒ์ผ๋ก ๋์จ ํ๋ ์์ํฌ์ด๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ๊ฐ์ฒ๋ผ ์ฌ์ฉ๋ ์ ์๋ Subject๋ฅผ ๋จ์ฉํ๋ฉด, Combine์ ์ฌ์ฉํ์ง ์๋ ์ฝ๋์ ๋น์ทํ ํํ๊ฐ ๋ ์ ์๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ๋จ์ฉํ์ง ์๋ ๊ฒ์ด ์ข๋ค. ๊ฐ์ฅ ๋์ค์ ๊ณ ๋ คํ๋ ์ฉ๋๋ก ๋๋ฉด ์ข์ ๊ฒ์ด๋ค.
Operator
์ํ์ operator๋ ์ซ์ฐจ๋ฅผ ์กฐํฉํด์ ์๋ก์ด ์ซ์๋ฅผ ๋ง๋๋ ๊ฒ์ด๋ค. ์ฐ์ด์ด์ ์ฌ์ฉ์ด ๊ฐ๋ฅํ๋ค.(์ฐ์ฐ์ ์ฐ์ ์์๊ฐ ๊ฐ์ ๊ฒฝ์ฐ)
Combine์์ Operator๋ Publisher๋ฅผ ์กฐํฉํ์ฌ ์๋ก์ด Publisher๋ฅผ ๋ง๋ ๋ค๋ผ๊ณ ์ดํดํ๋ฉด ์ข์ ๋ฏํ๋ค. ์ํ์์์ Operator์ ๋ง์ฐฌ๊ฐ์ง๋ก ์ฐ์ด์ด์ ์ฌ์ฉ์ด ๊ฐ๋ฅํ๋ค.(chain)
publisher.oprator1().operator2(parameter: anotherPublisher)...
- failure๊ฐ ๋ฐ์ํ๋ ๊ฒฝ์ฐ, ๋๋ถ๋ถ์ operator๋ failure๋ฅผ ๊ทธ๋๋ก ์๋๋ก ์ ๋ฌํ๋ค.
- (๋ฌผ๋ก failure๋ฅผ ๋ณํํ๋ operator๋ ์๋ค.)
map
let publisher = intPublisher.map { $0 * 2 }
let strPublisher = pub.map { String($0) }
-
array์์์ map
[10, 20].map { [$0 + 1, $0 + 2]} == [[11, 12], [21, 22]]
-
publisher์์์ map
let pub1 = [10, 20].publisher let pub2 = pub1.map{ [$0 + 1, $0 + 2].publisher } // pub1์ด ๋ฐฉ์ถํ๋ ๊ฐ -> array๋ก ๋ณํํ -> ํด๋น array๋ฅผ ๋ฐฉ์ถํ๋ publisher๋ก ๋ณํ
- ๊ฒฐ๊ณผ
- type:
Publisher<Publisher<Int, Error>, Error>
- action:
[11, 12].publisher
๋ฐฉ์ถ ํ,[21, 22].publisher
๋ฐฉ์ถ
tryMap
- map๊ณผ ๊ฐ์ผ๋ ๋ด๋ถ์์ error throw ๊ฐ๋ฅ
publisher.tryMap {
if {
throw myError
}
}
publisher.map {
if {
throw myError // ๋น๋ ์๋ฌ
}
}
- map์ ๊ฒฝ์ฐ, ๋ด๋ถ์์ failure๊ฐ ๋ฐ์ํ์ง ์๋๋ค๋ ๊ฒ์ ๋ณด์ฅํ๋ค. ์ฐธ๊ณ
- ๋ง์ฝ publisher์์, ์ฆ ์ฝ๋๋ธ๋ฝ ๋ฐ๊นฅ์ชฝ์์ failure๊ฐ ๋ฐ์ํ๋ค๋ฉด, map, tryMap ๋ชจ๋ ๊ทธ๋๋ก ์๋๋ก ์ ๋ฌํ๋ค.
flatMap
-
array์์์ flatMap
[[1, 2], [3, 4]].flatMap { $0 } == [1, 2, 3, 4]
- 2์ฐจ์ array๊ฐ ์์ ๋, flatten๋จ
-
publisher์์์ flatMap
let pub1: AnyPublisher<AnyPublisher<Int, Error>, Error> let pub2: pub1.flatMap { $0 } // type: AnyPublisher<Int, Error>
- publisher์์ publisher๊ฐ ์๋ ํํ
- ์ฆ, publisher๋ฅผ ๋ฐฉ์ถํ๋ publisher
- ์ด ๊ฒฝ์ฐ, ๋ด๋ถ type์ ๋ฐฉ์ถํ๋ publisher๋ก ๋จ
์์ map์ ์์์ ๋น๊ตํด๋ณด์. ๋ง์ฝ map์์์ ์์๋ก ๋ ์ฝ๋์์ flatMap์ผ๋ก ๋ณ๊ฒฝํ๋ฉด ๊ฒฐ๊ณผ๊ฐ ์ด๋ป๊ฒ ๋ ๊น?
-
array์์์ map
[10, 20].flatMap { [$0 + 1, $0 + 2]} == [11, 12, 21, 22]
-
publisher์์์ map
let pub1 = [10, 20].publisher let pub2 = pub1.flatMap{ [$0 + 1, $0 + 2].publisher } // pub1์ด ๋ฐฉ์ถํ๋ ๊ฐ -> array๋ก ๋ณํํ -> ํด๋น array๋ฅผ ๋ฐฉ์ถํ๋ publisher๋ก ๋ณํ
- ๊ฒฐ๊ณผ
- type:
Publisher<Int, Error>
- action:
[11, 12, 21, 22]
๋ฐฉ์ถ
๋ํ์ ์ฉ๋
- ๊ฐ์ ๋ณํํด์ผ ํ๋๋ฐ, ๋ฐ๋์ publisher๋ก ๋์์ผ ํ ๋
.flatMap { ์ฌ์ฉ์์ ํ๋์ผ๋ก ๊ฐ์ ๋ฐฉ์ถํ๋ publisher }
.flatMap { API๋ฅผ ์๊ณ ์๋ต์ ๋ฐ๋ Publisher }
์ด๋ฐ ๊ฒฝ์ฐ ์ฌ์ฉํ๋ฉด result๋ API์๋ต ๊ฐ๋ค์ ๋ฐฉ์ถํ๋ Publisher๊ฐ ๋๋ค.
๋์ ๋ฐฉ์
- ๊ฐ์ฅ ์๋ผ์ธ์ publishers๋ฅผ ๋ฐฉ์ถํ๋ publisher
- flatMap์ ํ๋ผ๋ฏธํฐ๋ก ์ต๋ publisher๋ฅผ 2๊ฐ๋ง ๊ฐ์ง๋๋ก ํ๋ค.
- flatMap์ map + flatten์ด๋ค.
- ๊ทธ๋์ ์ผ๋จ map์ ์ ์ฉ๋ถํฐ ์๊ฐํด๋ณด๋ฉด, ๊ฐ๊ฐ์ publisher๋ฅผ
$0.value
๋ก ์์ฑํด์ค๋ค.$0.value
๋ ๊ฐ ์์ฒด๋ฅผ ๋ด๋ณด๋ด๋ ๊ฒ์ด ์๋๊ณ , publisher๋ฅผ ๋ง๋ค์ด์ฃผ๋ ํ์์ด๋ค.- ์ฆ, p1.value๊ฐ ์ ์ฉ๋ ๊ฒฝ์ฐ, p1์ 1, 4๋ฅผ ๋ฐฉ์ถํ๋ publisher๋ฅผ ๋ง๋ค์ด์ฃผ๊ณ
- p2.value๊ฐ ์ ์ฉ๋ ๊ฒฝ์ฐ, p2์ 2, 5๋ฅผ ๋ฐฉ์ถํ๋ publisher๋ฅผ ๋ง๋ค์ด์ค๋ค.
- ๊ทธ๋์ ์์ฑ ์์ ์ ๋ณด๋ฉด, p1, p2, p3๊ฐ ์์ฐจ ์ ์ฉ๋๋ฉด์ publisher ์์ฑ ์์ ์ด ๋ฐ๋ฆฌ๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
- ์ด ๋, max publisher๋ฅผ 2๋ก ์ก์๊ธฐ ๋๋ฌธ์, publisher๋ 2๊ฐ๋ง ์ฑ๊ธด๋ค.
- ๋ง์ง๋ง์ผ๋ก flatten์ ์ ์ฉํ์ฌ ํ๋์ publisher๋ก ๋ง๋ค์ด์ค๋ค.
switchToLatest
let pub1: Publisher<Publisher<Int, Error>, Error>
let pub2 = pub1.switchToLastest()
- pub2์ type์
Publisher<Int, Error>
์ด๋ค.flatMap
๊ณผ ๋์ผํ๋ค.
- ํ์ง๋ง, Publisher๊ฐ ๋ฐฉ์ถ๋ ๋๋ง๋ค, ๊ทธ ์ ์ ๋ฐฉ์ถ๋์๋ Publisher๋ ๋ฌด์๋๋ค.
- flatMap์ ์ ์ฉํ๋ฉด, publisher๋ค์ด ๋ฐฉ์ถํ ๊ฐ๋ค์ ๋ฌถ์ด์ ํ๋์ Publisher๋ก ๋ง๋ค์ด์ฃผ์๋ค.
- ๊ทธ๋ฐ๋ฐ, ๊ฐ๊ฐ์ Publisher๋ค์ด ๋ฐฉ์ถํ๋ ์์ ์ด ๋ค๋ฅด๊ธฐ ๋๋ฌธ์, ๊ฐ๊ฐ์ Publisher์์์ ๋ฐฉ์ถํ ๊ฐ์ด ์์ฌ์ ์ต์ข Publisher์์ ๋ฐฉ์ถ๋๋ค.
- switchToLatest๋ฅผ ์ฌ์ฉํ๊ฒ ๋๋ฉด, ์ด ์์ ์์ ๊ฐ์ฅ ์ต๊ทผ์ Publishํ Publisher๋ง ๊ฐ์ ๋ฐ์ํ Publisher๋ฅผ ๋ง๋ค์ด์ค๋ค.
์ผ๋ถ ์ ์ธ ์ผ๋ถ ๋ฐฉ์ถ
-
์ด๋ ๊ฒ ๋ฐฉ์ถํ๋ ๊ฐ์ ์ผ๋ถ ์ ์ธํ๊ณ ์ผ๋ถ๋ ๋ฐฉ์ถํ๋ operator๋ค์ด ์๋ค.
- filter, compactMap
- first, first(where:), last, last(where:)
- drop, prefix
-
removeDuplicates
[1, 2, 2, 3, 3, 2, 2, 4].publisher.removeDuplicates() == [1, 2, 3, 2, 4].publisher
- ๊ฐ์ ๊ฐ์ด ๋ฐ๋ณตํ์ฌ ๋ฐฉ์ถ๋๋ ๊ฒ์ ๋ง๋ operator
merge
- type์ด ๊ฐ์ publisher๋ค์ ์กฐํฉ
- ๊ฐ publisher๋ด์์ ๊ฐ์ด ๋ฐฉ์ถ๋๋ฉด, ๊ทธ๋๋ก ๋ค๋ก ๋ฐฉ์ถ์ํด
let result = pub1.merge(pub2, pub3)
combineLastest
- ๊ฐ publisher ๋ด์์ ๊ฐ์ด ๋ฐฉ์ถ๋๋ฉด, ๋ค๋ฅธ publisher์ ๋ง์ง๋ง ๊ฐ๊ณผ ์กฐํฉํ์ฌ tuple์ ๋ง๋ค์ด ๋ฐฉ์ถ
- ์ด๋ฐ ์์ฑ ๋๋ฌธ์ Publisher๋ค์ Type์ด ๋ฌ๋ผ๋ ๋๋ค. ์ด์ฐจํผ ๋ฌถ์ด์ tuple๋ก ๋ฐฉ์ถํ๊ธฐ ๋๋ฌธ
delay
- ์ง๊ธ๊น์ง๋ ๋ฐฉ์ถ๋ ์์ ์ ๊ธฐ์ค์ผ๋ก action์ด ์ทจํด์ก๋ค.
- delay๊ฐ์ ๊ฒฝ์ฐ, ๋ฐฉ์ถ๊ฐ์ ๊ธฐ์ตํ๊ณ ์๋ค๊ฐ, ์ผ์ ์๊ฐ ์ดํ ๋ถํฐ ๋ฐฉ์ถ์ ์์ํ๋ค.
debounce
- ์ผ์ ์๊ฐ ๋์ ๋ฐฉ์ถ์ด ์์ ๊ฒฝ์ฐ, ๋ค๋ก ๋ฐฉ์ถ
- ์ฌ์ฉ์๊ฐ ๊ธ์๋ฅผ ์ ๋ ฅํ๋ ๊ฒฝ์ฐ ์ ์ฉ