From 6150bf7ddc7a7a74996328b6cf04692031d413b8 Mon Sep 17 00:00:00 2001 From: Bart Smykla Date: Sun, 16 Dec 2018 09:43:03 +0100 Subject: [PATCH] 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 --- src/error/option_unwrap/and_then.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/error/option_unwrap/and_then.md b/src/error/option_unwrap/and_then.md index aab95cac30..99d8133ac6 100644 --- a/src/error/option_unwrap/and_then.md +++ b/src/error/option_unwrap/and_then.md @@ -34,12 +34,12 @@ fn have_recipe(food: Food) -> Option { } } -// 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 { - 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), }, @@ -48,7 +48,7 @@ fn cookable_v1(food: Food) -> Option { // This can conveniently be rewritten more compactly with `and_then()`: fn cookable_v2(food: Food) -> Option { - have_ingredients(food).and_then(have_recipe) + have_recipe(food).and_then(have_ingredients) } fn eat(food: Food, day: Day) {