이니셜라이저는 두 개의 인자를 받는다.
조건에 맞지 않을 때까지는 발행된 값을 무시하기 위해 사용한다.
// Publishers.DropWhile Publisher
Publishers
.DropWhile(upstream: Publishers.Sequence<[Int], Never>(sequence: [1, 2, 3])) { $0 < 3 }
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine DropWhile Error")
case .finished:
print("Combine DropWhile Finish")
}
}, receiveValue: { value in
print("Combine DropWhile : \(value)")
})
.store(in: &cancellables)
// drop Operator
Publishers.Sequence<[Int], Never>(sequence: [1, 2, 3])
.drop { $0 < 3 }
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine DropWhile Error")
case .finished:
print("Combine DropWhile Finish")
}
}, receiveValue: { value in
print("Combine DropWhile : \(value)")
})
.store(in: &cancellables)
// Combine DropWhile : 3
// Combine DropWhile Finish
상위 Publisher가 1, 2, 3의 값을 순서대로 낸다.
3 미만일 때까지 발행된 값을 생략하라는 조건에 의해 3의 값을 내고 종료한다.
Observable.from([1, 2, 3])
.skipWhile { $0 < 3 }
.subscribe(onNext: { value in
print("RxSwift DropWhile : \(value)")
}, onError: { _ in
print("RxSwift DropWhile Error")
}, onCompleted: {
print("RxSwift DropWhile Finish")
})
.disposed(by: disposeBag)
// RxSwift DropWhile : 3
// RxSwift DropWhile Finish
SignalProducer([1, 2, 3])
.skip { $0 < 3 }
.start { event in
switch event {
case let .value(value):
print("ReactiveSwift DropWhile : \(value)")
case .failed:
print("ReactiveSwift DropWhile Error")
case .completed:
print("ReactiveSwift DropWhile Finish")
default:
break
}
}
// ReactiveSwift DropWhile : 3
// ReactiveSwift DropWhile Finish