Skip to content

Instantly share code, notes, and snippets.

@jacobbubu
Created April 11, 2017 07:53
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 jacobbubu/d8683d392ebea66e0003b9105cafe60c to your computer and use it in GitHub Desktop.
Save jacobbubu/d8683d392ebea66e0003b9105cafe60c to your computer and use it in GitHub Desktop.
Flow-type example for Tennis Kata
/* @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