Skip to content

Instantly share code, notes, and snippets.

@Youenn-Bouglouan Youenn-Bouglouan/Pizzas.fs

Last active Mar 16, 2017
What would you like to do?
C# pizzas versus F# pizzas. Which ones are tastier?!
using System;
namespace Pizzas
public class PizzaRecipe {}
public class PizzaOrder {}
public class ColdPizza {}
public class HotPizza {}
public class PizzaDelivery {}
public static class PizzaService
public static PizzaOrder OrderPizza(PizzaRecipe recipe, string size)
return new PizzaOrder();
public static ColdPizza PreparePizza(PizzaOrder order)
return new ColdPizza();
public static HotPizza CookPizza(ColdPizza pizza, int temperature)
return new HotPizza();
public static PizzaDelivery DeliverPizza(HotPizza pizza)
return new PizzaDelivery();
// The ol'good way.
public static PizzaDelivery BigPizzaProcess1(PizzaRecipe recipe)
var order = OrderPizza(recipe, "big");
var coldPizza = PreparePizza(order);
var hotPizza = CookPizza(coldPizza, 180);
var delivery = DeliverPizza(hotPizza);
return delivery;
// The Arabic way: You read from right to left.
public static PizzaDelivery BigPizzaProcess2(PizzaRecipe recipe)
return DeliverPizza(CookPizza(PreparePizza(OrderPizza(recipe, "big")), 180));
// The nice way!
public static PizzaDelivery BigPizzaProcess3(PizzaRecipe recipe)
return recipe
public static class PizzaExtensions
public static PizzaOrder Order(this PizzaRecipe recipe, string size)
return PizzaService.OrderPizza(recipe, size);
public static ColdPizza Prepare(this PizzaOrder order)
return PizzaService.PreparePizza(order);
public static HotPizza Cook(this ColdPizza pizza, int temperature)
return PizzaService.CookPizza(pizza, temperature);
public static PizzaDelivery Deliver(this HotPizza pizza)
return PizzaService.DeliverPizza(pizza);
open System
type PizzaRecipe() = class end
type PizzaOrder() = class end
type ColdPizza() = class end
type HotPizza() = class end
type PizzaDelivery() = class end
let order (size:string) (recipe:PizzaRecipe) =
let prepare (order:PizzaOrder) =
let cook (temperature:int) (pizza:ColdPizza) =
let deliver (pizza:HotPizza) =
let bigPizzaProcess (pizzaRecipe:PizzaRecipe) =
|> order "big"
|> prepare
|> cook 180
|> deliver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.