Тёмный

Dart Functions - The forEach() and map() functions in Dart. 

Johan Jurrius
Подписаться 10 тыс.
Просмотров 8 тыс.
50% 1

In this video we look at the forEach() method (iterate through a List using your own anonymous function) and the map() method (creating a new List from a previous List using your own anonymous function). Follow the full playlist here: • Introducing Flutter

Опубликовано:

 

10 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 14   
@ericberg2131
@ericberg2131 3 года назад
It would be nice if you could create a video on additional array methods such as; sort(), reduce(), fold(), every() ,where(), firstWhere(), singleWhere(), take(), skip(), List.from(), expand() Your videos and examples are the best.
@kennyho6222
@kennyho6222 3 года назад
Wow, I was having trouble with using forEach until I watched this video. Thanks!
@Jan123.
@Jan123. 3 года назад
Great video. Thanks a lot.
@bohdan8557
@bohdan8557 2 года назад
Great explanation!) Had an issue with .map()
@natia2216
@natia2216 2 года назад
Nice vid helped a lot
@heavenlife5619
@heavenlife5619 3 года назад
*1:19** why you don't put any DataType before the item variable ? In Anonymous function we have to declare any DataType like String item...??*
@JohanJurrius
@JohanJurrius 3 года назад
Dart automatically infers the data type. It knows that the list contains integers. So item will be of type int. Should show it when you hover over item.
@heavenlife5619
@heavenlife5619 3 года назад
​@@JohanJurrius ok but if I try to add some DataType then it is give error, I write list.forEach(int item) => print(item). then it is giving error. and can't I change the variable name in the print like list.forEach(int item) => print(MyItem) ?
@distributedchaos5129
@distributedchaos5129 2 года назад
@@heavenlife5619 You are missing extra set of parenthesis around (int item) => print(item), forEach takes in a function as an argument, here it is the anonymous function (int item) => print(item). Second, the 'item' is the variable you are passing on to the right side of your anon function. Sometimes you may pass two different items, (int i, int j) = i + j; Therefore variable name(s) on right side, where you are processing them, should match to the variable name(s) on the left side of anon function where you are passing them. final numbers = [1, 2, 6, 7]; numbers.forEach((int element) => print(element)); //works. Third, as sir has explained, dart does the inference automatically so that while coding we ourselves dont type wrong types down the stream as well as it reduces unnecessary typing which reduces time wasted on typing boilerplate code, and that time you can spend on optimising it, or writing new code.
@alinajfi7955
@alinajfi7955 Год назад
❤️
@xpwahab1
@xpwahab1 3 года назад
You said that iterables are collection of elemnts same as lists and sets. Means lists are iterables. Then why do we have to convert an iterable to a list? you said the new value we got from list.map is not a list but iterable and we can convert it to list (Arent list iterables?)
@JohanJurrius
@JohanJurrius 3 года назад
Let me know if this answers your question: stackoverflow.com/questions/52345694/dart-iterablee-vs-liste-always-use-iterable
@xpwahab1
@xpwahab1 3 года назад
@@JohanJurrius I guess i got it. list is a child class of iterable, like num has int and double, we can use num but its better to use int when we only need int. Also iterable is computed as needed.
@wiamwiam7318
@wiamwiam7318 2 года назад
How to avoid the frequency Ex : 20 : 3 30: 2 40 : 2 10 : 1 15 :1
Далее
Dart Classes - Basics of Classes in Dart
20:48
Просмотров 15 тыс.
▼ЮТУБ ВСЁ, Я НА ЗАВОД 🚧⛔
30:49
Просмотров 519 тыс.
Dart Map & List Explain in Detail
26:51
Просмотров 2,7 тыс.
Dart Collections - Sets
9:03
Просмотров 4,3 тыс.
Dart Collections - Lists
18:59
Просмотров 12 тыс.
Dart Basics - Looking at Dart Tools
10:39
Просмотров 9 тыс.
ForEach Method in Java
14:06
Просмотров 41 тыс.