Let’s say I have a discriminated union:
type foo = Bar | Baz | Batz
Then, I want to check how many members of a list are of type Baz:
List.sumBy (function Bar -> 1 | _ -> 0) foos
Is there a more idiomatic way to do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Notice that your example is incorrect. It should be:
which could be rewritten as:
I don’t think there’s a more idomatic way than using
List.sumByhere.