Skip to content

Instantly share code, notes, and snippets.

@MaximilianoFelice
MaximilianoFelice / chef-class.scala
Created September 6, 2017 22:42
[Medium] [Code] Builder Pattern in Scala with Phantom Types
class Chef[Pizza <: Chef.Pizza](ingredients: Seq[String]) {
import Chef.Pizza._
def addCheese(cheeseType: String): Chef[Pizza with Cheese] = new Chef(ingredients :+ cheeseType)
def addTopping(toppingType: String): Chef[Pizza with Topping] = new Chef(ingredients :+ toppingType)
def addDough: Chef[Pizza with Dough] = new Chef(ingredients :+ "dough")
def build(implicit ev: Pizza =:= FullPizza): Food = Food(ingredients)
@MaximilianoFelice
MaximilianoFelice / builder-phantom-types.scala
Last active July 26, 2023 22:49
A Builder example in Scala using Phantom Types
case class Food(ingredients: Seq[String])
class Chef[Pizza <: Chef.Pizza] protected (ingredients: Seq[String]) {
import Chef.Pizza._
def addCheese(cheeseType: String): Chef[Pizza with Cheese] = Chef(ingredients :+ cheeseType)
def addTopping(toppingType: String): Chef[Pizza with Topping] = Chef(ingredients :+ toppingType)
def addDough: Chef[Pizza with Dough] = Chef(ingredients :+ "dough")
# Notify Slack - Send notifications to a Slack Channel
#
# Original script from:
# Copyright (C) 2016 Gustavo Arjones (@arjones)
#
# Some configuration and notification changes were added by:
# 2017 Maximiliano Felice
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License