Skip to content

Instantly share code, notes, and snippets.

@misterspeedy
Created October 8, 2013 19:01
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/6889775 to your computer and use it in GitHub Desktop.
Save misterspeedy/6889775 to your computer and use it in GitHub Desktop.
Type to represent a card
/// A playing card.
type Card = { Rank : Rank; Suit : Suit }
with
static member FromString (s : String) =
let rank, suit =
match s.Length with
| 2 -> s.Substring(0, 1), s.[1]
// The 10 case has three characters
| 3 -> s.Substring(0, 2), s.[2]
| _ -> raise (ArgumentException("Invalid card string: ", s))
{ Rank = Rank.FromString rank; Suit = Suit.FromChar suit}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment