Function leftwm_core::utils::helpers::relative_find
source · pub fn relative_find<T, F>(
list: &[T],
reference_finder: F,
shift: i32,
should_loop: bool
) -> Option<&T>where
F: Fn(&T) -> bool,Expand description
Find element relative to reference element.
eg. to get the next element, use shift 1,
to get the previous element, use shift -1.
Arguments
list- The list to get the element fromreference_finder- Predicate to find the reference element in the listshift- The shift (distance) of the element you try to find relative to the reference element, can be negative to move leftshould_loop- If the list should loop when theshiftgoes beyond the start/end of the list
Example
let list = vec!["hello", "world", "foo", "bar"];
let result = leftwm_core::utils::helpers::relative_find(&list, |&e| e == "world", 2, false);
assert_eq!(result, Some(&"bar"));