pub fn drop_right_while<T, F>(collection: &[T], predicate: F) -> Vec<T>Expand description
Removes elements from the end 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 end while the predicate holds true.
§Examples
use lowdash::drop_right_while;
let numbers = vec![1, 2, 3, 4, 5];
let result = drop_right_while(&numbers, |&x| x > 3);
assert_eq!(result, vec![1, 2, 3]);use lowdash::drop_right_while;
let letters = vec!['a', 'b', 'c', 'd', 'e'];
let result = drop_right_while(&letters, |&c| c != 'c');
assert_eq!(result, vec!['a', 'b', 'c']);