Created
April 11, 2017 07:53
-
-
Save jacobbubu/d8683d392ebea66e0003b9105cafe60c to your computer and use it in GitHub Desktop.
Flow-type example for Tennis Kata
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
/* @flow */ | |
type Point = 'Love' | 'Fifteen' | 'Thirty'; | |
type Deuce = 'Deuce'; | |
type PlayerOne = 'Player1'; | |
type PlayerTwo = 'Player2'; | |
type Player = PlayerOne | PlayerTwo; | |
type GameOfPlayer = { | |
gameOfPlayer: Player | |
} | |
// A status that one of players reaches 'Forty'(before first deuce) first | |
type FortyData = { | |
Player : Player, | |
OtherPlayerPoint : Point, | |
} | |
type Advantage = { | |
advantage : Player, | |
} | |
// Both players haven't reaching deuce | |
type PointsData = { PlayerOnePoint : Point; PlayerTwoPoint : Point }; | |
type Score = PointsData | FortyData | Deuce | Advantage | GameOfPlayer; | |
let start: Score = { | |
PlayerOnePoint: 'Love', | |
PlayerTwoPoint: 'Love', | |
}; | |
let ball1: Score = { | |
PlayerOnePoint: 'Fifteen', | |
PlayerTwoPoint: 'Love', | |
}; | |
let ball2: Score = { | |
PlayerOnePoint: 'Thirty', | |
PlayerTwoPoint: 'Love', | |
}; | |
let ball3: Score = { | |
PlayerOnePoint: 'Thirty', | |
PlayerTwoPoint: 'Thirty', | |
}; | |
let ball4: Score = { | |
Player: 'Player1', | |
OtherPlayerPoint: 'Thirty', | |
}; | |
let ball5: Score = 'Deuce'; | |
let ball6: Score = { | |
advantage: 'Player1' | |
}; | |
let ball7: Score = { | |
gameOfPlayer: 'Player1' | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://blog.ploeh.dk/2016/02/10/types-properties-software-designing-with-types/