Fetching an element using find

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Jan 13 18:23:48 UTC 2020


On Mon, Jan 13, 2020 at 12:58:57PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote:
> On 1/13/20 12:47 PM, H. S. Teoh wrote:
> > 
> > Why not write your own convenience wrapper?
> > 
> > 	auto firstElement(R)(R r)
> > 		if (isInputRange!R)
> > 	{
> > 		if (r.empty) throw new Exception(...);
> > 		return r.front;
> > 	}
> > 
> > 	auto e = myData.find!(e => blah(e)).firstElement;
> 
> I certainly can (and did). I was wondering if there was something in
> Phobos to do it.
[...]

Maybe add a new function to Phobos? :-D


T

-- 
It always amuses me that Windows has a Safe Mode during bootup. Does that mean that Windows is normally unsafe?


More information about the Digitalmars-d-learn mailing list