Created
September 30, 2019 13:53
-
-
Save arnarthor/e5364d44df58442aa1c112ac814f6796 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Belt; | |
let randomlyFailedPromise = () => { | |
let random = Js.Math.random(); | |
Js.Promise.make((~resolve, ~reject as _) => | |
resolve(. | |
if (random > 0.5) { | |
Result.Error(`NumberToHigh); | |
} else { | |
Result.Ok(random); | |
}, | |
) | |
); | |
}; | |
let addTwo = a => a +. 2.; | |
let checkIfNumberIsBiggerThanTwoPointSeven = a => | |
if (a > 2.7) { | |
Result.Ok(a); | |
} else { | |
Result.Error(`NumberToLow); | |
}; | |
let logNumber = a => Js.log(a); | |
let multiplyByFour = a => a *. 4.; | |
/* Try to run a randomlyFailedPromise | |
if it succeeds addTwo | |
check if the number is bigger than two point seven | |
if it is multiply it by four | |
and then log your final result given that it's sucessful | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment