Skip to content

Commit 35a19ff

Browse files
authored
Merge pull request #1127 from bartsmykla/small-fixes-error-option-unwrap-and-then
Fixed small logic error in error/option_unwrap/and_then
2 parents 843cc35 + 6150bf7 commit 35a19ff

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/error/option_unwrap/and_then.md

+4-4
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)