Find the first element in a range that for which a predicate is true, or the empty range if the predicate is not true for any element.
find (predicate, range) is roughly defined as if (empty (range) || predicate (first (range))) return range; else return find (predicate, drop (range));
The complete parameter list is find (range, [direction,] predicate, [actor_non_empty, [actor_empty]]).
The additional first parameter is the direction. The actors are functions that are called with the range starting with the first element for which the predicate is true. If no actor is given, the range is returned. If one actor is given, it is called on the range and its return value called. If two actors are given, the first one is called if the range is non-empty and the second if the range is empty. The function then implements if (empty (range, direction)) return actor_empty (range); else if (predicate (first (range, direction))) return actor_non_empty (range); else return find (drop (range, direction), direction, predicate, actor_non_empty, actor_empty);
The recursion is implemented as an iteration if the range is homogeneous, to prevent stack overflows.
The first evaluation of the predicate to return true is the last to be evaluated.
The first evaluation of the predicate to return a true compile-time constant is the last to be instantiated.
The range to find an element in.
(optional) The direction to traverse the range in.
The function that is called with every element until it returns true.
(optional) The function that is called with the remaining range that starts with the first element that predicate returns true for. By default, the range itself is returned.
(optional) The function that is called with the empty range if predicate is not true for any element. By default, actor_non_empty is used.
Return whether all elements of the range evaluate to true.
Written tersely, all_of (r) returns fold (r, &&, true).
If the result is known at compile time, a compile time constant is returned.
Short-circuiting is important. If any element is known at compile time to be false, then the following elements are not instantiated. If any element is found at run time to false, then the following elements are not evaluated.
Return whether any elements of the range evaluate to true.
Written tersely, any_of (r) returns fold (||, false, r).
If the result is known at compile time, a compile time constant is returned.
Short-circuiting is important. If any element is known at compile time to be true, then the following elements are not instantiated. If any element is found at run time to true, then the following elements are not evaluated.
Compare two ranges for equality.
The first range to compare.
The second range to compare.
(optional) Direction that should be used to traverse the ranges. If not given, the default direction of the first range is used.
(optional) Predicate to use to compare individual elements. If not given, then operator== is used.
Compare two ranges lexicographically.
The first range to compare.
The second range to compare.
(optional) Direction that should be used to traverse the ranges. If not given, the default direction of the first range is used.
(optional) Predicate used for comparing individual elements. If not given, then operator== is used.