wraybowling / Food.js

A scalable cook book
http://wraybowling.github.io/Food.js/
5 stars 1 forks source link

Recipe Recursion #4

Open wraybowling opened 3 years ago

wraybowling commented 3 years ago

Some recipes need ingredients that in turn have their own recipe. I've been trying to decide a way to handle this for years. It's time to actually track my progress...

There's a simple way and a really complicated way. Right now I'm leaning towards a simple way because every time I think about the complicated way I make no progress. So. Here's my idea:

Currently, a regular ingredient can be written as "ingredient": 123 where the value is always number. For recursion, I think the simplest solution would be to assign the value as an object. Ingredients within that object could be checked against the master list to find recipes that have multiple uses. For example "Hollandaise" : { "Hollandaise" : 123 } But this would also allow the flexibility of defining sub-recipes, e.g. "steps", that will not have any use in the master list such as a specific dipping sauce like so "garlic soy": {"soy sauce": 29, "garlic": 29}. Note that the values must match the parent's portion size in that case. And of course, these effects would be able to combine. The most notable example is of course aiole. All aiole is just mayonnaise + something else but that means that if one of the ingredients comes in oil like anchovies you may as well build the mayonnaise itself using the oil the fish came in.

"Mayonnaise": {
  "Room Temperature Egg Yolk": 52,
  "Citric Acid (lemon)": 5,
  "Oil (add slowly)": 108,
  "Salt": 3
},
"Ceasar Salad": {
  "Romaine Lettuce": 500,
  "Ceasar Dressing": {
    "Anchovies": 23,
    "Mayonnaise": {"Mayonnaise": 155 },
    "Mustard": 10,
    "Worcestershire": 10,
    "Balsamic Vinegar": 10
  }
}

Which would initially render as:

Note that the 208 is a computed value. It is the sum of the sub-recipe's parts.

Note that the scalar for the mayo is 155/(52+5+108+3) = 0.9226190476 so that when Mayonnaise is expanded, the values from the initial recipe will be slightly smaller

Requirements:

philihp commented 3 years ago

I think before doing recursion, is there a way to denote which ingredients don’t scale?

for instance, red pepper flakes in a pasta sauce cause spice to grow exponentially. Maybe just add like 25% more?

sometimes ingredients are just there to catalyze. Like when poaching an egg, you just need a little bit of baking soda or vinegar to make the pH of the water different from the egg long enough that the egg white maintains cohesion long enough to cook. When you poach a 100 eggs, the water doesn’t need to be acidic enough to depolarize water.

wraybowling commented 3 years ago

Without recursion involved I could argue that these are two separate new issues.