Skip to content

Instantly share code, notes, and snippets.

@tjweir
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save tjweir/9017580 to your computer and use it in GitHub Desktop.

Select an option

Save tjweir/9017580 to your computer and use it in GitHub Desktop.
// From Conceptual Mathematics and http://eed3si9n.com/learning-scalaz/Category+theory.html
sealed trait Person {}
case object John extends Person {}
case object Mary extends Person {}
case object Sam extends Person {}
val a: Set[Person] = Set[Person](John, Mary, Sam)
sealed trait Breakfast {}
case object Eggs extends Breakfast {}
case object Oatmeal extends Breakfast {}
case object Toast extends Breakfast {}
case object Coffee extends Breakfast {}
sealed trait Dish {}
case object Mug extends Dish {}
case object Plate extends Dish {}
case object Bowl extends Dish {}
val favoriteBreakfast: Person => Breakfast = {
case John => Eggs
case Mary => Coffee
case Sam => Coffee
}
val favoritePerson: Person => Person = {
case John => Mary
case Mary => John
case Sam => Mary
}
val servedIn: Breakfast => Dish = {
case Eggs => Plate
case Coffee => Mug
case Oatmeal => Bowl
case Toast => Plate
}
val favoritePersonsBreakfast = favoriteBreakfast compose favoritePerson
val favoritePersonsBreakfastDish = servedIn compose favoriteBreakfast compose favoritePerson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment