Publishers.Drop
μ λ€λ¦ ꡬ쑰체 | λμ€μ μμκ° λ€μ λ°νλκΈ° μ΄μ μ λͺ μν κ°μμ μμλ₯Ό μλ΅νλ Publisher
μ΄λμ λΌμ΄μ λ λ κ°μ μΈμλ₯Ό λ°λλ€.
upstream
: μμμ νλ₯΄λ Publishercount
: μλ΅ν μμμ κ°μ
쑰건 μμ΄ μμμ λͺ κ°μ μμλ₯Ό μλ΅νκ³ μΆμ λ μ¬μ© κ°λ₯νλ€.
μ΄κΈ°κ°μ κ°λ CurrentValueSubject
λ₯Ό μ¬μ©νλ κ²½μ°, μ΄κΈ°κ°μ 무μνκΈ° μν΄ μ¬μ©ν μ μλ€.
dropFirst
μ€νΌλ μ΄ν°μ κ΄λ ¨μ΄ μλ€.
// Publishers.Drop Publisher
Publishers
.Drop(upstream: Publishers.Sequence<[Int], Never>(sequence: [1, 2, 3]), count: 2)
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine Drop Error")
case .finished:
print("Combine Drop Finish")
}
}, receiveValue: { value in
print("Combine Drop : \(value)")
})
.store(in: &cancellables)
// dropFirst Operator
Publishers.Sequence<[Int], Never>(sequence: [1, 2, 3])
.dropFirst(2)
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine Drop Error")
case .finished:
print("Combine Drop Finish")
}
}, receiveValue: { value in
print("Combine Drop : \(value)")
})
.store(in: &cancellables)
// Combine Drop : 3
// Combine Drop Finish
μμ Publisherλ 1, 2, 3μ κ°μ μ°¨λ‘λλ‘ λΈλ€.
2κ°μ μμλ₯Ό μλ΅νκ² νμμΌλ―λ‘ μ΅μ’ μ μΌλ‘ 3μ κ°μ λ΄κ³ μ’ λ£νλ€.
RxSwift
skip
μ€νΌλ μ΄ν°λ₯Ό μ¬μ©νμ¬ κ΅¬νν μ μλ€.
Observable.from([1, 2, 3])
.skip(2)
.subscribe(onNext: { value in
print("RxSwift Drop : \(value)")
}, onError: { _ in
print("RxSwift Drop Error")
}, onCompleted: {
print("RxSwift Drop Finish")
})
.disposed(by: disposeBag)
// RxSwift Drop : 3
// RxSwift Drop Finish
ReactiveSwift
skip
μ€νΌλ μ΄ν°λ₯Ό μ¬μ©νμ¬ κ΅¬νν μ μλ€.
SignalProducer([1, 2, 3])
.skip(first: 2)
.start { event in
switch event {
case let .value(value):
print("ReactiveSwift Drop : \(value)")
case .failed:
print("ReactiveSwift Drop Error")
case .completed:
print("ReactiveSwift Drop Finish")
default:
break
}
}
// ReactiveSwift Drop : 3
// ReactiveSwift Drop Finish
μ°Έκ³
Last updated
Was this helpful?