OT: on IDEs and code writing on steroids

Jarrett Billingsley jarrett.billingsley at gmail.com
Mon May 18 10:56:14 PDT 2009


On Mon, May 18, 2009 at 1:47 PM, BCS <ao at pathlink.com> wrote:

> I think this will work:
>
> int delegate(int delegate(ref T)) Where(T[] array, bool delegate(T) dg)
> {
>   struct Ret
>   {
>       T[] Array;
>       bool delegate(T) Dg;
>
>       int opApply(int delegate(ref T) idg)
>       {
>           foreach(ref T t; Array)
>              if(Dg(t)) if(int ret = idg) return ret;
>           return ret;
>       }
>       return &(Ret(array,dg)).opApply;
>   }
> }
>
> If not, a little tweeking shloudl cover it.

Using that, however, looks pretty ugly:

array.Where((SomeObject o) { return o.name == "foo"; });

D could really use some sugar for delegate literals, especially tiny
'predicate' literals like this.

array.Where(\o -> o.name == "foo");



More information about the Digitalmars-d mailing list