Can I pass a function by parameter?

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 7 20:35:11 PDT 2014


On Sunday, 7 September 2014 at 20:47:47 UTC, AsmMan wrote:
> I'm trying to use a bit of function programming.
>
> In a function like this:
>
> int f(in int[] arr, bool delegate(int) func);
>
> call using:
>
> bool g(int n) { ... }
> f(arr, g);
>
> instead of:
>
> f(arr, x => x == 0);
>
> it is possible?

In D there is a difference between a function and a first class 
function. Popular languages like C++ have a lot of accidental 
complexity, so we decided to introduce some to be successful as 
well.


More information about the Digitalmars-d mailing list