ax1*_*mx2 1 lambda f# functional-programming function function-composition
例如,F#是否有可能在Operators.Not某些标准.NET函数之间具有函数组合String.IsNullOrEmpty?
换句话说,为什么以下lambda表达式是不可接受的:
(fun x -> not >> String.IsNullOrEmpty)
Run Code Online (Sandbox Code Playgroud)
该>>函数组合一轮工作的另一种方式-它通过左边到右边的功能函数的结果-使您的代码段传递bool到IsNullOrEmpty,这是一种错误.以下作品:
(fun x -> String.IsNullOrEmpty >> not)
Run Code Online (Sandbox Code Playgroud)
或者你可以使用反转函数组合(但我认为>>在F#中通常是首选):
(fun x -> not << String.IsNullOrEmpty)
Run Code Online (Sandbox Code Playgroud)
除此之外,这个片段正在创建一个类型的函数'a -> string -> bool,因为它忽略了参数x.所以我想你可能真的只想:
(String.IsNullOrEmpty >> not)
Run Code Online (Sandbox Code Playgroud)