Partial function application (Currying)

atzensepp webwicht at web.de
Sat Jan 20 17:35:56 UTC 2024


Hello,

D-Language allows for anonymous functions.
Is there a way of elegant partial function application such as in 
other (functional) languages?
A function "doemar" accepts a function with one parameter,
Another function g defined within mail accepts two parameters and 
should be applied partially. I found a way but it requires a 
temporary lambda expression in the invocation.
Is there a better way to do this?

```d
     void doemar( int delegate(int y) f)
     {
        for(int i=0;i<3;i++) writeln( f(i));
     }


     void main()
     {

        int delegate(int x,int y) g;
        for (int i=0;i<3;i++)
        {
           g = (a,b) => i*10+ a*3+b;

           writeln("---------");
           doemar( (x) => g(x,i));
        }
     }
```
Thanks


More information about the Digitalmars-d-learn mailing list