KEMBAR78
Dart function - Recursive functions | PDF
2/12/22, 1:16 PM Dart function - Recursive Functions
https://softwarezay.com/notes/396_dart-function-recursive-functions 1/14
DEVELOPER'SNOTE
Dartfunction-RecursiveFunctions
11Feb2022,22:34pm
Dart
Arecursivefunctionisafunctionthatcallsitself.Arecursivefunctionisusedforrepeatingcode.Ifthestateofthefunctiondoesnot
change,andithasnopresetexitconditionthatisreached,arecursivecallcanturnintoaninfiniteloop.
void forever() { 

forever(); 

}

forever()isindeedaninfiniteloop.HereisarecursivefunctionthatwillrepeatedlyaddoneStringto
anotherString. 
String addOn(String original, String additional, int times) { 

if (times <= 0) { // exit condition to end "recursive loop" 

return original; 

} 

return addOn(original + additional, additional, times - 1); 

// recursive call 

} 

Note
1
Dartfunction-FunctionsWithinFunctions

Functionscanbedefinedwithinotherfunctions.These,too,canbereferencedbyvariablesandpassedtoother
functions. 
void talkAbout(String toShout, shoutFunc) { 

	 print(shoutFunc(toShout)); 

} 



void main() {

String exclame(String toExclame) => toExclame + "!"; 



String manyTalk(String toMany) { 

String allTogether = "";

for (int i = 0; i < 10; i++) { 

allTogether = allTogether + toMany; 

// keep concatenating toMany onto the end of itself

}

return allTogether; 

} 

talkAbout("Hello", exclame);

talkAbout("TicToc", manyTalk);

talkAbout("Wow", (String s) => s.toUpperCase()); 

// a function with no title!?

} 

Theanonymousfunctioninthelastlineofmain()?That’sright,afunctionwithnotitletoidentifyitisknownasan
anonymousfunction.  Anonymousfunctionsareusefulinsituationswhereafunctiondoesnotneedtobecalledfrom
multiplepartsofaprogrambyitsidentifier,orwheretheysimplymakesensestylistically.  
2/12/22, 1:16 PM Dart function - Recursive Functions
https://softwarezay.com/notes/396_dart-function-recursive-functions 2/14
Forexample,perhapsafunctiontakesanotherfunctionasaparameter.Ifthefunctionthatisgoingtobepassedtoit
isparticularlysmall,itmaylookmore“clean”toimplementitasananonymousfunctionthantocreateaseparatefull-
fledgedfunction.WhentalkAbout()runsfromthiscall,theidentifiershoutFuncwillrefertothisanonymousfunction,
anditwillbecallablethroughshoutFunc(). 
Note
2 Dartfunction-NamedOptionalParameters

NamedOptionalParameters
Namedoptionalparametersareverysimilartopositionaloptionalparameters,buttheyaredefinedandcalled
differently.Whenafunctionwiththemiscalled,theordertheyaresuppliedwithdoesnotmatter.Theyaredefined
withcurlybraces{}andcolonstoseparatetheirnamefromtheirdefaultvalue.Likepositionaloptionalparameters,
commasseparatethem.Alsolikepositionaloptionalparameters,theydonotneedtohavedefaultvalues.Incases
whennamedoptionalparametersarenotsuppliedwithavalue,theywillalsohaveadefaultvalueofnull.
void repeat(String word, {int repetitions: 1, String exclamation: ""}) { 

for (int i = 0; i < repetitions; i++) { 

print(word + exclamation); // the + operator can concatenate strings

}

} 

void main() {

repeat("Dog"); // legal

repeat("Dog", repetitions: 2, exclamation: "!"); // legal

repeat("Dog", repetitions: 2); // legal

repeat("Dog", exclamation: "!"); // legal, even without repetitions repeat("Dog",
exclamation: "!", repetitions: 2); // legal, even out of order 

} 

Namedoptionalparametersarealsoslightlymoreflexible,becauseoftheirindifferencetowardorder. 
Note
3 Dartfunction-PositionalOptionalParameters

PositionalOptionalParameters
Positionaloptionalparametersaredefinedwithsquarebracketswithinafunctiondefinition.
Forexample,thefollowingfunctionrepeat()hasanoptionalparametercalledrepetitions.
2/12/22, 1:16 PM Dart function - Recursive Functions
https://softwarezay.com/notes/396_dart-function-recursive-functions 3/14
void repeat(String word, [int repetitions]) { // repetitions is optional 


if (repetitions != null) { // check if repetitions was supplied 

for (int i = 0; i < repetitions; i++) { 

print(word); 

}

} else { // repetitions was not supplied, so just print once 

print(word);

}

} 

The!=operatorisusedheretocheckwhethertheoptionalparameterrepetitionswassupplied.
Ifanoptionalparameterisnotsuppliedavalue,anditdoesnothaveadefaultvalue,thenitwillhavethevaluenull.In
thecaseofrepeat(),itwillprintwordrepetitionstimes,ifrepetitionsissupplied.Ifrepetitionsisnotsupplied,itwill
printwordjustonetime.Thisfunctioncanbesimplifiedbyusingadefaultvalueforrepetitions.
void repeat(String word, [int repetitions = 1]) { 

for (int i = 0; i < repetitions; i++) { 

print(word);

}

} 

The=operatorisusedwithinthesquarebracketstosetthedefaultvalueofanoptionalpositionalparameter.
Commasseparatemultipleoptionalpositionalparameters.Whenafunctionwithoptionalpositionalparametersis
called,itsoptionalparametersmustbesuppliedinthesameorderthattheyaredefined. 
void repeat(String word, [int repetitions = 1, String exclamation = ""]) { for (int i = 0; i
< repetitions; i++) { 

print(word + exclamation); // the + operator can concatenate strings

}

}

void main() { 

repeat("Dog"); // legal

repeat("Dog", 2, "!"); // legal

repeat("Dog", 2); // legal

repeat("Dog", "!"); // ILLEGAL

repeat("Dog", "!", 2); // ILLEGAL




} 

Bothoptionalparametersdonotneedtobesupplied,butwhetheroneortwoissupplied,theymustbesuppliedinthe
rightorder. 
Note
4 Dartfunction-Single-LineFunctions

