Skip to content

Commit 6150bf7

Browse files
author
Bart Smykla
committed
Fixed small logic error in error/option_unwrap/and_then
To know about ingredients, you need to know recipe first. Signed-off-by: Bart Smykla <[email protected]>
1 parent 843cc35 commit 6150bf7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/error/option_unwrap/and_then.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ fn have_recipe(food: Food) -> Option<Food> {
3434
}
3535
}
3636
37-
// To make a dish, we need both the ingredients and the recipe.
37+
// To make a dish, we need both the recipe and the ingredients.
3838
// We can represent the logic with a chain of `match`es:
3939
fn cookable_v1(food: Food) -> Option<Food> {
40-
match have_ingredients(food) {
40+
match have_recipe(food) {
4141
None => None,
42-
Some(food) => match have_recipe(food) {
42+
Some(food) => match have_ingredients(food) {
4343
None => None,
4444
Some(food) => Some(food),
4545
},
@@ -48,7 +48,7 @@ fn cookable_v1(food: Food) -> Option<Food> {
4848
4949
// This can conveniently be rewritten more compactly with `and_then()`:
5050
fn cookable_v2(food: Food) -> Option<Food> {
51-
have_ingredients(food).and_then(have_recipe)
51+
have_recipe(food).and_then(have_ingredients)
5252
}
5353
5454
fn eat(food: Food, day: Day) {

0 commit comments

Comments
 (0)