dropWhile<T> function
Creates a slice of list excluding elements dropped from the beginning.
Elements are dropped until predicate returns falsey.
- @param {List} list The list to query.
- @param {Function} predicate The function invoked per iteration.
- @returns {List} Returns the slice of
list.
@example
var users = [
{ 'user': 'barney', 'active': true },
{ 'user': 'fred', 'active': true },
{ 'user': 'pebbles', 'active': false }
];
dropWhile(users, (o) => o['active']);
// => objects for ['pebbles']
Implementation
List<T> dropWhile<T>(List<T> list, bool Function(T) predicate) {
int index = 0;
while (index < list.length) {
if (!predicate(list[index])) {
break;
}
index++;
}
return list.sublist(index);
}