Single-LineFunctions
Darthassyntacticsugarthatmakesitpossibletodeclareshortfunctionsmorecompactly.
2/12/22, 1:16 PM Dart function - Recursive Functions
https://softwarezay.com/notes/396_dart-function-recursive-functions 4/14
Thesyntax=>isusedforseparatingthereturntype,name,andparametersofasingle-linefunctionfromits
implementation.
Aswithregularfunctions,specifyingthereturntypeofasingle-linefunctionisoptional.Single-linefunctionsdonot
usereturnstatements.
Instead,thereturnvalueisimplied.Theevaluatedresultoftheexpressionontherightofthe=>isthereturnvalue.
Thefollowingareexamplesofsomefunctionswesawearlierinthechapter,implementedassingle-linefunctions:
sayHello(String name) => print("Hello, $name"); // just as valid as next version

void sayHello(String name) => print("Hello, $name"); // same as previous but with void

int multiply(int num1, int num2) => num1 * num2; // think of as return num1 * num 2;

int luckyNumber() => 7; // return is implied

Single-linefunctionsarenotinherentlyanymoreorlessusefulthantheirlongercounterparts.
Theyaresimplyanotherwayofdefiningthesamething.Theyaresuppliedbythelanguageforconvenience. 
Note
5 Dartfunction-FunctionReturnValues

FunctionReturnValues
Notonlycanfunctionsreceiveinformationbywayofparameters,theycanalsoreturninformationtotheircallerby
wayofareturnvalue.Thereturnvalueisprecededbythekeywordreturn.Thetypeofthereturnvaluecanbe
indicatedbeforethenameofthefunction.Forexample,perhapsafunctionmultiply()returnstheproductoftwo
numbers. 
int multiply(int num1, int num2) { 

int product = num1 * num2; return product; 

} 

Webetterlookatanexamplewithmultiply().
main() {

int result = multiply(5, 5); // result will be equal to 25, the product returned by
multiply

print("2 multipled by 2 is ${multiply(2, 2)}"); // 4 is inserted for multiply(2, 2)

} 

Ifnoreturntypeisspecifiedinthedefinitionofthefunction,thenitcaneitherreturnanythingorreturnnothing.
Thatsoundsveryambiguous.Itisgoodpracticetospecifyareturntypewhenafunctionwillreturnavalue.
2/12/22, 1:16 PM Dart function - Recursive Functions
https://softwarezay.com/notes/396_dart-function-recursive-functions 5/14
multiply(int num1, int num2) { // VALID code, but wouldn't it be less ambiguous to specify
int? 

int product = num1 * num2;

return product; 

} 

afunctionneednothaveanyreturntypeatall.Inthatcase,thefunction’sreturntypecansimplybeleftblank.
Alternatively,itcanbespecifiedexplicitlythatafunctiondoesnotreturnavaluewiththekeywordvoid.
void sayHello(String name) { // void specifies this function does not return a value 

print("Hello, $name!"); 

} 

Ifavoidfunctiondidreturnavalue,thatwouldbeanerror.Whyisthekeywordvoidusefulifitisneverrequired?
Perhaps,liketypesinthemselves,itisahelpfulsanitycheckbothfortheprogrammerandthecompiler.Inother
words,ifweknowwedon’twantafunctiontoreturnavalue,andwedeclareitvoid,itisgoodthatwelatergetanerror
whenweforgetitisvoidandaccidentallytrytoreturnavalue. 
Whenafunctionreachesareturnstatement,itwillimmediatelyexit.Nocodeinthefunctionwillbeexecutedaftera
returnstatementisexecuted.
int luckyNumber() {

return 7; // function exits here

print("I'm thinking of a number..."); // DEAD CODE, never executed 

} 

Thiscanbeusefulwhenafunctionshouldexitpriortosomelargeoperationtakingplace.  
Forexample,perhapsafunctionalreadyhasenoughinformationtoproduceitsreturnvalue,soitdoesnotneedto
keepexecutingalongloop.Itcanalsobeconfusingifafunctionhastoomanydifferentpossiblepointsofexit,andit
cannoteasilybedeterminedwhichonewillbefollowed.Inotherwords,usereturnstatementswhentheymakesense,
butnotexcessively. 
Note
6 Dartfunction-MultipleParameters

Functionsneednotbelimitedtozerooroneparameter.Theycancontainanynumberofparameters.Ourbeep()
function,mayneedtoknowwhichsoundtoplay.Anotherparametercanprovidethatinformation.
beep(int milliseconds, String soundName) {...} //... is used here to represent more code
2/12/22, 1:16 PM Dart function - Recursive Functions
https://softwarezay.com/notes/396_dart-function-recursive-functions 6/14
Commasseparatemultiplefunctionparameters.Ingeneral,itshouldbeagoaltomakeafunctionasself-sufficientas
possible.Inotherwords,top-levelvariablesaregenerallyfrowneduponwhentheyareusedinsituationswherethe
designcouldbebetterservedbyfunctionparameters.Takealookatthefollowingprogramandtrytoimaginehowthe
top-levelvariablenumberOfPrintscouldbeeliminatedinfavorofafunctionparameter.
int numberOfPrints = 0;

printMany(String forPrinting) {

for (int i = 0; i < numberOfPrints; i++) { 

print(forPrinting);

}

} 



main() {

numberOfPrints = 10;

printMany("I will not overuse top-level variables.");

} 

Youshouldtakenotethatthefor-loopinprintMany()willexecutenumberOfPrintstimes.
Thisdesignmayseemsimpleenoughforasmallprogramofafewlinesofcode.Inamorecomplexprogram,things
willquicklybecomeunwieldywhentop-levelvariablesareusedinappropriately.WhatifnumberOfPrintsischangedby
anotherfunctionwhenwedonotexpectittobe?Iftherewere20top-levelvariables,woulditnotbehardtokeep
trackofwhicharebeingusedwhere?Hereisabetter,cleaner,morecompactversionofthesameprogram:
printMany(String forPrinting, int numberOfPrints) { 

for (int i = 0; i < numberOfPrints; i++) { 

print(forPrinting);

}

} 

main() {

printMany("I will not overuse top-level variables.", 10);

} 

Doyouseewhythisismorelogical?numberOfPrintsisdeclaredasaparameterofprintMany(),sinceitwillbe
accessedexclusivelyinprintMany().Thegoalistoassociateavariableascloselyaspossiblewiththeplaceinthe
programwhereitisutilized. 
Note
7 Dartfunction-TheLocalityofVariables

TheLocalityofVariables 
2/12/22, 1:16 PM Dart function - Recursive Functions
https://softwarezay.com/notes/396_dart-function-recursive-functions 7/14
someFunction() {

String name = "Thomas";

}



main() { 

print(name); // ERROR, name does not exist in this context
}

