我试图找出正确的语法来使用管道运算符 |> 来创建对象。目前我正在使用一个静态成员来创建对象并只是通过管道传递给它。这里是简化版。
type Shape =
val points : Vector[]
new (points) =
{ points = points; }
static member create(points) =
Shape(points)
static member concat(shapes : Shape list) =
shapes
|> List.map (fun shape -> shape.points)
|> Array.concat
|> Shape.create
我想做的事 ...
static member concat(shapes : Shape list) =
shapes
|> List.map (fun shape -> shape.points)
|> Array.concat
|> (new Shape)
这样的事情可能吗?我不想通过使用静态成员创建重复我的构造函数来复制代码。
从 F# 4.0 开始,更新 构造函数是一流的函数
在 F# 4.0 中,正确的语法是。
static member concat(shapes : Shape list) =
shapes
|> List.map (fun shape -> shape.points)
|> Array.concat
|> Shape