Is there any generic iteration function that stops at first match?
H. S. Teoh
hsteoh at quickfur.ath.cx
Fri Mar 5 02:43:36 UTC 2021
On Fri, Mar 05, 2021 at 02:13:39AM +0000, Jack via Digitalmars-d-learn wrote:
> something like filter[1] but that stops at first match? are there any
> native functions for this in D or I have to write one? just making
> sure to not reinvent the wheel
[...]
Why not just .front? E.g.:
int[] data = [ 1,2,3,4,5 ];
auto r = data.filter!(v => v % 2 == 0);
assert(r.front == 2);
T
--
There is no gravity. The earth sucks.
More information about the Digitalmars-d-learn
mailing list