TheLocalityofVariables
Functionparametersbecomevariableswithinafunction.Variableswithinafunctionareatypeoflocalvariables.Local
variableshaveascopethatislimitedtotheblockofcodewithinwhichtheyaredefined.Thismeanstheycanonlybe
accessedfromwithinthatblock.
Forexample,thevariableswehavebeendefininginthemain()functioncannotbeaccessedinanotherfunction.
Similarly,inthefollowingcodesnippet,thevariablenamecannotbeaccessedinmain():
someFunction() {

String name = "Thomas";

}



main() { 

print(name); // ERROR, name does not exist in this context
}

Variablescanalsobelocaltoblocksofcodethatarewithinfunctions.Avariablemaybelocaltoafor-loop,for
example,andnotaccessibleoutsideofit.Or,itcouldbelocaltoanif-statement,switch-statement,etc.Hereisamore
complexexamplethatillustrateslocalityfurther:
Variablescanalsobedeclaredoutsideoffunctions.Inthecasewheretheyare,theyarenolongerlocalvariables.A
variabledeclaredattheso-calledtoplevelofaDartsourcefileisaccessibleanywherewithinit.Forexample,the
followingprogramiscompletelylegal.Youwillnoticethatname2isusedinmain(),whichisdeclaredbeforename2.
main() {

for (int i = 0; i < 10; i++) { 

bool dog = true; 

if (dog) {

int howMany = 100; 

} 

if (howMany == 100) { // ERROR, howMany is only accessible within the if-statement above 


dog = false; 

} 

print("howMany is $howMany"); // ERROR, howMany is not accessible here either

}

if (dog) { // ERROR dog is not accessible here, since it is local to the for-loop 


print("dog is true"); 

} 

dog = true; // ERROR dog is not accessible here either 

}
2/12/22, 1:16 PM Dart function - Recursive Functions
https://softwarezay.com/notes/396_dart-function-recursive-functions 8/14
String name1 = "Tom";

sayHello(String name) {

print("Hello, $name!");

} 

main() {

sayHello(name1);

sayHello(name2);

}

String name2 = "John";

Note
8 Dartbasic-Function

Functions
Functionsletyoupackagemultiplerelatedlinesofcodeintoasinglebody.Youthensummonthefunctiontoavoid
repeatingthoselinesofcodethroughoutyourDartapp.
Afunctionconsistsofthefollowingelements:
Returntype
Functionname
Parameterlistinparentheses
Functionbodyenclosedinbrackets
DefiningFunctions
Thecodeyou’returningintoafunctiongoesinsidethecurlybrackets.Whenyoucallthefunction,youpass
in arguments thatmatchthetypesoftheparametersofthefunction.
Next,you’llwriteanewfunctioninDartPadthatwillchecktoseeifagivenstringis banana:
bool isBanana(String fruit) {

return fruit == 'banana';

}

Thefunctionuses return toreturna bool.Theargumentyoupasstothefunctiondeterminesthe bool.
Thisfunctionwillalwaysreturnthesamevaluetypeforanygiveninput.Ifafunctiondoesn’tneedtoreturnavalue,
youcansetthereturntypeto void. main doesthis,forexample.
WorkingWithFunctions
Youcancallthefunctionbypassinginastring.Youmightthenpasstheresultofthatcallto print:
void main() {

var fruit = 'apple';

print(isBanana(fruit)); // false

}
2/12/22, 1:16 PM Dart function - Recursive Functions
https://softwarezay.com/notes/396_dart-function-recursive-functions 9/14
NestingFunctions
Typically,youdefinefunctionseitheroutsideotherfunctionsorinsideDartclasses.However,youcanalsonestDart
functions.Forexample,youcannest isBanana inside main.
void main() {

bool isBanana(String fruit) {

return fruit == 'banana';
}



var fruit = 'apple';

print(isBanana(fruit)); // false

}

Youcanalsochangetheargumentyoutoafunction,thencallitagainwiththenewargument:
fruit = 'banana';

print(isBanana(fruit)); // true

Theresultofcallingthefunctiondependsentirelyontheargumentsyoupassin.
OptionalParameters
Ifaparametertoafunctionisoptional,youcansurrounditwithsquarebracketsandmakethetypenullable:
String fullName(String first, String last, [String? title]) {

if (title == null) {

return '$first $last';

} else {

return '$title $first $last';

}

}

Inthisfunction, title isoptional.Itwilldefaultto null ifyoudon’tspecifyit.
Now,youcancallthefunctionwithorwithouttheoptionalparameter:
print(fullName('Joe', 'Howard'));

// Joe Howard



print(fullName('Albert', 'Einstein', 'Professor'));

// Professor Albert Einstein

NamedParametersandDefaultValues
Whenyouhavemultipleparameters,itcanbeconfusingtorememberwhichiswhich.Dartsolvesthisproblem
with namedparameters,whichyougetbysurroundingtheparameterlistwithcurlybrackets: { }.
Theseparametersareoptionalbydefault,butyoucangivethemdefaultvaluesormakethemrequiredbyusingthe 
required keyword:
bool withinTolerance({required int value, int min = 0, int max = 10}) {

return min <= value && value <= max;

}

value isrequired,while min and max areoptionalwithdefaultvalues.
Withnamedparameters,youcanpassinargumentsinadifferentorderbysupplyingtheparameternameswitha
colon:
print(withinTolerance(min: 1, max: 5, value: 11)); // false
2/12/22, 1:16 PM Dart function - Recursive Functions
https://softwarezay.com/notes/396_dart-function-recursive-functions 10/14
Youcanleaveofftheparameterswithdefaultvalueswhencallingthefunction.
print(withinTolerance(value: 5)); // true

AnonymousFunctions
Dartsupports first-classfunctions,meaningthatittreatsfunctionslikeanyotherdatatype.Youcanassignthemto
variables,passthemasargumentsandreturnthemfromotherfunctions.
Topassthesefunctionsaroundasvalues,omitthefunctionnameandreturntype.Sincethere’snoname,thistypeof
functioniscalledan anonymousfunction.
Youcanassignananonymousfunctiontoavariablenamed onPressed,likeso:
final onPressed = () {

print('button pressed');

};

onPressed hasavalueoftype Function.Theemptyparenthesesindicatethefunctionhasnoparameters.Likeregular
functions,thecodeinsidethecurlybracketsisthefunctionbody.
Toexecutethecodewithinthefunctionbody,callthevariablenameasifitwerethenameofthefunction:
onPressed(); // button pressed

Youcansimplifyfunctionswhosebodyonlycontainsasinglelinebyusing arrowsyntax.Todothis,removethecurly
bracketsandaddafatarrow =>.
Here’sacomparisonoftheanonymousfunctionaboveandarefactoredversion:
// original anonymous function

final onPressed = () {

print('button pressed');

};



