On 14/03/2016 11:32, thedeemon wrote:

filter_map : ('a -> 'b option) -> 'a t -> 'b t

"filter_map f e returns an enumeration over all elements x such as f y
returns Some x, where y is an element of e."

It is really convenient and comes handy in many situations. However it
requires some common Option/Maybe type that different libraries could use.

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]]));


Reply via email to