Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

D: What difference between map and each?

Tags:

iteration

d

std.algorithm have two function for iteration map and each. I can't understand what is the difference?

like image 397
Suliman Avatar asked Dec 02 '22 17:12

Suliman


1 Answers

each performs an eager evaluation, while map performs a lazy one. This means that when you apply each, every element is calculated immediately, while map calculates its results only when you access them.

This also means that each is unsuitable for infinite streams.

like image 169
lodo Avatar answered Dec 23 '22 02:12

lodo