// refactored

final onPressed = () => print('button pressed');

That’smuchnicertoread.
UsingAnonymousFunctions
You’lloftenseeanonymousfunctionsinFlutter,likethoseabove,passedaroundascallbacksforUIevents.Thislets
youspecifythecodethatrunswhenauserdoessomething,likepressingabutton.
Anothercommonplacewhereyou’llseeanonymousfunctionsiswithcollections.Youcangiveacollectionan
anonymousfunctionthatwillperformsometaskoneachelementofthecollection.Forexample:
2/12/22, 1:16 PM Dart function - Recursive Functions
https://softwarezay.com/notes/396_dart-function-recursive-functions 11/14
Comments
Thereisnocomment.
Addcomment
// 1

final drinks = ['water', 'juice', 'milk'];

// 2

final bigDrinks = drinks.map(

// 3

(drink) => drink.toUpperCase()

);

// 4

print(bigDrinks); // (WATER, JUICE, MILK)

Let’slookateachstep:
1.Definealistof drinks thathavelowercaseletters.
2..map takesallthelistvaluesandreturnsanewcollectionwiththem.
3.Ananonymousfunctionispassedasaparameter.Inthatanonymousfunction,youhavea drink argumentthat
representseachelementofthelist.
4.Thebodyoftheanonymousfunctionconvertseachelementtouppercaseandreturnsthevalue.Sincetheoriginal
listisalistofstrings, drink alsohastype String.
Usingananonymousfunctionandcombiningitwith .map isaconvenientwaytotransformonecollectionintoanother.
Note:Don’tconfusethe .map methodwiththe Map type.
source:raywenderlich.com
Be the first of your friends to like this.
Like Share
Login&Comment
Dartfunction-FunctionsWithinFunctions
11Feb2022,22:26pm
Dartfunction-NamedOptionalParameters
11Feb2022,22:18pm
Dartfunction-PositionalOptionalParameters
11Feb2022,22:07pm
2/12/22, 1:16 PM Dart function - Recursive Functions
https://softwarezay.com/notes/396_dart-function-recursive-functions 12/14
Dartfunction-Single-LineFunctions
11Feb2022,22:00pm
Dartfunction-FunctionReturnValues
11Feb2022,21:50pm
Dartfunction-MultipleParameters
11Feb2022,21:45pm
Dartfunction-TheLocalityofVariables
11Feb2022,21:37pm
Flutter-CreatingaFlutterplatformclient
11Feb2022,21:16pm
DartMap/Object-returnsacopyoftheprovidedmap-dartMap.from()
09Feb2022,23:46pm
DartMap/Object-Updatesthevalueforthegivenkey-dartupdate()
09Feb2022,23:43pm
DartMap/Object-Removeseverykey/valuepairinthemap-dartclear()
09Feb2022,23:40pm
DartMap/Object-Removesthekey/valuepairifthegivenconditionistrue-dartremoveWhere()
09Feb2022,23:38pm
DartMap/Object-Removestheprovidedkeyanditsassociatedvalue-dartremove()
09Feb2022,23:37pm
DartMap/Object-Addsakey/valuepairifnon-existent-dartputIfAbsent()
09Feb2022,23:36pm
DartMap/Object-Runsthegivenfunctionovereachkey/valuepair-dartforEach()
09Feb2022,23:33pm
DartMap/Object-Checkswhetherthegivenvalueexists-dartcontainsValue()
09Feb2022,23:31pm
DartMap/Object-Checkswhetherthegivenkeyexists-dartcontainKey()
09Feb2022,23:29pm
DartMap/Object-tomergeallkey/valuepairsoftheprovidedmaptothecurrentone-addAll()
09Feb2022,23:25pm
Dartarray-Expandseachelementintozeroormoreelements
09Feb2022,23:21pm
Dartarray-Createsanewlistfromthegivencollection
09Feb2022,23:19pm
Dartarray-Returnsacollectionwhileincludingorskippingelements-take()-skip()
09Feb2022,23:17pm
Dartarray-where(),firstWhere(),singleWhere()
09Feb2022,23:15pm
Dartarray-every()
09Feb2022,23:12pm
Dartarray-Compressestheelementstoasinglevalue
09Feb2022,23:04pm
Dartarray-Ordertheelementsbasedontheprovidedorderingfunction
09Feb2022,23:03pm
Dartarray-Checkstoconfirmthatthegivenelementisinthelist
09Feb2022,23:01pm
Dartarray-Producesanewlistaftertransformingeachelementinagivenlist
2/12/22, 1:16 PM Dart function - Recursive Functions
https://softwarezay.com/notes/396_dart-function-recursive-functions 13/14
09Feb2022,23:00pm
Dartarray-Runsafunctiononeachelementinthelist
09Feb2022,22:57pm
Dartstring-splitsthegivenstring,convertsitspartsperrequirement,andcombinesthemintoanewstring-dart
splitMapJoin
09Feb2022,21:17pm
Dartstring-tocompareoneinputwithotherandreturnsaninteger-dartcompareTo
09Feb2022,21:14pm
Dartstring-tomatchethepatternagainstthegivenstring-dartallMatches
09Feb2022,21:12pm
Dartstring-toreplacefirstfewcharactersfromagivenstring
09Feb2022,21:08pm
Dartstring-toreplacepartofgivenstringthatmatchesthepatternwithnewstring-dartreplaceAll
09Feb2022,21:06pm
Dartstring-tosplitgivenstringintosubstring-dartsplit
09Feb2022,21:04pm
Dartstring-returnsaboolwhenthestringmatchesthepattern-dartstartsWith
09Feb2022,21:01pm
Dartstring-tocapitalizethefirstletterofastring-substring
09Feb2022,20:58pm
Dartbasic-Function
09Feb2022,20:36pm
Dartbasic-Maps
09Feb2022,20:29pm
Dartbasic-Collection-list
09Feb2022,20:25pm
Dartbasic-Controlflow-ForLoops
09Feb2022,20:11pm
Dartbasic-Controlflow-WhileLoops
09Feb2022,20:04pm
Dartbasic-Controlflow-IfStatements
09Feb2022,19:56pm
Dartbasic-Nullability
09Feb2022,19:53pm
Dartbasic-Immutability
09Feb2022,19:51pm
Dartbasic-Strings
09Feb2022,19:48pm
Dartbasic-LogicalOperators
09Feb2022,19:45pm
Dartreturnsremainingiterablefromgivenlist-dartskip()
09Feb2022,19:41pm
Dartreturnsthecountprovidedfromgivenlist-darttake
09Feb2022,19:39pm
Dartreturnsabooleandependinguponwhetherallelementssatisfiestheconditionornotinthegivenlist-dartevery
09Feb2022,19:38pm
Dartreturnsabooleandependinguponwhetheranyelementsatisfiestheconditionornotinthegivenlist-dartany
2/12/22, 1:16 PM Dart function - Recursive Functions
https://softwarezay.com/notes/396_dart-function-recursive-functions 14/14
Copyright©
2022
.Allrightsreserved.
09Feb2022,19:34pm

