Also important to understand that what languages like Java and C# called Lambdas are in essence a plugin solution for first class functions. i.e. languages that have first class functions do not use the terminology lambdas.If you know what you are doing with Lambda functions, you can make your code simpler and more easier to read.
First class functions, simply means that we treat functions no differently than we treat data (arguments / parameters / variables, ...) i.e. referential transparency between values and functions.
Neither Java or C# innately supported first class functions, hence the term: lambdas. Why they don't is historical; by hinging design on a class construct means that everything has to be expressed i.t.o that. Complete switchover is not feasible because it would break so much existing code, hence it was added as a separate construct, aptly named lambdas. Practically this means that in order to take advantage of Lambdas with existing functions / methods, we have to first create lambda wrappers around these. For example in Java these are considered different type signatures.
PHP:
// Java Lambda function
BiFunction<Double, Double, Double> power = (value, power) -> Math.pow(value, power);
// Traditional Java function
double power(double value, double power) {
return Math.pow(value, power);
}
FYI I'm going to posting quite a few articles on my blog (in next few weeks) regarding this type of stuff.
Last edited: