Skip to content

Instantly share code, notes, and snippets.

@kasperpeulen
Last active December 14, 2019 18:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kasperpeulen/b9ac0d3d53d751ccd2166cf3064c9e5c to your computer and use it in GitHub Desktop.
Save kasperpeulen/b9ac0d3d53d751ccd2166cf3064c9e5c to your computer and use it in GitHub Desktop.
What is algebraic about algebraic data types?
type TastyFruit = { fruit: 'blueberry' | 'raspberry' } & { portion: 3 | 5 | 7 | 11 } & { tasty: true };
type SomeTimesTasty = { fruit: 'orange' | 'banana' } & { portion: 1 | 2 } & { tasty: boolean };
type NastyFruit = { fruit: 'lemon' } & { portion?: 1 } & { tasty: false };
type Fruit = TastyFruit | SomeTimesTasty | NastyFruit;
const numberOfUniqueInstances = (2 * 4 * 1) + (2 * 2 * 2) + (1 * 2 * 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment