Skip to content

Instantly share code, notes, and snippets.

@misterspeedy
Created October 8, 2013 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misterspeedy/6889791 to your computer and use it in GitHub Desktop.
Save misterspeedy/6889791 to your computer and use it in GitHub Desktop.
Type to represent a hand of cards
/// 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