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?