The OpenD Programming Language

find

Finds an element e of an input range where pred(e) is true.

$(PANEL $(UL $(LI `find` behaves similarly to `dropWhile` in other languages.) $(LI To _find the *last* matching element in a $(REF_ALTTEXT bidirectional, isBidirectionalRange, std,range,primitives) `haystack`, call `find!pred(retro(haystack))`. See $(REF retro, std,range).) ))

Complexity: find performs O(walkLength(haystack)) evaluations of pred.

Parameters

pred

The predicate to match an element.

haystack InputRange

The input range searched in.

Return Value

Type: InputRange

haystack advanced such that the front element satisfies pred. If no such element exists, returns an empty haystack.

Examples

auto arr = [ 1, 2, 3, 4, 1 ];
assert(find!("a > 2")(arr) == [ 3, 4, 1 ]);

// with predicate alias
bool pred(int e) => e + 1 > 1.5;
assert(find!(pred)(arr) == arr);

Meta