A function to peel, chop, and cook food all in sequence. We chain multiple uses of `map()` to simplify the code.
(food: Option<Food>)
| 35 | // A function to peel, chop, and cook food all in sequence. |
| 36 | // We chain multiple uses of `map()` to simplify the code. |
| 37 | fn process(food: Option<Food>) -> Option<Cooked> { |
| 38 | food.map(|f| Peeled(f)) |
| 39 | .map(|Peeled(f)| Chopped(f)) |
| 40 | .map(|Chopped(f)| Cooked(f)) |
| 41 | } |
| 42 | |
| 43 | // Check whether there's food or not before trying to eat it! |
| 44 | fn eat(food: Option<Cooked>) { |