Created
October 8, 2013 19:02
-
-
Save misterspeedy/6889791 to your computer and use it in GitHub Desktop.
Type to represent a hand of cards
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// A hand of exactly five cards. | |
type Hand(cards : Card[]) = | |
do | |
if cards.Length <> 5 then | |
raise (ArgumentException("Invalid number of cards")) | |
/// The cards in the hand, sorted in descending order of rank. | |
member h.Cards = cards |> Array.sortBy (fun card -> 0 - card.Rank.SortValue) | |
static member FromString (s : string) = | |
let cards = | |
s.Split([|' '|]) | |
|> Array.map (fun s' -> Card.FromString s') | |
Hand cards |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment