Video: Qhov txawv ntawm MAP thiab flatMap yog dab tsi?
2024 Tus sau: Stanley Ellington | [email protected]. Kawg hloov kho: 2023-12-16 00:17
Ob leeg daim ntawv qhia () thiab flatMap () coj a daim ntawv qhia muaj nuj nqi uas yog siv rau txhua lub caij ntawm aStream, thiab rov qab kwj. Lub xwb txawv yog tias daim ntawv qhia muaj nuj nqi hauv cas ntawm flatMap () tsim ib tug kwj ntawm qhov tseem ceeb tshiab, whereasfor daim ntawv qhia () nws tsim ib tug nqi rau txhua inputelement.
Kuj paub, kev siv flatMap yog dab tsi?
flatMap () V/s map(): Nws tsis flatten tus kwj. Tab sis flatMap () yog kev sib xyaw ua ke ntawm daim ntawv qhia thiab kev ua haujlwm tiaj tus piv txwv li, nws siv afunction rau cov ntsiab lus thiab ua kom lawv. 2) map() yog siv rau transformation xwb, tab sis flatMap () yog siv rau ob qho tib si transformation thiab flattening.
Ib yam li ntawd, daim ntawv qhia tiaj tus yog dab tsi? tiaj tus - daim ntawv qhia . Daim ntawv qhia muaj nuj nqi tshaj acollection thiab flatten qhov tshwm sim los ntawm ib-theem. Nws yog ib qho uas xav tau daim ntawv qhia muaj nuj nqi ntawm ib daim ntawv teev cov tswv yim uas rov qab ntau tus nqi hauv ib daim ntawv teev npe, tab sis koj tsis xav kom cov zis tso rau hauv tib txoj kev raws li cov tswv yim. ruby… ["ob tug noog", "peb ntsuab peas"].
Tsis tas li ntawd, FlatMap kwj yog dab tsi?
Kawm siv kwj flatMap () txoj kev uas yog siv rau flatten a ntws ntawm collections rau a ntws cov khoom sib xyaw ua ke los ntawm tag nrho cov collections. Cov flatMap () kev ua haujlwm muaj txiaj ntsig ntawm kev siv ib-rau-ntau qhov kev hloov pauv rau cov ntsiab lus ntawm cov ntws , thiab ces flattening theresulting ntsiab rau hauv ib tug tshiab ntws.
Qhov sib txawv ntawm kev sau thiab kwj yog dab tsi?
A ntws tsis khaws cov ntaub ntawv. Kev ua haujlwm ntawm a ntws tsis hloov kho nws qhov chaw, tab sis tsuas yog tsim kev puas tsuaj. Kev sau muaj qhov loj me me, tab sis ntws tsis txhob. Zoo li Iterator, tshiab ntws yuav tsum tau generated torevisit tib lub ntsiab ntawm qhov chaw.
Pom zoo:
Dab tsi yog qhov txawv ntawm qhov ua tau zoo thiab cov khoom lag luam teb thiab cov ntsiab lus ntawm kev lag luam uas txhua qhov ua haujlwm zoo tshaj?
Lub tuam txhab muaj peev xwm ua kom tau raws li cov neeg siv khoom xav tau raws sijhawm yog hu ua Kev Ua Haujlwm Zoo, thaum ua haujlwm tau zoo yog lub tuam txhab muaj peev xwm xa khoom raws li tus neeg siv khoom xav tau nrog tsawg kawg ntawm cov khoom siv raw, kev ua haujlwm thiab tus nqi
Dab tsi yog qhov txawv ntawm qhov point thiab nonpoint qhov chaw ntawm dej paug?
Piv txwv li, cov dej tso tawm los ntawm cov chaw tsim khoom lag luam ntawm qee yam lossis cov chaw kho dej khib nyiab. Cov chaw uas tsis yog cov ntsiab lus suav nrog kev khiav tawm ntawm thaj av ua liaj ua teb uas tuaj yeem ntxuav cov chiv lossis lwm yam tshuaj rau hauv pas dej lossis dej ntws - qhov no yuav tshwm sim ntau txhiab square kilometers
Dab tsi yog qhov txawv ntawm qhov rov qab los ntawm peev thiab rov qab los ntawm peev?
Ua ntej, qee qhov kev txhais. Rov qab los ntawm peev ntsuas qhov rov qab uas qhov kev nqis peev ua rau cov neeg koom nrog peev. Rov qab los ntawm peev (thiab ntawm no Idiffer nrog qee cov ntsiab lus) yog thaum tus neeg ua lag luam tau txais ib feem ntawm nws cov peev txheej qub rov qab - suav nrog cov nyiaj tau los ntawm cov nyiaj tau los - los ntawm kev nqis peev
Dab tsi yog qhov txawv ntawm qhov cuam tshuam qhov (socket) thiab lub qhov (socket) pa?
Rau kuv qhov kev paub qhov sib txawv yog nqes mus rau cov khoom siv Qhov saum npoo-hardening ua rau muaj kev cuam tshuam cov qhov (socket) kom nqus tau qhov hloov pauv tam sim ntawd (aka 'kev cuam tshuam') zoo dua. Nrog rau kev cuam tshuam txaus txaus, lub qhov (socket) tsis tu ncua tuaj yeem tawm ntawm cov duab vim tias cov hlau siv muaj softer
Dab tsi yog qhov txawv ntawm qhov kev thov thiab qhov xav tau ntawm cov khoom hais tias mis nyuj?
Dab tsi yog qhov txawv ntawm qhov kev thov thiab qhov xav tau ntawm cov khoom, hais mis nyuj? Kev xav tau yog kev sib raug zoo ntawm ntau tus nqi thiab qhov xav tau ntawm cov nqi ntawd. Kev xav tau ntawm cov mis nyuj yog qhov kev sib raug zoo ntawm tus nqi sib txawv ntawm cov mis nyuj thiab qhov xav tau ntawm cov nqi ntawd