(10 >)\" is there a way to write this such that the" />
开发者

Is there a way to write this in F#?

let is_sum_greater_than_10 list =
    list
    |> Seq.filter (filter)
    |> Seq.sum
    |> (10 >)

This does not compile. Lookng at the last line "|> (10 >)" is there a way to write this such that the left is pipelined t开发者_StackOverflowo the right for binary operators?

Thanks


You can use a partial application of the < operator, using the (operator-symbol) syntax:

let is_sum_greater_than_10 list =
    list
    |> Seq.filter filter
    |> Seq.sum
    |> (<)10

You can also see this as an equivalent of a lambda application:

let is_sum_greater_than_10 list =
    list
    |> Seq.filter filter
    |> Seq.sum
    |> (fun x y -> x < y)10

or just a lambda:

let is_sum_greater_than_10 list =
    list
    |> Seq.filter filter
    |> Seq.sum
    |> (fun y -> 10 < y)


You can use a slightly modified version of your example, albeit this is in an infix expression notation:

let ``is sum greater than 10`` filter list =
    (list
        |> Seq.filter filter
        |> Seq.sum) > 10
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