μ λ€λ¦ ꡬ쑰체 | μ£Όμ΄μ§ ν΄λ‘μ κ° falseλ₯Ό λ°νν λκΉμ§ μμμ νλ₯΄λ Publisherλ‘λΆν° μμλ₯Ό μλ΅νλ Publisher
μ΄λμ
λΌμ΄μ λ λ κ°μ μΈμλ₯Ό λ°λλ€.
upstream
: μμμ νλ₯΄λ Publisher
predicate
: μμμ μλ΅ μ¬λΆλ₯Ό κ²°μ νλ ν΄λ‘μ
쑰건μ λ§μ§ μμ λκΉμ§λ λ°νλ κ°μ 무μνκΈ° μν΄ μ¬μ©νλ€.
drop
μ€νΌλ μ΄ν°μ κ΄λ ¨μ΄ μλ€.
// 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μ κ°μ λ΄κ³ μ’
λ£νλ€.
RxSwift
skipWhile
μ€νΌλ μ΄ν°λ₯Ό μ¬μ©νμ¬ κ΅¬νν μ μλ€.
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
ReactiveSwift
skip
μ€νΌλ μ΄ν°λ₯Ό μ¬μ©νμ¬ κ΅¬νν μ μλ€.
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
μ°Έκ³
ReactiveX - Operators - Skip