Ingredient is a named Go type based on string. It represents an ingredient name as a distinct domain value, making recipe code more expressive and helping prevent accidental use of an unrelated string. section 5.2.2 section 5.1
type Ingredient string
type IngredientMeasurement struct {
Ingredient Ingredient
Measurement Convertible #1
}
type IngredientList []IngredientMeasurement #2
type Step struct {
Description string
Ingredients IngredientList
}
The declaration places Ingredient inside a recipe model, where IngredientMeasurement pairs each name with a Convertible measurement and IngredientList groups those values. section 5.2.2
The type supports a clear recipe-domain structure:
- IngredientMeasurement associates an Ingredient with a Convertible measurement. section 5.2.2
- IngredientList stores measured ingredients for a recipe step. section 5.2.2
- GroceryList uses Ingredient as a map key so quantities can be accumulated by ingredient name. section 5.2.2
Ingredients in a pancake recipe
A recipe can contain Ingredient values such as Flour, Sugar, Milk, and Egg, each paired with a metric measurement. Scaling the recipe and creating a grocery list then operate on those structured values. section 5.6.2
