I have to write a function for school which determines from a poker hand if it has two pairs. I should do it with partial active pattern, but I am stuck here.
let (|TwoPairs|_|) (x: (string * string) list) =
x
|> List.groupBy snd
|> List.sortByDescending fst
|> List.filter (fun (_, v) -> v |> List.length = 2)
|> List.length = 2
let x2 =
match [("S", "2"); ("S", "6"); ("S", "6"); ("S", "4"); ("S", "2")] with
| TwoPairs p -> sprintf "Two pairs"
| _ -> "Nothing"
How do I give back the last comparison as an option and what should be in Some _ in this case?