On Monday, 21 March 2016 at 11:34:15 UTC, Nick Treleaven wrote:
There is a pull for Option:
https://github.com/D-Programming-Language/phobos/pull/3915
We could have:
// fun takes r.front and produces an Option of that type
auto mapFilter(alias fun, R)(R r);
// turn a possibly null value into an Option
Option!T nullFilter(T)(T v) if (isNullable!T);
auto src = [new Object(), new T(), null];
auto res = mapFilter!(e => nullFilter(cast(T)e));
assert(res.equal([src[1]]));
Using the interface proposed in the PR:
auto src = [new Object(), new T(), null];
assert(src.map!(e =>
option(cast(T)e)).joiner.equal(only(src[1])));