pub fn drop_while<T, F>(collection: &[T], predicate: F) -> Vec<T>Expand description
Removes elements from the beginning of a collection as long as a predicate returns true,
and returns the remaining elements. As soon as the predicate returns false, the function stops dropping elements.
Time Complexity: O(n), where n is the number of elements until the predicate returns false.
§Arguments
collection- A slice of items from which elements will be dropped.predicate- A function that takes an item and returnstrueorfalse.
§Type Parameters
T- The type of elements in the collection. Must implementClone.F- The type of the predicate function. Must implementFn(&T) -> bool.
§Returns
Vec<T>- A vector containing the elements after dropping from the beginning while the predicate holds true.
§Examples
use lowdash::drop_while;
let numbers = vec![1, 2, 3, 4, 5];
let result = drop_while(&numbers, |&x| x < 3);
assert_eq!(result, vec![3, 4, 5]);use lowdash::drop_while;
let letters = vec!['a', 'b', 'c', 'd'];
let result = drop_while(&letters, |&c| c < 'c');
assert_eq!(result, vec!['c', 'd']);