F# 中的函数应用运算符 ($)? [英] Function Application Operator ($) in F#?
本文介绍了F# 中的函数应用运算符 ($)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有这个代码
let identifier = spaces_surrounded (many1Satisfy isLetter)
我想知道是否有任何原生 F# 函数允许我将其重构为
I was wondering if it there was any native F# function that allowed me to refactor it to
let identifier = spaces_surrounded $ many1Satisfy isLetter
也就是说,诸如
let ($) f1 f2 = f1 (f2)
(也就是说如果我没记错的话,我的 Haskell 技能还不算太敏锐..).
(that is if I am not mistaken, my Haskell skills are not too sharp..).
推荐答案
用于此的标准 F# 习语是前向管道运算符 |>
如果您要重写
The standard F# idiom for this is the forward pipe operator |>
were you would rewrite
let identifier = spaces_surrounded (many1Satisfy isLetter)
作为
let identifier = many1Satisfy isLetter |> spaces_surrounded
如果你想保持原来的顺序,你也可以使用反向管道操作符<|
,但这往往不太常见
you can also use the backward pipe operator <|
if you want to maintain the original order, but this tends to be a little less common
let identifier = spaces_surrounded <| many1Satisfy isLetter
这篇关于F# 中的函数应用运算符 ($)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文