Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to write this in F#?

Tags:

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 to the right for binary operators?

Thanks

like image 260
SharePoint Newbie Avatar asked Oct 20 '10 12:10

SharePoint Newbie


Video Answer


1 Answers

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)
like image 140
Stringer Avatar answered Oct 12 '22 03:10

Stringer