Publishers.AllSatisfy
μ λ€λ¦ ꡬ쑰체 | μ λ¬λ°μ λͺ¨λ μμκ° μ£Όμ΄μ§ 쑰건μ ν΅κ³Όνλμ§λ₯Ό λνλ΄λ νλμ λΆλ¦¬μΈ κ°μ λ°ννλ Publisher
μ΄λμ λΌμ΄μ λ λ κ°μ μΈμλ₯Ό λ°λλ€.
upstream
: μμμ νλ₯΄λ Publisherpredicate
: κ°κ°μ μ λ¬λ°μ μμλ₯Ό νκ°νλ ν΄λ‘μ
μμ Publisherκ° λ΄λ λͺ¨λ κ°λ€μ΄ μ£Όμ΄μ§ 쑰건μ ν΅κ³Όνλμ§λ₯Ό λνλ΄λ λΆλ¦¬μΈ κ°μ λ°ννλ€.
λͺ¨λ κ°λ€μ΄ μ£Όμ΄μ§ 쑰건μ λ§μ‘±νλμ§ μκΈ° μν΄ μ¬μ©ν μ μλ€.
allSatisfy
μ€νΌλ μ΄ν°μ κ΄λ ¨μ΄ μλ€.
// Publishers.AllSatisfy Publisher
Publishers
.AllSatisfy(upstream: Publishers.Sequence<[Int], Never>(sequence: [2, 4, 7])) { $0.isMultiple(of: 2) }
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine AllSatisfy Error")
case .finished:
print("Combine AllSatisfy Finish")
}
}, receiveValue: { value in
print("Combine AllSatisfy : \(value)")
})
.store(in: &cancellables)
// allSatisfy Operator
Publishers.Sequence<[Int], Never>(sequence: [2, 4, 7])
.allSatisfy { $0.isMultiple(of: 2) }
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine AllSatisfy Error")
case .finished:
print("Combine AllSatisfy Finish")
}
}, receiveValue: { value in
print("Combine AllSatisfy : \(value)")
})
.store(in: &cancellables)
// Combine AllSatisfy : false
// Combine AllSatisfy Finish
μμ Publisherκ° 2, 4, 7μ κ°μ μ°¨λ‘λλ‘ λ΄κ³ , 쑰건μΌλ‘ κ°μ΄ 2μ λ°°μμΈμ§λ₯Ό νμΈνκ² νμλ€.
2, 4μ κ°μ 2μ λ°°μμ΄λ 7μ κ°μ 2μ λ°°μκ° μλλ―λ‘ λͺ¨λ κ°λ€μ΄ 쑰건μ λ§μ‘±νμ§ μκ² λλ€.
κ²°κ³Όμ μΌλ‘ falseλ₯Ό λ°ννκ³ μ’ λ£νλ€.
RxSwift
ν΄λΉ λμμ ꡬννκΈ° μν μ€νΌλ μ΄ν°λ₯Ό μ 곡νμ§ μλλ€.
ReactiveSwift
ν΄λΉ λμμ ꡬννκΈ° μν μ€νΌλ μ΄ν°λ₯Ό μ 곡νμ§ μλλ€.
μ°Έκ³
Last updated
Was this helpful?