如何将函数直接应用于 F# 中匹配表达式的值

Vic*_*isa 1 f# functional-programming match

假设我有

let someFunction someVar =
  let x = 
    match someVar with
    | Value1 -> 10
    | Value2 -> 20
  anotherFunction x
Run Code Online (Sandbox Code Playgroud)

有没有办法在不使用辅助“x”变量的情况下直接将“anotherFunction”应用于匹配表达式的返回?

scr*_*wtp 6

是的,您可以直接应用它。

let someFunction someVar =
    anotherFunction( 
        match someVar with
        | Value1 -> 10
        | Value2 -> 20)
Run Code Online (Sandbox Code Playgroud)

与 F# 中的大多数其他内容一样,匹配块是您可以使用内联的表达式,如果您认为它可以改进您的代码。不过,我不相信在这种情况下它更可取。