Skip to content

Instantly share code, notes, and snippets.

@arnarthor
Created September 30, 2019 13:53
Show Gist options
  • Save arnarthor/e5364d44df58442aa1c112ac814f6796 to your computer and use it in GitHub Desktop.
Save arnarthor/e5364d44df58442aa1c112ac814f6796 to your computer and use it in GitHub Desktop.
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