0

Difference between map and takewhile?

So basically takewhile is the same as map but takes a predicate function (bool returning function) instead of a generic function. Am I saying right?

5th Jan 2019, 5:56 PM
Vincenzo Ciavolino
Vincenzo Ciavolino - avatar
3 Respostas
+ 7
map applies a function to every element of an iterable (for example a list). takewhile returns elements from an iterable and stops as soon as one element doesn't meet the condition. Here's an example: https://code.sololearn.com/c6ZYNt708vTS/?ref=app
5th Jan 2019, 6:06 PM
Anna
Anna - avatar
+ 6
So if you want to compare, compare with filter: filter filters up to the end, takewhile terminates at first miss.
5th Jan 2019, 6:12 PM
HonFu
HonFu - avatar
+ 2
Helo
17th Jan 2019, 1:08 PM
Мамура Саидаббасова