Skip to content

Instantly share code, notes, and snippets.

@nikoheikkila
Last active March 10, 2023 09:57
Show Gist options
  • Save nikoheikkila/49f88c62b4dea150e0605f8cfece1832 to your computer and use it in GitHub Desktop.
Save nikoheikkila/49f88c62b4dea150e0605f8cfece1832 to your computer and use it in GitHub Desktop.
TypeScript version of the card game presented in the talk Domain Modelling Made Functional by Scott Wlaschin.
export enum Suit {
Club,
Diamond,
Spade,
Heart,
}
export enum Rank {
Two = 2,
Three,
Four,
Five,
Six,
Seven,
Eight,
Nine,
Ten,
Jack,
Queen,
King,
Ace,
}
export type Card = { suit: Suit; rank: Rank; };
export type Hand = Card[];
export type Deck = Card[];
export type ShuffledDeck = Card[];
export type Player = { name: string; hand: Hand; };
export type Game = { deck: Deck; players: Player[]; };
export type ReturnDeck = { deck: ShuffledDeck; card: Card };
export type Deal = (input: ShuffledDeck) => ReturnDeck;
export type Shuffle = (input: Deck) => ShuffledDeck;
export type Pickup = { hand: Hand, card: Card};
export type PickupCard = (input: Pickup) => Hand;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment