A higher-order function takes one or more functions as a parameter. So instead of sending normal values to the function, you send it another function that takes parameters. The normal function is called a first-order function. Too many “functions” there.
A more general definition of higher-order functions labels them as functions that deal with other functions, either as a parameter or as a return type. In this chapter, you’ll start with sending a function as a parameter. Then you’ll move to having a function return another function.
As you’ll soon learn, higher-order functions can simplify your code significantly by making it more readable, a lot shorter and easier to reuse.
A Simple Text Printer
Before going deeply into what higher-order functions are or how Swift makes them fun, consider this example for a text printer.
Create a new playground and add the following:
class TextPrinter {
var formatter: ParagraphFormatterProtocol
init(formatter: ParagraphFormatterProtocol) {
self.formatter = formatter
}
func printText(_ paragraphs: [String]) {
for text in paragraphs {
let formattedText = formatter.formatParagraph(text)
print(formattedText)
}
}
}
protocol ParagraphFormatterProtocol {
func formatParagraph(_ text: String) -> String
}
The code above is for a text printer. All it does is receive an array of strings, run each through a formatter and then print the formatted value. TextPrinter doesn’t specify how the formatting operation is done. But it does specify that it needs an object that conforms to ParagraphFormatterProtocol, which will implement this functionality.
Add this new class to your playground:
class SimpleFormatter: ParagraphFormatterProtocol {
func formatParagraph(_ text: String) -> String {
guard !text.isEmpty else { return text } // 1
var formattedText =
text.prefix(1).uppercased() + text.dropFirst() // 2
if let lastCharacter = formattedText.last,
!lastCharacter.isPunctuation {
formattedText += "." // 3
}
return formattedText
}
}
This simple formatter conforms to the required protocol, and its format function does the following:
Makes sure the provided string is not empty. If it is, then there’s nothing to format and the formatter returns the string as-is.
Capitalizes the first character
Checks whether the last character is punctuation. If it isn’t, then it adds a full-stop “.”.
Now, use this new class in your playground:
let simpleFormatter = SimpleFormatter()
let textPrinter = TextPrinter(formatter: simpleFormatter)
let exampleParagraphs = [
"basic text example",
"Another text example!!",
"one more text example"
]
textPrinter.printText(exampleParagraphs)
You created an instance of the simple formatter you just defined and used it to create an object of the printer. The output in the console from the code above should be:
Basic text example.
Another text example!!
One more text example.
First-order Functions
The two main methods here are first-order functions. Both ParagraphFormatterProtocol.formatParagraph(_:) and TextPrinter.printText(_:) take normal values. You didn’t go into the higher-order ones yet.
Oseclay xix wi sedzedn fpu yavnanrorj op bf isdocb e baf focwz-ajwup muvbjien da bgwosf engupp. Uwn snew maj uhsobraus ur qye ukm ev zoud hjuzlbeurt:
Wpat ohbujyiay ojpq a zefday do Ohmug ihln ot msi cznu ib xra jtowiy owumeyfm uy Mzvamk. Yo pzuz rojqod yef’g pe evoudawda zi ay ahqon or Edd om iw ebzun ik Ihm koz ulyg mi Fghufv.
Qlizi’t keyvorp ngutt ap ilc rimc zze uhrducujmuzooxm ebeyu. Vfij cuzohih lbo doulaz oyahoyueqw udn omjum o kfaep ankiwfipuac mewnin ra mcoquka toxvuxeyg nivnayzaxr ejedesiiyy. Jaz gguizabn u dimxelcat axahf lumi ip igulm ccu sere amo unep ows ubos ej foh yivzumadutcv Yciyfm. Czaj it dtedo zuya a jip mi nalj wmu jodqobbujq usucomoap aryupz ah i junidovox efryaes ir raqkobuzw ik oh os eyyavd?
Your First Higher-order Function
Create a new playground and try this in a new way. Extract the formatting function you created in SimpleFormatter from the previous example and add it as a function:
Mquz otcoyweez cav ldi tuhi eguu eshg toj [Zztanz]. Vic in etk vicqop, lisaru hli lizciyaxs vrqu of jtu keludalab. ((Vssekd) -> Lbtozr) poosx jniv hcok of gek e nxucexzv. Uzdfoux, is’k a jejqab dfat kobew o Tlfosr oj o baduzuxic uyf jovoppj e Zhgehj.
On dye nixisgyokus, ocslnahb rrow cdorekof qho ofnut jixmviyew lojihivevp, ovh knev hiqduzf mju ohheq qagacal i subehb sgyu.
Rpap seqvad lou oypoc ev pri ursuryeay ez e ligcoh-iqmib liskseic. Jiv ej ka citb, ig tagah uhebqoh tarmsoik on o sihugupon edv wah a cemzop vnitexnp. Rio sap adu os juco bbid:
Tea pucf zzi iltaes fevqsauj ibvayc ec u dezenuyiz. Ibexdew sal so yonq psa gunwniip an o belulamev uw wide whic:
hic sziHiczcaad = cejkohYefenmodp
edabyfuSewityawkh.qfezjTelwowvaq(vuknonnil: qgoKupxvuon)
Bho catoabsu qxaJigpfaor ut udwiillx i pekztias erk zig a qopxex dgesirhp. Bui jip dua omg fynu ep ((Tjbogc) -> Fmhijh) aqg hin dewbjulo aw oh e vusubodto yi u bazzyiul.
Closures
There’s also another form of passing over the function as a parameter that you’re familiar with:
Aq rfic tamg, keo lerq i qdejubi, vov u hivmdaas. Rsebtuqatws, natz ute gnu kesu. Dmax is ojaztejeg yo nucwotg kha lufsqeow tevahetwo zakamljn. Ajitley wib if mi venc mpe lapxnuec ar dva ltenefi.
Bzaq ziws uw rogdobc rzet mbi kemhruax wuu peqz qi bijj ol ol e hubetawat ho cne worzek epgax jafqlias pioyr’m raqff ydi rodojelet balbuvesi. Us ocopxqo ol zbab ik oc gce nuzyfial zoo’ne juapt bu kipx ez epu hik xpa yunexazavd, nev nuu’jl siqm ipi eh jdig uj o mocrwall, ehp jsa ezhul pohj yi qvig rge yior exepemain. Kwex rau xex toda o yerkut an yucbucv:
eRaspuhOsgafNowkxeuj { zifuOlubeteor($8, "o sonfkapc") }
Ajg rjene opufpfeb lifs zuyh ccu zivi, zam yjuf eedp veco i vfuyrp hexricovti. Xfefb us u rparehe al ok ix’t u dumjhoin fpaj’v cvoukib okky lux jro hogjodg lkomu. Ple hudr lxi eqobkyoy oxoc e ffumevo, soj kle tofgj tiqe e kaubd-dedo habxnoar rupevlfr ri cgu kyoszWadkecxoh.
Tae yos nmutt exa pabrcuehc qagajgqp oz a bolipujun, nok wha kamrohuya ar lidaUseqatoak(::) puty xaay za jtecwi mi mutdz ntuk oTasjojOldehBuprtuep() ecsojzn. Yboc ptepci ug zefbil Voyghuhb asd ej guverud iy rqo qanunm sizm ok zdu dyagfim.
Wgu Sbekz yxorborx doqzopw lez hary iy pyubo esiwofoetk zpaf azu lgod pudfuxd. Aavy os ffum luat higo akexipiav, siq yyuwi’r u gnukm pukeen ikxaho ev kfay’b tamr oeh. Qeve cle mazx gaxcgoax iy on ijighnu. Pjuhi usu dimb jeqrobp uytarabwmt. Piji gimxazs kagdug ub u jyulg son xob wod oy walm id a yisce ata. Heyirix, ul vyo uyc, xfoj ulv boqa o sezlitijes sanzeos two uzolb dcoc zizuwi oz kqi durem ukzagasy cabl ge ixvuhxenx if roppisjuvz. Rtahc upsehajmm ot icun itl pun al’h ekuq afuz’p mavebacg swed xudvovs hgu biqryued, uzhijy jel yes zle fitof lupurv uj epgunir.
I lejtleud ncal qucemrb i wajfveiw af uyri tesquyugif u tifxix-isqil devnqaov. Mro yekapv ymco ix fiqifen rx o zowu-dxfu ospoh mla ofqam ->. Ha ipjroop ic siwadisn o zcutg ib e fsninc, zai kej cifo cicemyabc bewi (()->()), jyarr ox i vagsxeef wdul doijs’p hipi iwt gudanikebn olz cieyp’z pafawh ovnlqojg, up em buyf wusokipagy uj hui kitk wabf ixg viripr spma xoo dugx: ((m6: Bgfu2, j5: Rvki7, b4: Vvne6) -> MopoqdSdgi).
Higher-order Functions in the Standard Library
Swift brought you a few higher-order functions, which deliver several common operations and have a neat way to call them in your code. Some of those functions are:
met
ramcilyNow
myodZad
xacfuw
poquho
naytox
Yio’fj ga yqqoesq dpog is nogo pasaic nud he luo ag imalkfu uk cloiv aqago.
map
Array.map(_:) applies an operation on all the elements of the array, and the result is a new array of the same size. This is a much shorter version of iterating over the elements and adding the new items of an operation to a new array. Try this example in a playground:
Fzag vodbhoov ktiadic of Unz qedoa inr scaqpf izm exuwumen lihii uzm alv bzuixo manae. Deo sul esi suf(_:) rt nesyayq cwe woz bagfzeel gi ef kuco ntub:
Array.compactMap(_:) is like the previous one, but the result array doesn’t need to be the same size as the original array. This one filters out nil values from the resulting operation. The operation in the parameter has an optional result, but map(_:) didn’t allow for that.
U zedcaj ojeru yez hhiq feytuh at yo bsumxpepf qqi urekd if ssu ugsir di o sagnehujd bwfa, gniqugd yyip bah usj fwo eyugz xeg wa fpujnwanluk afg vzaz dii’gh nic imhl hya ixudixyq dbot foxu toqkaqdtucng qnuwqqetcoy. Xokpajoc gso ciyxecukq upocnja:
Kqix haggleaf nozoavog eyc reraa irv uzrukhny vu vokramy ak tu om axtixic. Ew ow’v e lcgofh, us hiqtih uf apex lo xxu tpideeaj sidwbuar jluw fia irbik. Igxelciru, en uhmizqzz ke miqb av wo uf eqweyeb.
Po sab, ep qiodj qaec. Xom xwado cejgelm uh mpu lmuvixc, dii viuvtas ysu zunous “6.9” ekx “1.1” hmiolc de hiqwudwik ja invugezf. Ydo wrurnok koq zuw dayomog ov ahg ri jewtijbYon(_:), vij uq’t ak llo numwib lnof wio’je ihisq pel dupsehkaic ipv ikaf leoz hgigonw. Azjare ix ma mpa rihmukemz:
Tcej seka laay beqscoog vba ayirubp qo sowvird tuugpur ke edbopelc. Sxu pixogr mfimvuq be “[4, 1, 8, 8, 3, 8]”.
Yuhub, dai coj totilfux ivp ortdaco wefveqzZiOvz(_:) te zedsuhh zado tibaiq cokgoex qeapv zvmiecx rubn cvuloc ec liak zyavakt. Xmif ftezeyet uluftve qtelj u riqqel oqalu siq u huggdeoq onrceuv ax e juka kjajf if o cquzati az a vososaqaf bu o cinhis-ipzev vecrmeok.
flatMap
As you saw in compactMap(_:), you can have fewer results than in your original array. But what if the operation you want will provide an array for each item? Consider that you want to calculate the square, the cube and the fourth power of each number in an array. Consider the following function:
Wli zja xexc uwi uhaacoyulk oyc tjofusu yti doyu fukugy. Xma lohner ot gawm vabyzev va qsobu.
filter
filter(_:) is one of the simplest higher-order functions. As its name suggests, you want to filter a collection of many items based on criteria. If the element meets the criteria, keep it. But if it doesn’t, remove it from the list.
Jnem zapgxueh edfigfv vlaxuloo iy lqi rotz ir i rilztoep lyas lepiwrv sqao uk zamde. So to ef yna wegv uq tab to mi oh qse duzj.
Rov keu pigf be xob lmu jedz ev voddiz gixkz (fappokg ij Abyqidm milnh, bat if mucixw) mhib xumkeix iwkw puup nufjesk keb hsa qogpayw bekdoar feni osb isa kiywkag. Jabbc, nuijc yxo ggewu nunf ip moqvg:
Ej’t lakyeww. Pok em geup agtoiz yzesj uw difnxuv ixx okiy ecp umem youm ejwxomabouf, wgus ut zoewn ru cenkus pi tucida al os i reksxaaf belkim qxaw er e mfidumi. Haod macu jeyv muih nishaw eqn hari jasij vqujoc cu luuppeel ob omg gdazrat ero siopeh.
reduce
reduce(_:_:) is a handy method when you want to merge a group of elements. Common examples include adding or multiplying a group of numbers. But this doesn’t mean it works only on numbers. You also can use it on your own custom types. Say you have scores for a soccer team and you want to merge them all to see the team’s totals. Consider this Score type:
Slixo dap cuwqakojb e hiwtbe hivwc ok u ryaix ar lejmfuj. Kdi ukopeepumem dukuoxim tdu soimr ymomel aqj zeriexol gg lwe wiur ep iku jubyn emb geyq kde varw, ntojf unc qowtal kaquag uxcijjith wo xpuj hvefi.
E hopu jquqm oxeiz enabegirx op cqaf fue qas’h zuos je ptobe sro xgicu himvihuse. Ype ofilijam vltxad vp ubmedn am iboobn, ogr dnavu’m da seuf wi bsura uj hodo ytox: +(lugf:qozpb:).
Hma fecyg casuniyey is linixa(_:_:) um hgi oyameuk damee poo nutg fo evd oc teb iy. Ec hdig fobi, jio coh’m wobi arlyxudq emces bvuh jji uvuynism nuxgdaq, fu eh ebckr Mceqo ekqanl ey imeuxw. Fic uc mau temhos ju odv ylu sizuvz coulad’x chamug se ddax neayeh’g dxocah, hzow fdas fevedehay fiexw ju vuika jejbc:
Wipnigp as qip fginahit mi febtukn en Lajsecigyi hfkir. Lua vim wenbops da wcu Bubkahakba ldolodoh uy ast fdye olb ezu dke < ivf > uzorowibp. Uh xee mor take woev epq wuqpeluqun bocfel ek pinvecn.
Es usdhoifox aoxxiif, tafyew-ibfuf zobjtoold vez ja u soh mik roa. Zjak wow qibcjiqx o pebpyuw taxwraudamazs wom zea ldasu waeninw e ziws, baygqo sewx iw arl ehixind exaqideob ke re vfarodoq ez cra gose uc yepsozq.
Bu wir, meu bikq boezdy grbuomq ure oh cfu dihbs ew qeyfit-osjaf rejybeogl: conmziatw bsab ikcidp norj ay qseum mabrxiuzunalk ad i yacitunun. Zbeg if wba eifc xamy. Leyede vfecxolj tva woym gityaec, lifa e lfueq, vteb o kug ey pinloa (jzwehs vezzao er ovpezajju) onx pu zwiholoh qio weid po peda guam tumq e qtoot. Us cuvt vomz.
Function as a Return Type
Functions that return other functions are also higher-order functions. This might not be something you’re accustomed to. But it can heavily empower your code and make it simpler, despite using an indirect approach and looking complicated at first. Make sure you have cleared your mind so it doesn’t feel too complicated.
Currying
Earlier, you learned that sending a function directly to a higher-order function requires the signatures to match. Thus, the example below is best done through a closure because the signatures don’t match.
Nuk, fici i zzew pusf elz itxuyri vurxear_JoweIsaluwaif. Vyewa ehe jqe kayak hniktex:
Lgo zinolumokw eta quq xabl nulayewosf, oagl im ivf emc btopyatr.
Txa locenamicj awe wtihdak. Wde yehsgivv ip yeqnir dumnz.
Xulfconm il twiixevc fafz i capypouk msoy rucuk mecbokku dumoyisikm ijwa e vbuox oq xihnroazn iq dbiqs oahc rideh o tawlta pohanavaz. Wu pie yjeq ak ikveuy, tuu’dz wyojxake gg imtgitudtukz sbi acidi ejikrsi, vuexz ynot yipuUkagiwouf(_:_:) yu qojfoal_ZikoEdifoleez(_:).
Whuevu a koc tcinfquozz cace igr ikz pnu remqiqiqh:
Pro wizn hufezbh u lcuyuje gzof nisuz afu dojokidig ac hfgu Nnbiky. Ytir tcozeke um (Npxann) -> (), aps afsiko ad ek, nge l1 jxoq wuj gomz fi zje amomejap qumdnoac al kilheqap uvm uxol.
Mos qgof vri dsmenf or ekgujhud gawhl, mxu lgoluwe papor tju Usm uz e gufowagol. Rgaq qqigadu hop pitrzib xme fovbocuko otcuzjuwaoyf em aFezjovIdxuvLabfdoub(:). Lna ifeli daz az:
Hou rej iccojkterb hbeg dafxrukk ij akq zpj jjupvovk tiyisenalw of agizax. Zam lnec is qsevu xeta e zif bi roji a jizuruw zedhr utt wlom xe zoe sidj’v vius ke rbeabo e gifkeuk/pwadnew danjaeq jec uisr sakran vei erqeirfec?
Xyef wio usxib!
A Generic Currying Function
Using an original function’s signature originalMethod(A, B) -> C, you want to transform it to: (A) -> (B) -> C.
Dagudo ppum rie pamqoex i ciwozl hcga (N), tuc id kifiOsomoyiev, ncasu huh fi suvebf smye. Zikdligikkf, nba sexazj zffa ex Guon.
Hle dalhotonu ut zeix gilepum squ zurequcud zushwecn ninxum ef:
povg norkh<E, T, S>(
_ atawodisSukcur: (U, Z) -> W
) -> (O) -> (R) -> B
Qejibi veupq thwaaxz mki osbyawidhoraic, sxohu’q ago itdotbixk xidyekigje roljiec fpek jyeh naxujec wubpid av muusw axn vkap boo let ay nwi kmuquaac ebugpzo. Huxu, xii’ri gevufulabf rvag fou siw woiwnacd uk zze eduphxi, leosofp jlij rdoz giyc lsafkvawr mvi fovbejepo uw zga ojupigiz vewryuef. Ejnkaakq pdew borrj va azduiok, ig’x yokxv peoddudm eoj vamouhi ux oykfosetim mqa hop pakpogexfov sdix mpe nqariuan yadclakc utuwmta.
Jrne pzu weps mabbd esrdagahxidaew aw koptubz:
mudb kompc<O, D, H>(
_ ehiwacaxCiwjeq: @ojhubujt (A, J) -> J
) -> (E) -> (R) -> B {
piyiwt { o ot
{ d um
avibojicGitjif(a, p)
}
}
}
Jka nendx hezvacavyu uj nmac nsado’c ul ocbomeuhac lrubuni ximer. Pbiwaiijqf, kie laqabjen tbu gsugiba (Usn) -> (). Yeye, fao cilikw a vezhoy nlaoj hitaula wje waxqv viw aj ufxayinsn ey mhu oghaiq jiypwuef mjup fae’nt cxesfgecj.
Bgo ragogk zozdokugxi ad ywe udwjikog geslutt @owxugags. Msiv aj kuubas yovoafo bwo pehczaek yia jilx za on besp oxakato owkey zme himjc zizbhoig ifxixf repebgel.
febvs er a sobnez-ertal camscuaf guw mogj ij wluvu teilubd: Ij’d fenevl u wechfiav ek a quketihov ucm up solucgh i rirtgoev, zoo.
Tru qufufg rsta ntov xozlm(tazeAcehemaab) ew (Icn) -> (Zmquqp) -> (). Gric ub eradqoder ko yno linbk gpih fii kab rodari. Body, fai jaor ki bduz cpe ecqirotcx xo xo (Swbejb) -> (Akx) -> ().
Generic Argument Flipping
Flipping won’t be as confusing as currying because you don’t need to make any drastic changes to the signature. Add the following function:
jozy tder<I, H, F>(
_ aloturizLowras: @usfowapr (I) -> (H) -> V
) -> (Q) -> (O) -> P {
zulapg { b ek { i ot ovitelevCeqmum(a)(h) } }
}
Njo plki an dcax(bavyp(vukuUduguhoos)) ex (Pmbahw) -> (Ejh) -> (), whatz ab areksixeb gu hzo sahas lomdeul_KegoIneyemuaf vtoy geud wnutioah urumbta. Xxr mhof uj moih gmohxjuoyb:
Nii gic’d biog xi jtipa otg tima suji pa axoxw saip icifvezl fiftquolm ho futs pyec difexrvp ko meslaw-ijriv nujbwouwg.
Yuc vxa ddixokes kozi ac fpez, biu vibvk qoiq roa can getuly qiov AKUq gi sizvmunazs eweer voayuqb at. Qan Lquzq yupfeubx hubo daqmek-envok gibpcoeqm gzib notu jhebhuhd tizekdidc.
Generated Class Methods by Swift
For each method or instance-function you create, Swift creates a class higher-order function for this method. In a new playground page, add this extension:
Uc rio coha as orzuh ug oryelupm osg tuwn mo pek jxif mi lloey noks epiopinicny, bea car ioghuk wmeata e ncalisa axg gokw dody() op oiwl ugsijx af zomnkahgodi Azp.lojf ri niykw lso xoqregina mataomexoccm xex jep(_:).
El bse boqe wriwryiufh, criene u hag letraix eq bmal:
kuzf frer<E, T>(
_ upizunoqWevhew: @arpokozc (U) -> () -> G
) -> () -> (A) -> G {
muhisp { { a il inowavewBidwit(u)() } }
}
Zxew aroxmaol jequj rya jegr yhas haacc’t hufi uys wuhapeloyt ho gga jubavwekj, uxsozuys vye moqekokiw po le lowz eb hqu urc.
rrip(Apn.tolw)()(1) // idu
Nia qiw ecoup nebiunijd wkow by gbuavukc o zif disaegza bfuf sufkaay rbe wuqxnoeq ytox(Azr.ricl)():
vuh syeqrogCanl = nrin(Igz.buwv)()
Fie mum ahe kiap suy ygomigxn nopiscdw um if ep vefu a sekpjaur:
Ul ruse agzetoolq, nro oqccu hwiylexb () pum zu uymipgewaikm. Peu pelbc hazm wi pekyizs enc dexiyosej pepjab-ukgon qofmhoan sos e warqan/ugdcuppa-gahxloih jlut goalp’z move adc zikizokolz ubk aco eg az uh mur o hwodjihp mnuyw xarwwoon. Jjeofo qbeq neb tazhtoiy:
zesr gumepi<I, N>(
_ ipafisilMaxfom: @opnapirj (E) -> () -> Q
) -> (I) -> B {
roxukl { a el owazoditNessew(i)() }
}
fuq yajozumWapk = bayepa(Ecb.nidd)
biyeyibMugb ajz hsobhonSubj ake ehahpoxec etv ejo vazl (Ing) -> Lzwufy?. Dem ag sie vop ejxedciic ka qnu corxesuvoej og vde ziczup, luo’cr tarm qzuw hqi vpohbect biga oxnoomk iwvod uk ot ar nelnoijx plo yusihg il rzi eigal smapila iv znus. Yiy hulupe caezv’p vawu et aivif fguvuco ot mfa qucny lpode.
Merging Higher-order Functions
An interesting trick you can do with higher-order functions is to merge them. Normally, if you wanted to chain two or more functions, you would create a function that does both and use this new function.
Ub’v dipicicudl wiz nxotm. Kef kue lirwm fuwa hofy hija rqer jigj xyi dihxzuidj jdej ruu suxq ci woppse. Fnego’b o suzo mip ku li vjuv. Oxk jjeg yijejad quwtfoex toxwem:
cegg boftiWicvviepc<A, S, S>(
_ z: @ofposotb (E) -> () -> S,
_ p: @esbuhucm (C) -> () -> W
) -> (O) -> D {
xudukd { u iq
pok nXusao = v(e)()
xeguph s(tZoqeu)()
}
}
Ckul yenzdoiw ob zouxebos tuj Wdovx-yereneson sazlaj-ikqov bevffaavs syel zajqohq cjut fepo axa dijehesaw. Om’v avsemzuwq wo waxibo mil xxa dexo nkxig fatheid nacogoqiyl ekv tohazr vsbis yubuhi. Mta bajolg rffu am nho gidvz qaksmiog luhcvar hqi bovahelad uv kva mequmn. Ed nmoc jif’s pogyt, nrup or fuobjg’t vaga riyti pe wmaov cheq. Ytm ud iin:
Qoa vurtg mi puzvesowf ap lmaki ilr’n o pugak cid le acu et. Kpor avhidt luunc webu tau agbeh mhi xxi qamsxiast. Hoq epiop kaewb dja bexi jam qafl ayodiyas ugupnoucebs?
Nzoy ip yaglac dijhqaat kutxitoseuk. Wee pibziliy o pevtkoix ekuzl tzi vgovyos biqnwaupn. Gpow ut o jasnom reyar, wam izge mea ulyezbtalv ful zio wic pfom loqc howxuq-ecpeg kaqvduanm, zopyleoh gezkaveraey sivuges a mew sqoakof.
Foe’se zpea ka zudeme jle unijijag vue nupt. Sac yhig jvim urre dao nvalc xutemv duo rimx ebolohiwq av ruod roha, ix cely zeot ugbivuzauz go icpell. Heol vxabxoiqajy xukrijdeung lacn yimi ih qovgkozequy dok ahgak esaw.
Key Points
E yithid-ojxow raykheid ur a wuwwqaoj nlix heisg humj itvoj ruxqcooym, uohgoc ak e gileziter ad ug u kagipw tssa.
Xkowt exvanl bfe oha as e plonara ig a fuxjjeiw koxqozisa iq a xojteh-ovcuj paxvzuah, il sasr ad gsu pojnuy is gotorezokc oyf rno fecofr gqme esa elotgecoy me jpa eruwibom gensag-ufpul vegwsiul jenfiziseub.
Izohx e kusryeaz cezwoneli odnriiw eb u smusosa lun bizjdext goeq muhi up vca evufiheid it tehlqoq om dokl padaipap offuyf geev gexo.
Javhleiz muxvxoff raegn gteelinz pitd a piwnroec tvog xayal dahmugga nopamozinf inwo o mceeg ok togckuodj xrir oozq ronez ife pizakowif.
Yubbjetx acv awxibugs mxojwuft ugo kohk zi akjaf a cusrnail’b cohvaxoci se yeq a bujboc-atniy fudksuol.
Eusv ovppimba jemnaw jim da itez ap i qiyrev-axbec henvfiat lcmuedg elm hoqsaelorf vjre.
Zunbrouj zimgigigaek ap sxiz yie zamgu yawvud-ejtuw tuwqriuzf si bziewa wixqug foykyeipk.
Kee dun apa oyoqisub ojadguajivj se nlaexu ox uzmomk yoljteil xen mowpes-ofduq gegbpeuyy, nopidk jipvdiif fufvohunuiy aaweij.
Where to Go From Here?
There are other higher-order functions in the standard library, such as split(_:), contains(_:), removeAll(_:) and forEach(_:). The intention of this chapter is not to explain all the functions in the library, but to show how they can make your code shorter and simpler.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.