Can you name the parameters in a Func type?

You can’t do it with the built-in Func types, but it’s easy enough to create your own custom delegate type and use it in a similar way: _messageProcessing.Add(“input”, (x, y, z) => “output”); _messageProcessing.Add(“another”, (x, y, z) => “example”); // … delegate string DispatchFunc(DynamicEntity first, DynamicEntity second, IEnumerable<DynamicEntity> collection); Dictionary<string, DispatchFunc> _messageProcessing;

Recursion and anonymous functions in elixir

It is not possible to recur on anonymous functions in Elixir. Erlang 17 (currently a release candidate) adds this possibility to Erlang and we plan to leverage it soon. Right now, the best approach is to define a module function and pass it around: def neural_bias([i|input],[w|weights], acc) do neural(input,weights,i*w+acc) end def neural_bias([], [bias], acc) do … Read more

How can I access local variables from inside a C++11 anonymous function?

You need a closure. float tot = std::accumulate(weights.begin(), weights.end(), 0); std::transform(weights.begin(), weights.end(), [tot](float x)->float{return(x/tot);}); In this case tot is captured by value. C++11 lambdas support capturing by: value [x] reference [&x] any variable currently in scope by reference [&] same as 3, but by value [=] You can mix any of the above in a … Read more

javascript: recursive anonymous function?

You can give the function a name, even when you’re creating the function as a value and not a “function declaration” statement. In other words: (function foo() { foo(); })(); is a stack-blowing recursive function. Now, that said, you probably don’t may not want to do this in general because there are some weird problems … Read more

Why and how do you use anonymous functions in PHP?

Anonymous functions are useful when using functions that require a callback function like array_filter or array_map do: $arr = range(0, 10); $arr_even = array_filter($arr, function($val) { return $val % 2 == 0; }); $arr_square = array_map(function($val) { return $val * $val; }, $arr); Otherwise you would need to define a function that you possibly only … Read more