Skip to content

Commit 06ebe87

Browse files
Modify lambda usage examples to show both notations
1 parent 37dbeb6 commit 06ebe87

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

docs/fsharp/language-reference/functions/lambda-expressions-the-fun-keyword.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ The *expression* is the body of the function, the last expression of which gener
4949

5050
## Using Lambda Expressions
5151

52-
Lambda expressions are especially useful when you want to perform operations on a list or other collection and want to avoid the extra work of defining a function. Many F# library functions take function values as arguments, and it can be especially convenient to use a lambda expression in those cases. The following code applies a lambda expression to elements of a list. In this case, the anonymous function adds 1 to every element of a list.
52+
Lambda expressions are especially useful when you want to perform operations on a list or other collection and want to avoid the extra work of defining a function. Many F# library functions take function values as arguments, and it can be especially convenient to use a lambda expression in those cases. The following code applies a lambda expression to elements of a list. In this case, the anonymous function checks if an element is a text ending with specified characters.
5353

5454
[!code-fsharp[Main](~/samples/snippets/fsharp/lang-ref-1/snippet302.fs)]
5555

56+
The above shows both notations: using the `fun` keyword, and the shorthand `_.Property` notation.
57+
5658
## See also
5759

5860
- [Functions](index.md)
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
let list = List.map (fun i -> i + 1) [ 1; 2; 3 ]
2-
printfn "%A" list
1+
let fullNotation = [ "a"; "ab"; "abc" ] |> List.find ( fun text -> text.EndsWith("c") )
2+
printfn "%A" fullNotation // Output: "abc"
3+
4+
let shorthandNotation = [ "a"; "ab"; "abc" ] |> List.find ( _.EndsWith("b") )
5+
printfn "%A" shorthandNotation // Output: "ab"

0 commit comments

Comments
 (0)