Chaining std.algorithm functions

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Apr 12 10:10:55 PDT 2012


On Thu, Apr 12, 2012 at 07:00:35PM +0200, DH wrote:
> Hi. I was wondering why the following works:
> 
>     filter!(a => a % 2 == 0)(map!(a => a + 1)([1,2,3,4,5]))
> 
> but the following does not:
> 
>     [1,2,3,4,5]
>         .map!(a => a + 1)()
>         .filter!(a => a % 2 == 0)()
> 
> ...giving me the error `Error: no property 'filter' for type
> 'Result'`
> 
> The dot syntax works fine if I'm just doing one map/filter/etc.,
> though. Is there a better way to do chaining like this? Am I
> misunderstanding how the dot syntax sugar works or how map/filter/etc
> work in D? I'd prefer not to use the first style as it can get a bit
> unwieldy...
[...]

The second syntax requires dmd 2.059, which is currently on beta.
Earlier versions of dmd do not support this syntax.


T

-- 
Two wrongs don't make a right; but three rights do make a left...


More information about the Digitalmars-d-learn mailing list