이니셜라이저는 한 개의 인자를 받는다.
// Publishers.First Publisher
Publishers
.First(upstream: Publishers.Sequence<[Int], Never>(sequence: [1, 2, 3, 4, 5]))
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine First Error")
case .finished:
print("Combine First Finish")
}
}, receiveValue: { value in
print("Combine First : \(value)")
})
.store(in: &cancellables)
// first Operator
Publishers.Sequence<[Int], Never>(sequence: [1, 2, 3, 4, 5])
.first()
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine First Error")
case .finished:
print("Combine First Finish")
}
}, receiveValue: { value in
print("Combine First : \(value)")
})
.store(in: &cancellables)
// Combine First : 1
// Combine First Finish
상위 Publisher는 1, 2, 3, 4, 5의 값을 차례대로 낸다.
Observable.from([1, 2, 3, 4, 5])
.first()
.subscribe(onSuccess: { value in
print("RxSwift First : \(value)")
}, onError: { _ in
print("RxSwift First Error")
})
.disposed(by: disposeBag)
// RxSwift First : Optional(1)
SignalProducer([1, 2, 3])
.first()?.signal
.observe { event in
switch event {
case let .value(value):
print("ReactiveSwift First : \(value)")
case .failed:
print("ReactiveSwift First Error")
case .completed:
print("ReactiveSwift First Finish")
default:
break
}
}
// ReactiveSwift First : 1
// ReactiveSwift First Finish