Last active
March 10, 2023 09:57
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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