Publishers.ContainsWhere
์ ๋ค๋ฆญ ๊ตฌ์กฐ์ฒด | ์กฐ๊ฑด ํด๋ก์ ๋ฅผ ๋ง์กฑํ๋ ์์๋ฅผ ์ ๋ฌ๋ฐ๋๋์ ๋ฐ๋ผ ๋ถ๋ฆฌ์ธ ๊ฐ์ ๋ฐฉ์ถํ๋ Publisher
์ด๋์ ๋ผ์ด์ ๋ ๋ ๊ฐ์ ์ธ์๋ฅผ ๋ฐ๋๋ค.
upstream
: ์์์ ํ๋ฅด๋ Publisherpredicate
: ์์๊ฐ ์กฐ๊ฑด๊ณผ ๋ง๋์ง ํ๋จํ๊ธฐ ์ํ ํด๋ก์
predicate
์ ๋๊ฒจ์ง ํด๋ก์ ๋ฅผ ํต๊ณผํ๋ ์์๊ฐ ์๋ค๋ฉด true๋ฅผ ๋ฐํํ๊ณ ๊ทธ๋ ์ง ์์ผ๋ฉด false๋ฅผ ๋ฐํํ๋ค.
contains
์คํผ๋ ์ดํฐ์ ๊ด๋ จ์ด ์๋ค.
// Publishers.ContainsWhere Publisher
Publishers
.ContainsWhere(upstream: Publishers.Sequence<[Int], Never>(sequence: [2, 4, 6])) { $0 == 5 }
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine ContainsWhere Error")
case .finished:
print("Combine ContainsWhere Finish")
}
}, receiveValue: { value in
print("Combine ContainsWhere : \(value)")
})
.store(in: &cancellables)
// contains Operator
Publishers.Sequence<[Int], Never>(sequence: [2, 4, 6])
.contains { $0 == 5 }
.sink(receiveCompletion: { completion in
switch completion {
case .failure:
print("Combine Contains Error")
case .finished:
print("Combine Contains Finish")
}
}, receiveValue: { value in
print("Combine Contains : \(value)")
})
.store(in: &cancellables)
// Combine ContainsWhere : false
// Combine ContainsWhere Finish
ํด๋ก์ ๋ก ์กฐ๊ฑด ํ๊ฐ์์ ๋๊ฒจ ํด๋น ์กฐ๊ฑด์ ํต๊ณผํ๋ ์์๊ฐ ์๋์ง์ ๋ํ ๋ถ๋ฆฌ์ธ ๊ฐ์ ๋ฐํํ๋ค.
์์ Publisher๋ 2, 4, 6์ ๊ฐ์ ์์๋๋ก ๋ด๋ฉฐ, ์กฐ๊ฑด์ธ $0 == 5
๋ฅผ ํต๊ณผํ๋ ์์๊ฐ ํ๋๋ ์์ผ๋ฏ๋ก ๊ฒฐ๊ณผ์ ์ผ๋ก false๋ฅผ ๋ด๊ณ ์ข
๋ฃํ๋ค.
RxSwift
ํด๋น ๊ธฐ๋ฅ์ ๊ตฌํํ๊ธฐ ์ํ ์คํผ๋ ์ดํฐ๋ฅผ ์ ๊ณตํ์ง ์๋๋ค.
ReactiveSwift
ํด๋น ๊ธฐ๋ฅ์ ๊ตฌํํ๊ธฐ ์ํ ์คํผ๋ ์ดํฐ๋ฅผ ์ ๊ณตํ์ง ์๋๋ค.
์ฐธ๊ณ
Last updated
Was this helpful?