The OpenD Programming Language

findAdjacent

Advances r until it finds the first two adjacent elements a, b that satisfy pred(a, b). Performs O(r.length) evaluations of pred.

For more information about pred see find.

Range
findAdjacent
(
alias pred = "a == b"
Range
)
(
Range r
)
if ()

Parameters

pred

The predicate to satisfy.

r Range

A forward range to search in.

Return Value

Type: Range

r advanced to the first occurrence of two adjacent elements that satisfy the given predicate. If there are no such two elements, returns r advanced until empty.

Examples

int[] a = [ 11, 10, 10, 9, 8, 8, 7, 8, 9 ];
auto r = findAdjacent(a);
assert(r == [ 10, 10, 9, 8, 8, 7, 8, 9 ]);
auto p = findAdjacent!("a < b")(a);
assert(p == [ 7, 8, 9 ]);

See Also

Meta