Skip to content

Instantly share code, notes, and snippets.

@misterspeedy
Created October 7, 2013 18:25
Show Gist options
  • Select an option

  • Save misterspeedy/6872627 to your computer and use it in GitHub Desktop.

Select an option

Save misterspeedy/6872627 to your computer and use it in GitHub Desktop.
Representing a hand of cards as an F# type.
/// 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