파이프 생성자를 파이프 작성자로 사용하는 올바른 구문을 찾으려고합니다. 현재 정적 멤버를 사용하여 개체를 만들고 그 개체로 파이핑합니다. 다음은 단순화 된 버전입니다. 내가 원하는 무엇F # 파이프 기호를 개체 생성자와 함께 사용
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 F # 4.0 # 4.0
현재 일류 함수이다.static member concat(shapes : Shape list) =
shapes
|> List.map (fun shape -> shape.points)
|> Array.concat
|> Shape
어, 아주 간단합니다. 나는 많은 다른 문법을 시도하고 재미를 사용하는 것을 생각조차하지 않았다. 고마워요. – gradbot