<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 21, 2016 at 4:34 AM, Nick Treleaven via Digitalmars-d <span dir="ltr"><<a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">On 14/03/2016 11:32, thedeemon wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
filter_map : ('a -> 'b option) -> 'a t -> 'b t<br>
<br>
"filter_map f e returns an enumeration over all elements x such as f y<br>
returns Some x, where y is an element of e."<br>
<br>
It is really convenient and comes handy in many situations. However it<br>
requires some common Option/Maybe type that different libraries could use.<br>
</blockquote>
<br></span>
There is a pull for Option:<br>
<a href="https://github.com/D-Programming-Language/phobos/pull/3915" rel="noreferrer" target="_blank">https://github.com/D-Programming-Language/phobos/pull/3915</a><br>
<br>
We could have:<br>
<br>
// fun takes r.front and produces an Option of that type<br>
auto mapFilter(alias fun, R)(R r);<br>
<br>
// turn a possibly null value into an Option<br>
Option!T nullFilter(T)(T v) if (isNullable!T);<br>
<br>
auto src = [new Object(), new T(), null];<br>
auto res = mapFilter!(e => nullFilter(cast(T)e));<br>
assert(res.equal([src[1]]));<br>
<br>
<br>
</blockquote></div><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">see my proposal [+implementation] for emit <a href="http://forum.dlang.org/post/mailman.538.1458560190.26339.digitalmars-d@puremagic.com">http://forum.dlang.org/post/mailman.538.1458560190.26339.digitalmars-d@puremagic.com</a> </div><div class="gmail_extra"><br></div><div class="gmail_extra">emit is more powerfull, and generalizes map,filter,joiner<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">auto res = src.mapFilter!(e=>nullFilter(cast(T)e));</div><div class="gmail_extra">with emit:</div><div class="gmail_extra">auto res = src.emit!((put,e){if(cast(T)e) put(e);});</div><div class="gmail_extra"> <br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div></div>