Skip to content

Instantly share code, notes, and snippets.

@misterspeedy
Created October 8, 2013 19:00
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/6889751 to your computer and use it in GitHub Desktop.
Save misterspeedy/6889751 to your computer and use it in GitHub Desktop.
DU to represent a rank
/// A card rank.
type Rank =
| Ace | King | Queen | Jack | Value of int
static member FromString s =
match s with
| "A" -> Ace | "K" -> King | "Q" -> Queen | "J" -> Jack
| "10" -> Value(10)
| _ when s.Length = 1 && s.[0] >= '2' && s.[0] <= '9' -> Value(int(s.[0]) - int('0'))
| _ -> raise (ArgumentException(sprintf "Invalid rank string: %s" s))
/// The value of the rank for comparison purposes.
member r. SortValue =
match r with
| Ace -> 14 // Aces high - low-ace cases are handled elsewhere
| King -> 13
| Queen -> 12
| Jack -> 11
| Value v -> v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment