+ 4

What difference between filter and takewhile function?

26th Jul 2016, 5:21 AM
ŠŠ½Š²Š°Ń€ Š˜ŃŠ¼Š¾ŠøŠ»Š¾Š²
ŠŠ½Š²Š°Ń€ Š˜ŃŠ¼Š¾ŠøŠ»Š¾Š² - avatar
2 Answers
+ 17
filter will iterate through whole input iterator while takewhile will break once the predicate turn False, if you have an iterator with 1st element that false to predicate, takewhile will break at 1st iteration and return empty
25th Nov 2016, 4:02 PM
skycc
skycc - avatar
+ 6
filter: don't need import.Returns all the elements that satisfy the predicate. takeWhile: Returns the longest prefix whose elements satisfy the predicate.
26th Jul 2016, 5:35 PM
CĆ©sar Augusto Gaete
CĆ©sar Augusto Gaete - avatar