Right now, I'm repeating the following pattern many times :
range.map!(x => cast(Foo) x).filter!(x => x !is null)
Which is kind of annoying. Could we get something in phobos to do
this ?
On Monday, 14 March 2016 at 08:04:18 UTC, deadalnix wrote:
Right now, I'm repeating the following pattern many times :
range.map!(x => cast(Foo) x).filter!(x => x !is null)
Which is kind of annoying. Could we get something in phobos to
do this ?
BTW, .NET has an extension method called OfTyp
On Monday, 14 March 2016 at 08:04:18 UTC, deadalnix wrote:
Right now, I'm repeating the following pattern many times :
range.map!(x => cast(Foo) x).filter!(x => x !is null)
This reminds me of a function in OCaml extended stdlib that I've
used quite often and really miss in D:
filter_map : (
On Monday, 14 March 2016 at 08:04:18 UTC, deadalnix wrote:
Right now, I'm repeating the following pattern many times :
range.map!(x => cast(Foo) x).filter!(x => x !is null)
Which is kind of annoying. Could we get something in phobos to
do this ?
you could use an alias.
alias NullFliter = fi
On Monday, 14 March 2016 at 08:04:18 UTC, deadalnix wrote:
Right now, I'm repeating the following pattern many times :
range.map!(x => cast(Foo) x).filter!(x => x !is null)
Which is kind of annoying. Could we get something in phobos to
do this ?
There you go ;)
alias castRange(T) = map!(x
On Monday, 14 March 2016 at 23:34:37 UTC, Stefan Koch wrote:
On Monday, 14 March 2016 at 08:04:18 UTC, deadalnix wrote:
Right now, I'm repeating the following pattern many times :
range.map!(x => cast(Foo) x).filter!(x => x !is null)
Which is kind of annoying. Could we get something in phobos
On Monday, 14 March 2016 at 23:34:37 UTC, Stefan Koch wrote:
On Monday, 14 March 2016 at 08:04:18 UTC, deadalnix wrote:
Right now, I'm repeating the following pattern many times :
range.map!(x => cast(Foo) x).filter!(x => x !is null)
Which is kind of annoying. Could we get something in phobos
On Tuesday, 15 March 2016 at 04:05:11 UTC, Meta wrote:
I believe this should work with the latest DMD:
alias castRange(T) = t => t.map!(x => cast(T) x).filter!(x => x
!is null);
No it does not.
However this works :
auto typeFilter(T, Range)(Range range) {
import std.
On Tuesday, 15 March 2016 at 07:42:58 UTC, Stefan Koch wrote:
On Tuesday, 15 March 2016 at 04:05:11 UTC, Meta wrote:
I believe this should work with the latest DMD:
alias castRange(T) = t => t.map!(x => cast(T) x).filter!(x =>
x !is null);
No it does not.
However this works :
auto
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 O
On Mon, Mar 21, 2016 at 4:34 AM, Nick Treleaven via Digitalmars-d <
digitalmars-d@puremagic.com> wrote:
> 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, whe
On Monday, 21 March 2016 at 11:50:06 UTC, Timothee Cour wrote:
On Mon, Mar 21, 2016 at 4:34 AM, Nick Treleaven via
Digitalmars-d < digitalmars-d@puremagic.com> wrote:
On 14/03/2016 11:32, thedeemon wrote:
filter_map : ('a -> 'b option) -> 'a t -> 'b t
"filter_map f e returns an enumeration
On Tuesday, 22 March 2016 at 20:09:51 UTC, Matthias Bentrup wrote:
It is logically just a combination of map and concat (which
turns a range of ranges into a combined range, but I think that
one is missing in the std lib too).
http://dlang.org/phobos/std_range.html#.chain
On Wednesday, 23 March 2016 at 11:36:39 UTC, Nick Treleaven wrote:
On Tuesday, 22 March 2016 at 20:09:51 UTC, Matthias Bentrup
wrote:
It is logically just a combination of map and concat (which
turns a range of ranges into a combined range, but I think
that one is missing in the std lib too).
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 a
15 matches
Mail list logo