Skip to content

Instantly share code, notes, and snippets.

@HDBandit
Created May 14, 2016 17:12
Show Gist options
  • Save HDBandit/566227fb24948ba548d4d638c1ed296c to your computer and use it in GitHub Desktop.
Save HDBandit/566227fb24948ba548d4d638c1ed296c to your computer and use it in GitHub Desktop.
public class Pizza {
private Ingredient[] ingredients;
private Function<Pizza, Pizza> complement;
private int basePrice;
public static Pizza newPizza(int price, Ingredient... ingredients) {
return new Pizza(price, ingredients);
}
private Pizza(int basePrice, Ingredient... ingredients) {
this.ingredients = ingredients;
this.basePrice = basePrice;
}
public void setComplements(Function<Pizza, Pizza>... complements) {
complement = Stream.of(complements).reduce(Function.identity(), Function::andThen);
}
public int getTotalPrice() {
Pizza p = complement.apply(this);
return p.getBasePrice();
}
public int getBasePrice() {
return basePrice;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment