On Friday, 2 September 2016 at 06:56:07 UTC, Lutger wrote:
I was looking for something like FirstOrDefault* from .NET in
phobos. For example, I have this piece of code:
string findBobOrReturnNull(string[] names)
{
auto r = names.find("bob");
if(r.empty) return null;
return r.front;
On Friday, 2 September 2016 at 06:56:07 UTC, Lutger wrote:
You could do:
names.find("bob").chain(only(``)).front;
It's not very expressive though.
I was looking for something like FirstOrDefault* from .NET in
phobos. For example, I have this piece of code:
string findBobOrReturnNull(string[] names)
{
auto r = names.find("bob");
if(r.empty) return null;
return r.front;
}
assert(findBobOrReturnNull(["alice", "bob"]) == "bob");
a