Dart function - Recursive functions

  • 1.
    2/12/22, 1:16 PMDart function - Recursive Functions https://softwarezay.com/notes/396_dart-function-recursive-functions 1/14 DEVELOPER'SNOTE Dartfunction-RecursiveFunctions 11Feb2022,22:34pm Dart Arecursivefunctionisafunctionthatcallsitself.Arecursivefunctionisusedforrepeatingcode.Ifthestateofthefunctiondoesnot change,andithasnopresetexitconditionthatisreached,arecursivecallcanturnintoaninfiniteloop. void forever() { forever(); } forever()isindeedaninfiniteloop.HereisarecursivefunctionthatwillrepeatedlyaddoneStringto anotherString.  String addOn(String original, String additional, int times) { if (times <= 0) { // exit condition to end "recursive loop" return original; } return addOn(original + additional, additional, times - 1); // recursive call }  Note 1 Dartfunction-FunctionsWithinFunctions  Functionscanbedefinedwithinotherfunctions.These,too,canbereferencedbyvariablesandpassedtoother functions.  void talkAbout(String toShout, shoutFunc) { print(shoutFunc(toShout)); } void main() { String exclame(String toExclame) => toExclame + "!"; String manyTalk(String toMany) { String allTogether = ""; for (int i = 0; i < 10; i++) { allTogether = allTogether + toMany; // keep concatenating toMany onto the end of itself } return allTogether; } talkAbout("Hello", exclame); talkAbout("TicToc", manyTalk); talkAbout("Wow", (String s) => s.toUpperCase()); // a function with no title!? }  Theanonymousfunctioninthelastlineofmain()?That’sright,afunctionwithnotitletoidentifyitisknownasan anonymousfunction.  Anonymousfunctionsareusefulinsituationswhereafunctiondoesnotneedtobecalledfrom multiplepartsofaprogrambyitsidentifier,orwheretheysimplymakesensestylistically.  
  • 2.
    2/12/22, 1:16 PMDart function - Recursive Functions https://softwarezay.com/notes/396_dart-function-recursive-functions 2/14 Forexample,perhapsafunctiontakesanotherfunctionasaparameter.Ifthefunctionthatisgoingtobepassedtoit isparticularlysmall,itmaylookmore“clean”toimplementitasananonymousfunctionthantocreateaseparatefull- fledgedfunction.WhentalkAbout()runsfromthiscall,theidentifiershoutFuncwillrefertothisanonymousfunction, anditwillbecallablethroughshoutFunc().  Note 2 Dartfunction-NamedOptionalParameters  NamedOptionalParameters Namedoptionalparametersareverysimilartopositionaloptionalparameters,buttheyaredefinedandcalled differently.Whenafunctionwiththemiscalled,theordertheyaresuppliedwithdoesnotmatter.Theyaredefined withcurlybraces{}andcolonstoseparatetheirnamefromtheirdefaultvalue.Likepositionaloptionalparameters, commasseparatethem.Alsolikepositionaloptionalparameters,theydonotneedtohavedefaultvalues.Incases whennamedoptionalparametersarenotsuppliedwithavalue,theywillalsohaveadefaultvalueofnull. void repeat(String word, {int repetitions: 1, String exclamation: ""}) { for (int i = 0; i < repetitions; i++) { print(word + exclamation); // the + operator can concatenate strings } } void main() { repeat("Dog"); // legal repeat("Dog", repetitions: 2, exclamation: "!"); // legal repeat("Dog", repetitions: 2); // legal repeat("Dog", exclamation: "!"); // legal, even without repetitions repeat("Dog", exclamation: "!", repetitions: 2); // legal, even out of order }  Namedoptionalparametersarealsoslightlymoreflexible,becauseoftheirindifferencetowardorder.  Note 3 Dartfunction-PositionalOptionalParameters  PositionalOptionalParameters Positionaloptionalparametersaredefinedwithsquarebracketswithinafunctiondefinition. Forexample,thefollowingfunctionrepeat()hasanoptionalparametercalledrepetitions.
  • 3.
    2/12/22, 1:16 PMDart function - Recursive Functions https://softwarezay.com/notes/396_dart-function-recursive-functions 3/14 void repeat(String word, [int repetitions]) { // repetitions is optional  if (repetitions != null) { // check if repetitions was supplied for (int i = 0; i < repetitions; i++) { print(word); } } else { // repetitions was not supplied, so just print once print(word); } }  The!=operatorisusedheretocheckwhethertheoptionalparameterrepetitionswassupplied. Ifanoptionalparameterisnotsuppliedavalue,anditdoesnothaveadefaultvalue,thenitwillhavethevaluenull.In thecaseofrepeat(),itwillprintwordrepetitionstimes,ifrepetitionsissupplied.Ifrepetitionsisnotsupplied,itwill printwordjustonetime.Thisfunctioncanbesimplifiedbyusingadefaultvalueforrepetitions. void repeat(String word, [int repetitions = 1]) { for (int i = 0; i < repetitions; i++) { print(word); } }  The=operatorisusedwithinthesquarebracketstosetthedefaultvalueofanoptionalpositionalparameter. Commasseparatemultipleoptionalpositionalparameters.Whenafunctionwithoptionalpositionalparametersis called,itsoptionalparametersmustbesuppliedinthesameorderthattheyaredefined.  void repeat(String word, [int repetitions = 1, String exclamation = ""]) { for (int i = 0; i < repetitions; i++) { print(word + exclamation); // the + operator can concatenate strings } } void main() { repeat("Dog"); // legal repeat("Dog", 2, "!"); // legal repeat("Dog", 2); // legal repeat("Dog", "!"); // ILLEGAL repeat("Dog", "!", 2); // ILLEGAL  }  Bothoptionalparametersdonotneedtobesupplied,butwhetheroneortwoissupplied,theymustbesuppliedinthe rightorder.  Note 4 Dartfunction-Single-LineFunctions  Single-LineFunctions Darthassyntacticsugarthatmakesitpossibletodeclareshortfunctionsmorecompactly.
  • 4.
    2/12/22, 1:16 PMDart function - Recursive Functions https://softwarezay.com/notes/396_dart-function-recursive-functions 4/14 Thesyntax=>isusedforseparatingthereturntype,name,andparametersofasingle-linefunctionfromits implementation. Aswithregularfunctions,specifyingthereturntypeofasingle-linefunctionisoptional.Single-linefunctionsdonot usereturnstatements. Instead,thereturnvalueisimplied.Theevaluatedresultoftheexpressionontherightofthe=>isthereturnvalue. Thefollowingareexamplesofsomefunctionswesawearlierinthechapter,implementedassingle-linefunctions: sayHello(String name) => print("Hello, $name"); // just as valid as next version void sayHello(String name) => print("Hello, $name"); // same as previous but with void int multiply(int num1, int num2) => num1 * num2; // think of as return num1 * num 2; int luckyNumber() => 7; // return is implied Single-linefunctionsarenotinherentlyanymoreorlessusefulthantheirlongercounterparts. Theyaresimplyanotherwayofdefiningthesamething.Theyaresuppliedbythelanguageforconvenience.  Note 5 Dartfunction-FunctionReturnValues  FunctionReturnValues Notonlycanfunctionsreceiveinformationbywayofparameters,theycanalsoreturninformationtotheircallerby wayofareturnvalue.Thereturnvalueisprecededbythekeywordreturn.Thetypeofthereturnvaluecanbe indicatedbeforethenameofthefunction.Forexample,perhapsafunctionmultiply()returnstheproductoftwo numbers.  int multiply(int num1, int num2) { int product = num1 * num2; return product; } Webetterlookatanexamplewithmultiply(). main() { int result = multiply(5, 5); // result will be equal to 25, the product returned by multiply print("2 multipled by 2 is ${multiply(2, 2)}"); // 4 is inserted for multiply(2, 2) } Ifnoreturntypeisspecifiedinthedefinitionofthefunction,thenitcaneitherreturnanythingorreturnnothing. Thatsoundsveryambiguous.Itisgoodpracticetospecifyareturntypewhenafunctionwillreturnavalue.
  • 5.
    2/12/22, 1:16 PMDart function - Recursive Functions https://softwarezay.com/notes/396_dart-function-recursive-functions 5/14 multiply(int num1, int num2) { // VALID code, but wouldn't it be less ambiguous to specify int? int product = num1 * num2; return product; } afunctionneednothaveanyreturntypeatall.Inthatcase,thefunction’sreturntypecansimplybeleftblank. Alternatively,itcanbespecifiedexplicitlythatafunctiondoesnotreturnavaluewiththekeywordvoid. void sayHello(String name) { // void specifies this function does not return a value print("Hello, $name!"); } Ifavoidfunctiondidreturnavalue,thatwouldbeanerror.Whyisthekeywordvoidusefulifitisneverrequired? Perhaps,liketypesinthemselves,itisahelpfulsanitycheckbothfortheprogrammerandthecompiler.Inother words,ifweknowwedon’twantafunctiontoreturnavalue,andwedeclareitvoid,itisgoodthatwelatergetanerror whenweforgetitisvoidandaccidentallytrytoreturnavalue.  Whenafunctionreachesareturnstatement,itwillimmediatelyexit.Nocodeinthefunctionwillbeexecutedaftera returnstatementisexecuted. int luckyNumber() { return 7; // function exits here print("I'm thinking of a number..."); // DEAD CODE, never executed }  Thiscanbeusefulwhenafunctionshouldexitpriortosomelargeoperationtakingplace.   Forexample,perhapsafunctionalreadyhasenoughinformationtoproduceitsreturnvalue,soitdoesnotneedto keepexecutingalongloop.Itcanalsobeconfusingifafunctionhastoomanydifferentpossiblepointsofexit,andit cannoteasilybedeterminedwhichonewillbefollowed.Inotherwords,usereturnstatementswhentheymakesense, butnotexcessively.  Note 6 Dartfunction-MultipleParameters  Functionsneednotbelimitedtozerooroneparameter.Theycancontainanynumberofparameters.Ourbeep() function,mayneedtoknowwhichsoundtoplay.Anotherparametercanprovidethatinformation. beep(int milliseconds, String soundName) {...} //... is used here to represent more code
  • 6.
    2/12/22, 1:16 PMDart function - Recursive Functions https://softwarezay.com/notes/396_dart-function-recursive-functions 6/14 Commasseparatemultiplefunctionparameters.Ingeneral,itshouldbeagoaltomakeafunctionasself-sufficientas possible.Inotherwords,top-levelvariablesaregenerallyfrowneduponwhentheyareusedinsituationswherethe designcouldbebetterservedbyfunctionparameters.Takealookatthefollowingprogramandtrytoimaginehowthe top-levelvariablenumberOfPrintscouldbeeliminatedinfavorofafunctionparameter. int numberOfPrints = 0; printMany(String forPrinting) { for (int i = 0; i < numberOfPrints; i++) { print(forPrinting); } } main() { numberOfPrints = 10; printMany("I will not overuse top-level variables."); } Youshouldtakenotethatthefor-loopinprintMany()willexecutenumberOfPrintstimes. Thisdesignmayseemsimpleenoughforasmallprogramofafewlinesofcode.Inamorecomplexprogram,things willquicklybecomeunwieldywhentop-levelvariablesareusedinappropriately.WhatifnumberOfPrintsischangedby anotherfunctionwhenwedonotexpectittobe?Iftherewere20top-levelvariables,woulditnotbehardtokeep trackofwhicharebeingusedwhere?Hereisabetter,cleaner,morecompactversionofthesameprogram: printMany(String forPrinting, int numberOfPrints) { for (int i = 0; i < numberOfPrints; i++) { print(forPrinting); } } main() { printMany("I will not overuse top-level variables.", 10); } Doyouseewhythisismorelogical?numberOfPrintsisdeclaredasaparameterofprintMany(),sinceitwillbe accessedexclusivelyinprintMany().Thegoalistoassociateavariableascloselyaspossiblewiththeplaceinthe programwhereitisutilized.  Note 7 Dartfunction-TheLocalityofVariables  TheLocalityofVariables 
  • 7.
    2/12/22, 1:16 PMDart function - Recursive Functions https://softwarezay.com/notes/396_dart-function-recursive-functions 7/14 someFunction() { String name = "Thomas"; } main() { print(name); // ERROR, name does not exist in this context } TheLocalityofVariables Functionparametersbecomevariableswithinafunction.Variableswithinafunctionareatypeoflocalvariables.Local variableshaveascopethatislimitedtotheblockofcodewithinwhichtheyaredefined.Thismeanstheycanonlybe accessedfromwithinthatblock. Forexample,thevariableswehavebeendefininginthemain()functioncannotbeaccessedinanotherfunction. Similarly,inthefollowingcodesnippet,thevariablenamecannotbeaccessedinmain(): someFunction() { String name = "Thomas"; } main() { print(name); // ERROR, name does not exist in this context } Variablescanalsobelocaltoblocksofcodethatarewithinfunctions.Avariablemaybelocaltoafor-loop,for example,andnotaccessibleoutsideofit.Or,itcouldbelocaltoanif-statement,switch-statement,etc.Hereisamore complexexamplethatillustrateslocalityfurther: Variablescanalsobedeclaredoutsideoffunctions.Inthecasewheretheyare,theyarenolongerlocalvariables.A variabledeclaredattheso-calledtoplevelofaDartsourcefileisaccessibleanywherewithinit.Forexample,the followingprogramiscompletelylegal.Youwillnoticethatname2isusedinmain(),whichisdeclaredbeforename2. main() { for (int i = 0; i < 10; i++) { bool dog = true; if (dog) { int howMany = 100; } if (howMany == 100) { // ERROR, howMany is only accessible within the if-statement above  dog = false; } print("howMany is $howMany"); // ERROR, howMany is not accessible here either } if (dog) { // ERROR dog is not accessible here, since it is local to the for-loop  print("dog is true"); } dog = true; // ERROR dog is not accessible here either }
  • 8.
    2/12/22, 1:16 PMDart function - Recursive Functions https://softwarezay.com/notes/396_dart-function-recursive-functions 8/14 String name1 = "Tom"; sayHello(String name) { print("Hello, $name!"); } main() { sayHello(name1); sayHello(name2); } String name2 = "John"; Note 8 Dartbasic-Function  Functions Functionsletyoupackagemultiplerelatedlinesofcodeintoasinglebody.Youthensummonthefunctiontoavoid repeatingthoselinesofcodethroughoutyourDartapp. Afunctionconsistsofthefollowingelements: Returntype Functionname Parameterlistinparentheses Functionbodyenclosedinbrackets DefiningFunctions Thecodeyou’returningintoafunctiongoesinsidethecurlybrackets.Whenyoucallthefunction,youpass in arguments thatmatchthetypesoftheparametersofthefunction. Next,you’llwriteanewfunctioninDartPadthatwillchecktoseeifagivenstringis banana: bool isBanana(String fruit) { return fruit == 'banana'; } Thefunctionuses return toreturna bool.Theargumentyoupasstothefunctiondeterminesthe bool. Thisfunctionwillalwaysreturnthesamevaluetypeforanygiveninput.Ifafunctiondoesn’tneedtoreturnavalue, youcansetthereturntypeto void. main doesthis,forexample. WorkingWithFunctions Youcancallthefunctionbypassinginastring.Youmightthenpasstheresultofthatcallto print: void main() { var fruit = 'apple'; print(isBanana(fruit)); // false }
  • 9.
    2/12/22, 1:16 PMDart function - Recursive Functions https://softwarezay.com/notes/396_dart-function-recursive-functions 9/14 NestingFunctions Typically,youdefinefunctionseitheroutsideotherfunctionsorinsideDartclasses.However,youcanalsonestDart functions.Forexample,youcannest isBanana inside main. void main() { bool isBanana(String fruit) { return fruit == 'banana'; } var fruit = 'apple'; print(isBanana(fruit)); // false } Youcanalsochangetheargumentyoutoafunction,thencallitagainwiththenewargument: fruit = 'banana'; print(isBanana(fruit)); // true Theresultofcallingthefunctiondependsentirelyontheargumentsyoupassin. OptionalParameters Ifaparametertoafunctionisoptional,youcansurrounditwithsquarebracketsandmakethetypenullable: String fullName(String first, String last, [String? title]) { if (title == null) { return '$first $last'; } else { return '$title $first $last'; } } Inthisfunction, title isoptional.Itwilldefaultto null ifyoudon’tspecifyit. Now,youcancallthefunctionwithorwithouttheoptionalparameter: print(fullName('Joe', 'Howard')); // Joe Howard print(fullName('Albert', 'Einstein', 'Professor')); // Professor Albert Einstein NamedParametersandDefaultValues Whenyouhavemultipleparameters,itcanbeconfusingtorememberwhichiswhich.Dartsolvesthisproblem with namedparameters,whichyougetbysurroundingtheparameterlistwithcurlybrackets: { }. Theseparametersareoptionalbydefault,butyoucangivethemdefaultvaluesormakethemrequiredbyusingthe  required keyword: bool withinTolerance({required int value, int min = 0, int max = 10}) { return min <= value && value <= max; } value isrequired,while min and max areoptionalwithdefaultvalues. Withnamedparameters,youcanpassinargumentsinadifferentorderbysupplyingtheparameternameswitha colon: print(withinTolerance(min: 1, max: 5, value: 11)); // false
  • 10.
    2/12/22, 1:16 PMDart function - Recursive Functions https://softwarezay.com/notes/396_dart-function-recursive-functions 10/14 Youcanleaveofftheparameterswithdefaultvalueswhencallingthefunction. print(withinTolerance(value: 5)); // true AnonymousFunctions Dartsupports first-classfunctions,meaningthatittreatsfunctionslikeanyotherdatatype.Youcanassignthemto variables,passthemasargumentsandreturnthemfromotherfunctions. Topassthesefunctionsaroundasvalues,omitthefunctionnameandreturntype.Sincethere’snoname,thistypeof functioniscalledan anonymousfunction. Youcanassignananonymousfunctiontoavariablenamed onPressed,likeso: final onPressed = () { print('button pressed'); }; onPressed hasavalueoftype Function.Theemptyparenthesesindicatethefunctionhasnoparameters.Likeregular functions,thecodeinsidethecurlybracketsisthefunctionbody. Toexecutethecodewithinthefunctionbody,callthevariablenameasifitwerethenameofthefunction: onPressed(); // button pressed Youcansimplifyfunctionswhosebodyonlycontainsasinglelinebyusing arrowsyntax.Todothis,removethecurly bracketsandaddafatarrow =>. Here’sacomparisonoftheanonymousfunctionaboveandarefactoredversion: // original anonymous function final onPressed = () { print('button pressed'); }; // refactored final onPressed = () => print('button pressed'); That’smuchnicertoread. UsingAnonymousFunctions You’lloftenseeanonymousfunctionsinFlutter,likethoseabove,passedaroundascallbacksforUIevents.Thislets youspecifythecodethatrunswhenauserdoessomething,likepressingabutton. Anothercommonplacewhereyou’llseeanonymousfunctionsiswithcollections.Youcangiveacollectionan anonymousfunctionthatwillperformsometaskoneachelementofthecollection.Forexample:
  • 11.
    2/12/22, 1:16 PMDart function - Recursive Functions https://softwarezay.com/notes/396_dart-function-recursive-functions 11/14 Comments Thereisnocomment. Addcomment // 1 final drinks = ['water', 'juice', 'milk']; // 2 final bigDrinks = drinks.map( // 3 (drink) => drink.toUpperCase() ); // 4 print(bigDrinks); // (WATER, JUICE, MILK) Let’slookateachstep: 1.Definealistof drinks thathavelowercaseletters. 2..map takesallthelistvaluesandreturnsanewcollectionwiththem. 3.Ananonymousfunctionispassedasaparameter.Inthatanonymousfunction,youhavea drink argumentthat representseachelementofthelist. 4.Thebodyoftheanonymousfunctionconvertseachelementtouppercaseandreturnsthevalue.Sincetheoriginal listisalistofstrings, drink alsohastype String. Usingananonymousfunctionandcombiningitwith .map isaconvenientwaytotransformonecollectionintoanother. Note:Don’tconfusethe .map methodwiththe Map type. source:raywenderlich.com Be the first of your friends to like this. Like Share Login&Comment Dartfunction-FunctionsWithinFunctions 11Feb2022,22:26pm Dartfunction-NamedOptionalParameters 11Feb2022,22:18pm Dartfunction-PositionalOptionalParameters 11Feb2022,22:07pm
  • 12.
    2/12/22, 1:16 PMDart function - Recursive Functions https://softwarezay.com/notes/396_dart-function-recursive-functions 12/14 Dartfunction-Single-LineFunctions 11Feb2022,22:00pm Dartfunction-FunctionReturnValues 11Feb2022,21:50pm Dartfunction-MultipleParameters 11Feb2022,21:45pm Dartfunction-TheLocalityofVariables 11Feb2022,21:37pm Flutter-CreatingaFlutterplatformclient 11Feb2022,21:16pm DartMap/Object-returnsacopyoftheprovidedmap-dartMap.from() 09Feb2022,23:46pm DartMap/Object-Updatesthevalueforthegivenkey-dartupdate() 09Feb2022,23:43pm DartMap/Object-Removeseverykey/valuepairinthemap-dartclear() 09Feb2022,23:40pm DartMap/Object-Removesthekey/valuepairifthegivenconditionistrue-dartremoveWhere() 09Feb2022,23:38pm DartMap/Object-Removestheprovidedkeyanditsassociatedvalue-dartremove() 09Feb2022,23:37pm DartMap/Object-Addsakey/valuepairifnon-existent-dartputIfAbsent() 09Feb2022,23:36pm DartMap/Object-Runsthegivenfunctionovereachkey/valuepair-dartforEach() 09Feb2022,23:33pm DartMap/Object-Checkswhetherthegivenvalueexists-dartcontainsValue() 09Feb2022,23:31pm DartMap/Object-Checkswhetherthegivenkeyexists-dartcontainKey() 09Feb2022,23:29pm DartMap/Object-tomergeallkey/valuepairsoftheprovidedmaptothecurrentone-addAll() 09Feb2022,23:25pm Dartarray-Expandseachelementintozeroormoreelements 09Feb2022,23:21pm Dartarray-Createsanewlistfromthegivencollection 09Feb2022,23:19pm Dartarray-Returnsacollectionwhileincludingorskippingelements-take()-skip() 09Feb2022,23:17pm Dartarray-where(),firstWhere(),singleWhere() 09Feb2022,23:15pm Dartarray-every() 09Feb2022,23:12pm Dartarray-Compressestheelementstoasinglevalue 09Feb2022,23:04pm Dartarray-Ordertheelementsbasedontheprovidedorderingfunction 09Feb2022,23:03pm Dartarray-Checkstoconfirmthatthegivenelementisinthelist 09Feb2022,23:01pm Dartarray-Producesanewlistaftertransformingeachelementinagivenlist
  • 13.
    2/12/22, 1:16 PMDart function - Recursive Functions https://softwarezay.com/notes/396_dart-function-recursive-functions 13/14 09Feb2022,23:00pm Dartarray-Runsafunctiononeachelementinthelist 09Feb2022,22:57pm Dartstring-splitsthegivenstring,convertsitspartsperrequirement,andcombinesthemintoanewstring-dart splitMapJoin 09Feb2022,21:17pm Dartstring-tocompareoneinputwithotherandreturnsaninteger-dartcompareTo 09Feb2022,21:14pm Dartstring-tomatchethepatternagainstthegivenstring-dartallMatches 09Feb2022,21:12pm Dartstring-toreplacefirstfewcharactersfromagivenstring 09Feb2022,21:08pm Dartstring-toreplacepartofgivenstringthatmatchesthepatternwithnewstring-dartreplaceAll 09Feb2022,21:06pm Dartstring-tosplitgivenstringintosubstring-dartsplit 09Feb2022,21:04pm Dartstring-returnsaboolwhenthestringmatchesthepattern-dartstartsWith 09Feb2022,21:01pm Dartstring-tocapitalizethefirstletterofastring-substring 09Feb2022,20:58pm Dartbasic-Function 09Feb2022,20:36pm Dartbasic-Maps 09Feb2022,20:29pm Dartbasic-Collection-list 09Feb2022,20:25pm Dartbasic-Controlflow-ForLoops 09Feb2022,20:11pm Dartbasic-Controlflow-WhileLoops 09Feb2022,20:04pm Dartbasic-Controlflow-IfStatements 09Feb2022,19:56pm Dartbasic-Nullability 09Feb2022,19:53pm Dartbasic-Immutability 09Feb2022,19:51pm Dartbasic-Strings 09Feb2022,19:48pm Dartbasic-LogicalOperators 09Feb2022,19:45pm Dartreturnsremainingiterablefromgivenlist-dartskip() 09Feb2022,19:41pm Dartreturnsthecountprovidedfromgivenlist-darttake 09Feb2022,19:39pm Dartreturnsabooleandependinguponwhetherallelementssatisfiestheconditionornotinthegivenlist-dartevery 09Feb2022,19:38pm Dartreturnsabooleandependinguponwhetheranyelementsatisfiestheconditionornotinthegivenlist-dartany
  • 14.
    2/12/22, 1:16 PMDart function - Recursive Functions https://softwarezay.com/notes/396_dart-function-recursive-functions 14/14 Copyright© 2022 .Allrightsreserved. 09Feb2022,19:34pm