Soif I openthefunctionalOh, actually, Javafunctionalfolderinside, YouseethatwehaveonLeeDeepPalmfoulandthiscontainsthegroup I d alterfact I d andthentheactualversion.
SorighthereyoucanseethatfirstwehaveanentirelistandthenweloopthroughthatandthenwehaveanIVstatementandfinallywehave a finalfourlooploopingthroughfemalesandyoucanseethattherewas a lotoflogicnot, youknow, youknow, a substantialamountoflogic.
Butseethat, forexample, thisifstatementissomelogicandalsoyoucanseethatthisis a lotofcodeforsomethingverysimple.
Andthisiswhat I wantedtoshowyouabouttheimperativeapproach.
Next, let's goaheadandimplementthisusingthe D clarityofapproachandyouwillseethatit's muchneater.
Soif I putthiswholescreen, youcanseethatwehavetheexactsameoutput.
Butthe D clarityapproachismuchNita.
Soobviously, ifyouweretohavethisinto a lessrighthere, Sothisiswherecollectcomesintoplayandthen I canremovethislineandthiswithsemicolumnandanextrainterestto a variableandthensayfemalesandthentowrite.
AndyoucanseethatNow I'vegot a listrighthere, and I couldagainsimplysayfemalestuedotandthenforrichsystem, don't outcallingcolumnprintline.
Soif I runagain, youcanseethatthisistheexactsameoutput.
Sotherewegonow.
Youshouldhave a fullunderstandingoffthedifferencesbetweentheClarity's andimperativeapproach.
Sothispackagerightherecontains a bunchofffunctionalinterfaceisrighthere, yousee, byconsumerbyfunction, binaryoperatorbypredicatedbullyum, supplierconsumerandthelistgoesonsothey'reprettymuchidenticalaboutfromthetype.
SotheonesthatyouwillmostlikelybeusingourfunctionsbyefunctionsParettikidsbypredatorsandconsumersandalsothereis a byconsumer, but I'm But I'm gonnaexplainexactlyhoweverythingfitstogether, becauseonceyoulearnthosemainones, thentherestwillbeverysimple.
Sorighthereonlyshowyouthat.
Sowehave a predicated.
Sowhereistheprettygood?
Soletmefindcredited.
Sorighthereis a prettygoodLetmequicklyshowyou a credititandsurelythatweactuallyhaveused, youknow, predicatedbefore.
So a predatorrepresents a prettygoodbasically.
Thisprettyrepresents a predictedbullionvaluefunctionoffoneargument.
SoletmegobacktointelligenceandRayhere.
Rememberwherewehadthisdeclareiteveapproach.
Sorighthere.
Sothisfilter.
Sobasically, if I prettymuchextractthisinto a variable, youcanseethatthisis a predicated.
Andlookatthis.
Thispredicatedlookslikethis.
Sothepregnantaccepts a personandthenreturnstrueorfalse, basedoffthatperson I eatwhetherthepersoneaseofftypefemale, right?
Sonowif I goaheadandsimplysayincrementandthenzeroandthenendupwithSam a columnAndif I permitextractistooavailableAndfornow, let's goaheadandsimplysouththisincrementandletmeputthisfullscreen.
Sothisis a normalfunctioninJava, soThisiswhatyouareusedto.
Sothistakesaninputandthenreturnsonesingleup.
Oh, righthere.
Andthisisprettymuchtheequivalentrighthere.
Sorepresents a functionthatacceptsoneargumentandproduces a result.
Sothewaythatweconvertthisinto a functionrighthereisthefollowing.
Solet's goaheadandsimplysayfunction.
Andif I actuallydeletethissaunashowingsomethingsofunction, youcanseethatthisfunctiontakes a T rightso t andthenaresobasicallythesearethedatatypesofftheinputandtheoutput.
It's solet's saythatyouwanttodothefollowing, solet's saythatyouhave a functionso a normaltravelfunctionsostaticandthenthisreturn a bullion, andhere, let's simplygoaheadandsayisphonenumberviolet.
Solet's goaheadandsimplytake a phonenumbersostringandthenphonenumber.
Allright, goaheadandinsideofthefunctionalinterfacepackage, createclasscalledandthescoresupplierwith a publicstaticvoidmainmethod.
Solet's goaheadandlearnaboutwhat a supplieris.
Soif I gotothedogsrighthere, youcanseethattheysaysupplier T represents a supplieroffresults.
Sobasically, sometimesyoumighthave a methodrightherethatsimplylet's saythatwehave a methodlikethat.
So a methodlikethissostaticandthengetwatchLeeString, getconnection.
Youarewell, quitelistentoget d B connection.
Youroh, right.
Sothiswilltakenoargumentsand I simplyreturn.
Andthen, forexample, J.
D.
P c Colon, Foresight, sportsslashlocalhostandthen 5432 footslashLet's sayusers, right?
Sothisisnotreallybutyougettheidea.
Sothewaythatwecan, um, usesfunctionnowisif I simplysaysouthandthenget D B connectionorwell, andanywhereinthisyoucanseethatwegettheactualconnectioneuroforsomekindofdatabase.
Sothepurposeoffthisfunctionrighthere, it's simplytoreturn a valuerighthere.
Sothisisthevolatilereturns, sowecandosowecanuse a suppliertorepresenttheexactsamething.
Soif I putthisoninyourlinesoyoucanseeexactlywhat I'm doingandyoucanseethatnow, thisistheexactsamething.
Butif I goaheadandsayitwas a systemtheoutupinlinesosouthandrightheretousethis, I cansayget D B connectionyouroilsupplierdon't andthengetsonowif I runthis, I don't gettheexactsameresult.
Sothisisprettymuchhowyouuse a supplier.
So a suppliersimplyreturnsanykindofvaluethatyouwon, right?
Soifyouhaveanyquestionsonsuppliers, goaheadanddropme a message.
Otherwise, let's moveon.
Allright.
Sobynowyoushouldseeexactlythedifferencesbetweenwriting a normaljobfunctionandfunctionalinterfaceissothebenefitoffknowingthefunctionalinterfaceisiswhenyoustarttouseoptionalsandstreamsofmorespecificstreams.