pub fn last_or<T>(collection: &[T], fallback: T) -> TExpand description
Returns the last item from the collection. If the collection is empty, returns the provided fallback value.
§Arguments
collection- A slice of items.fallback- The value to return if the collection is empty.
§Returns
T- The last item in the collection or the fallback value if empty.
§Examples
use lowdash::last_or;
let numbers = vec![1, 2, 3];
let last_num = last_or(&numbers, 10);
assert_eq!(last_num, 3);
let empty: Vec<i32> = vec![];
let last_num = last_or(&empty, 10);
assert_eq!(last_num, 10);