Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
In the last section, we started talking about how we're going to use the built in function where that
belongs to every single list that we create to automatically walk through a list of cards and return
every card with some given suit.
So I'm going to flip back over to Dart Pad and we're going to start our implementation inside of the
cards with suit method that we added.
So inside of here, I'm going to reference the cards property that exists inside of every deck we create
and then on this cards list right here, I'm going to call the where method.
We're going to just write out the entire implementation of this method right here, and we'll talk a
little bit about how it works.
So inside of here, I'm going to place another set of parentheses and then I'll write out the word card.
Then outside those parentheses, I'll add a set of curly braces.
And then inside of there, I'll put return card, dot suit equals equals suit like so.
OK, so let's talk about what just happened here when we call cardstock, where we have to pass in a
function.
So that's what this is right here.
We defined a function without a name and we passed it in to the aware method.
The weird method then takes this function and it runs that function one time for every element within
the cards list.
So every single card within the cards list is taken and it's passed to this function as the first argument.
Then inside that function, you and I have to write some amount of logic that returns a boolean, if
we return a boolean value of true, then that value is retained.
Otherwise, if it if we return false, then it assumes that, no, we don't care about this element.
So we are looking for every card within our cards list that has some given suit.
So we looked at the card dot suit property and we said if this thing is equal to the string suit that
was passed in to our method here, then we want to keep that card around.
OK, so that's how this we're method right here works.
Now, the last thing we'll do is make sure that whatever gets returned from Card Square gets returned
from our cards with function as well.
And so to do so, we'll just add on the key word return right before it's.
OK, so let's now try testing this out inside of our main function, so I'll scroll up to the top and
let's take out our let's see the shuffle in.
What the heck?
And we'll print out the result of Dec dot cards with suit.
And notice how we now get this nice autocomplete here with a function that you and I added.
So we'll call this thing and I'm going to try to get every card with a suit of diamonds.
All right, so now I will run this code and we'll see what happens.
OK, just going to give it a minute, let's try it one more time here.
There we go, much better.
So I now get four of diamonds, five to three and Ace, so clearly we went through that list and we
pulled out every card with some given suit.
Now, one thing I want to point out here is that rather than the square brackets we had before, we
now have a set of parentheses.
So if you go back over to the documentation for that weird method, you'll notice that it says that
it returns a new lazy iterable.
So an iterable is something that is like a list, but not quite a list.
We're not going to make a big distinction between the two just yet, but this is a topic that will come
back to later in the course for right now.
I really just wanted to show you how to make use of the standard library and how to use some of the
built-In methods that exist on lists already.
OK, so it looks good, so let's take a quick pause right here and we'll come back in the next section.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.