The way you do is beautiful. You can express any recursive function in lists as a fold, but I donβt think you get anything by doing it here. There is also no built-in function to do exactly what you need, but you could build a more general function and build your own calculation on top of it. Here is one such approach:
let rec allChoices = function | [] -> [[]] | l::ls -> [for x in l do for xs in allChoices ls do yield x::xs] let values hand = hand |> List.map cardValues |> allChoices |> List.map (List.sum)
The allChoices function takes a list of lists and returns every possible list containing one element from each (for example, allChoices [[1];[2;3];[4;5]] = [[1;2;4];[1;2;5];[1;3;4];[1;3;5]] ). We use this function to get all possible lists of values ββfor cards in hand, and then summarize each such list.
There are probably several other ways to look at a problem that other options might offer.
source share