Skip to content

Commit

Permalink
Merge pull request #1127 from bartsmykla/small-fixes-error-option-unw…
Browse files Browse the repository at this point in the history
…rap-and-then

Fixed small logic error in error/option_unwrap/and_then
  • Loading branch information
frewsxcv authored Dec 16, 2018
2 parents 843cc35 + 6150bf7 commit 35a19ff
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/error/option_unwrap/and_then.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ fn have_recipe(food: Food) -> Option<Food> {
}
}
// To make a dish, we need both the ingredients and the recipe.
// To make a dish, we need both the recipe and the ingredients.
// We can represent the logic with a chain of `match`es:
fn cookable_v1(food: Food) -> Option<Food> {
match have_ingredients(food) {
match have_recipe(food) {
None => None,
Some(food) => match have_recipe(food) {
Some(food) => match have_ingredients(food) {
None => None,
Some(food) => Some(food),
},
Expand All @@ -48,7 +48,7 @@ fn cookable_v1(food: Food) -> Option<Food> {
// This can conveniently be rewritten more compactly with `and_then()`:
fn cookable_v2(food: Food) -> Option<Food> {
have_ingredients(food).and_then(have_recipe)
have_recipe(food).and_then(have_ingredients)
}
fn eat(food: Food, day: Day) {
Expand Down

0 comments on commit 35a19ff

Please sign in to comment.