C#能做的,F#基本都能做,但F#能做的,C#未必能做。

F#中的函数可以把几个函数组合起来使用。下面的例子是把由 function1 和 function2 这两个函数通过运算符“>>”(或“<<”)组合而成funuoction3,然后可以拿function3使用。

 

let function1 x = x + 1

let function2 x = x * 2

let function3 = function1 >> function2

let result5 = function3 100

运算结果是 202。

 

再看下面的例子:

let addOne x = x + 1
let timesTwo x = 2 * x
 
let Compose1 = addOne << timesTwo
let Compose2 = addOne >> timesTwo
 
// 结果是 5
let result1 = Compose1 2
 
//结果是 6
let result2 = Compose2 2

相关文章:

  • 2022-12-23
  • 2021-05-17
  • 2022-12-23
  • 2022-02-20
  • 2021-06-09
  • 2021-06-19
  • 2022-02-14
  • 2021-04-07
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-14
  • 2021-10-20
  • 2021-05-18
  • 2022-12-23
相关资源
相似解决方案