From eb34020b8e9e10914628fbc62dc9f2debdce1d64 Mon Sep 17 00:00:00 2001 From: Justine Mignot Date: Fri, 13 May 2022 14:04:01 +0200 Subject: [PATCH] Add exercice about 'if' (#40) * :sparkles: add bonus (about if) in exo1 * :recycle: improve bonus * :fire: remove not clear exercice * :recycle: better bonus explanations * :recycle: spaces --- src/exo1/exo1.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/exo1/exo1.ts b/src/exo1/exo1.ts index 0442bd7..08ec470 100644 --- a/src/exo1/exo1.ts +++ b/src/exo1/exo1.ts @@ -27,6 +27,17 @@ export const divide = (a: number, b: number): number => { export const safeDivide: (a: number, b: number) => Option = unimplemented; + +// You probably wrote `safeDivide` using `if` statements and it's perfectly valid! +// There are ways to not use `if` statements. +// Keep in mind that extracting small functions out of pipes and using `if` statements in them +// is perfectly fine and is sometimes more readable than not using `if`. +// +// BONUS: Try now to re-write `safeDivide` without any `if` +// +// HINT: Have a look at `fromPredicate` constructor + + /////////////////////////////////////////////////////////////////////////////// // EITHER // ///////////////////////////////////////////////////////////////////////////////