On Wednesday, 14 February 2018 at 23:46:30 UTC, aliak wrote:
On Wednesday, 14 February 2018 at 15:14:24 UTC, Meta wrote:


I think the best way to do this is to implement `map` for your optional type.

Optional!U map(U, alias f)()
{
    return empty? no!U : some!U(f(t));
}

Optional!int a = 3;
auto b = a.map!(v => cast(float)v);
assert(is(typeof(b) == Optional!float));

Ooh yes, of course! Thank you :)

Even better:

import std.conv;

auto b = a.map!(to!float);

Reply via email to