Higher-order functions?

Nick Sabalausky SeeWebsiteToContactMe at semitwist.com
Tue Apr 10 17:37:22 PDT 2012


"Timon Gehr" <timon.gehr at gmx.ch> wrote in message 
news:jm2hnp$s0s$1 at digitalmars.com...
>
> (Well, the standard way to do what that python code does is using 
> templates.
>
> auto car_prices = map!(car => car.get_price)(list_of_cars);// lazy range
> auto car_prices = array(map!(car => car.get_price(list_of_cars)); // eager 
> array)
>

And keep in mind, too, even though those high-order functions take the 
delegate/closure as a template paramater, you CAN still rig it up for the 
delegate/closure to be changed at runtime (as long as the delegate's 
signature is the same):

auto myDelegate = (Car c) => c.getPrice;

// Change it at runtime:
if(foo)
    myDelegate = (Car c) => c.getPrice + 7;

auto carPrices = map!myDelegate(list_of_cars);




More information about the Digitalmars-d-learn mailing list