F #, Forward a match case without using a temporary variable

I would like to redirect the variable to a match case without using the temp variable or lambda. Idea:

let temp = x |> Function1 |> Function2 // ........ Many functions later. |> FunctionN let result = match temp with | Case1 -> "Output 1" | Case2 -> "Output 2" | _ -> "Other Output" 

Hope to write something similar to the following:

 // IDEAL CODE (with syntax error) let result = x |> Function1 |> Function2 // ........ Many functions later. |> FunctionN |> match with // Syntax error here! Should use "match something with" | Case1 -> "Output 1" | Case2 -> "Output 2" | _ -> "Other Output" 

The closest I have is using lambda. But I think the code below is not very good, because I will still β€œname” the temporary variable.

 let result = x |> Function1 |> Function2 // ........ Many functions later. |> FunctionN |> fun temp -> match temp with | Case1 -> "Output 1" | Case2 -> "Output 2" | _ -> "Other Output" 

On the other hand, I can directly replace the temp variable with a large piece of code:

 let result = match x |> Function1 |> Function2 // ........ Many functions later. |> FunctionN with | Case1 -> "Output 1" | Case2 -> "Output 2" | _ -> "Other Output" 

Can I write code similar to Code # 2? Or do I need to select code number 3 or number 4? Thanks.

+5
source share
1 answer
 let result = x |> Function1 |> Function2 // ........ Many functions later. |> FunctionN |> function | Case1 -> "Output 1" | Case2 -> "Output 2" | _ -> "Other Output" 
+12
source

Source: https://habr.com/ru/post/1273162/


All Articles