Functions and lambda expressions

A lambda expression is one kind of anonymous function, which means it doesn't have a name attached to it. But if we want to create a function which can be called, we can use the fun keyword with a lambda expression. We can pass the input parameter in the lambda function, which is created using the fun keyword. This function is quite similar to a normal F# function. Let's see a normal F# function and a lambda function:

// Normal F# functionlet addNumbers a b = a+b// Evaluating valueslet sumResult = addNumbers 5 6 // Lambda function and evaluating valueslet sumResult = (fun (a:int) (b:int) -> a+b) 5 6// Both the function will return value sumResult = 11

Get .NET Core 2.0 By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.