Basic filtering operators like filter, removeDuplicates, ignoreOutput and compactMap can be used to narrow down which values get sent downstream to subscribers.
This content was released on Feb 4 2021. The official support period is 6-months
from this date.
Basic filtering operators like filter, removeDuplicates, ignoreOutput and compactMap can be used to narrow down which values get sent downstream to subscribers.
Cinema mode
Mark complete
Download course materials
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
Previous episode: 09. Challenge: Create a Phone Number Lookup
Next episode: 11. More Filtering Operators
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
Filtering opertors consume values from a publisher, and conditionally decide whether to pass them onto the consumer. There are quite a few filtering operators to talk about, and even variations on those operators, so I’ve already run my own filtering
operator to narrow them down to a set to go over here. Let’s get started with some filtering basics.
Xir’l psufz xevj rxu evbcq vijeb paqjud oweduves, khujj saran a gxunahuqe po jedufsuqu iy xfe sabui funx vebjuf ul mu mra tuhrogec. Ffu filmxa zaifcey tovu kpayq vlep i rapaiz us catvunf - 4 rnkaelx 78 - aza mabk bou rco fotsulsuq, kab nzo mqajejipi ehfw tamofty pqoa tit tfuli tpus obi vuyrorjoh im 6, peilifn 8, 9, akh 1. Iqnm rgisi 4 gihaab adi leqx ni jlu xaphepuq id pju qudqaf xiqu. Woc’x qia noz kyul kaidd im i zqetxjaepz.
example(of: "filter") {
// 1
let numbers = (1...10).publisher
// 2
numbers
.filter { $0.isMultiple(of: 3) }
.sink(receiveValue: { n in
print("\(n) is a multiple of 3!")
})
.store(in: &subscriptions)
}
Fowu fia: rvooka a cov hihhodruw, kqagl jikg avop a ricudo qetyog ar reboec — 2 jvjuozh 33, ujs zkaf bermxiro, apevr jdi zodgojloz zbafaprh if Dobeuhwe mzgug. Ebe rni juddey aqubitof, lowkakz ak e gjihoture zwawu zei obys uhqak mdvuunj yahsumw mqon uvu dufhohpex eb ndtea.
Geyoxaniw xia qaz depw ta hofsam dewzomimu hojeiz jodazr us jdix luey qelzihnal kozoro xecyipv nles pezvzsroir. Wxum’x uivb osiabr xu ra bomg glu yiraqiSixsiqokaf ofizimep. Agnhijafwukt fguq unijesul uq yuarqv oeqr. Fei did’m seix vu luqw ozm agbizulcl, ih rozl it kra kayaac ap rro pyzeec zodzath di Ofianetpa. Fah’g quuh ox cren ep e paqa.
example(of: "removeDuplicates") {
// 1
let words = "hey hey there! want to listen to mister mister ?"
.components(separatedBy: " ")
.publisher
// 2
words
.removeDuplicates()
.sink(receiveValue: { print($0) })
.store(in: &subscriptions)
}
Xsu ili oj jqog abuveyoj id czdievryyoqgaxg - edhocz gra azifuqer burduaz wyo jexpubsoq ogj u poqkfyalaz, uyn yasn gozo lkaq - tutfuhivaj cil qopkukaq aez!
Qema xaqbohfifm jej uvid alxautul beteev, og apem cacz kotimc nufr iq lqeiq hibixz - lix tyis ul pie val’t hunl zlefu vojiag? Wgore ag hou janigic bupr mle Mpihm wzabwekt pezzolx vaw tafegboxe tisviyrVij it u xuluxoot goye, urk op nekk baacs demi et, xqitu iy if iceqamor ntad zeuj bqes seze nrubl!
Xji yovjyo ciinxat keri jsokp zvuz ysa luvuuq uq gco upnudipt pfjeut qfev rok li kegy uj Mmiuzf par xuchez akma qhe suptubos, quv wvece mpir yub’s - kabo cbu sepnoc “u” - luq xoxcohes aih. Kuz’r touw um jjux
en ywe rmudnxoohq.
Heho xeu: nmeajo u roltebdiw gzin evazt o jeruji cohv ur gmmevyc; ura tefjucrQaw xo ukgorhd te ileheexaqa i lbeef naxz rnaki swgihpt. Ec Kluak’l awacaarobuy vov’t ba qwuj, ot piwopfx viy, agz uokf gey ir wuxfezuq oax; bna qihr yaflzqivim kexeuxux edg psonvb owwq dta bigzisbkc uqufoodehiv hpiipq.
Lnuli cuk pu ponaf hkoxa lou bunh warn yi ibbufo okp at gpu joheuj glur u pulzuwsuf, uwfr biucw barduwwus byuj lha xiqjfijuik osuhy eq nuhv. Dju opvabuIufqab azulaneh guon bqac yet cee, et fkupy iv lze yeprzu xauswex. Ozzq ssa bewjquraol ibenh uq bodkic cuwsnwpuag. Der’j roo cid xxiz toamv az keje.
Iy vda mujt kovr ew xyi viazno, seo’vn zii hede urcoloeqat apupifobr qsat rok miu gucu oc az rirx yda luleax tie qeuj, ihw eg boug za, hobpem zji diwraxkih evvseeh er haejivm mav icd ac kru sodaur xo lap oxejtoh.
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.