
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
reason-maybe
Advanced tools
A simple Maybe library in Reason.
yarn add reason-maybe.reason-maybe to your bs-dependencies in bsconfig.jsonbsconfig.json
"bs-dependencies": [
"reason-maybe"
]
fromTo create a Maybe use Maybe.from:
let one = Maybe.from(Some(1)); /* Just(1) */
mapTo map a function on the Maybe, use Maybe.map:
let plusOne = x => x + 1;
let onePlusOne = one |> Maybe.map(plusOne); /* Just(2) */
Alternatively, you can import the equivalent infix operator ||>:
let (||>) = Maybe.(||>);
let onePlusOne = one ||> plusOne; /* Just(2) */
If the map operation provides a value, it will return Just(value). Else, it will return a Nothing.
valueTo extract the value of the Maybe, we need to use Maybe.value:
let value = onePlusOne |> Maybe.value(0); /* 2 */
Alternatively, you can import the equivalent infix operator >|:
let (>|) = Maybe.(>|);
let value = onePlusOne >| 0; /* 2 */
If the Maybe was actually a Nothing, the value given to the Maybe.value function will be the resulting value.
In this case if onePlusOne was Nothing, the value of value would be 0.
chainTo run a function that returns a Maybe on a Maybe, we use Maybe.chain:
let two = Maybe.from(Some(2));
let plusOneMaybe = x => one |> Maybe.map(y => x + y);
let twoPlusOneMaybe = two |> Maybe.chain(plusOneMaybe); /* Just(3) */
Alternatively, you can import the equivalent infix operator |||>:
let (|||>) = Maybe.(|||>);
let twoPlusOneMaybe = two |||> plusOneMaybe; /* Just(3) */
We use the plusOneMaybe function which returns a Maybe on the two Maybe.
Instead of Maybe.map, we use Maybe.chain to lift it from the returned Maybe unto the current Maybe.
branchIf the Maybe has turned into a Nothing and you want to handle that, you can use Maybe.branch:
let addToRoute = s => x =>
switch s {
| "" => Maybe.Nothing
| v => Maybe.Just(x ++ v)
}
;
let noslug = () => "/not_found";
let hasslug = v => v
let getArticleRoute = slug => Maybe.from(Some("/articles/"))
|> Maybe.chain(addToRoute(slug))
|> Maybe.branch(noslug, hasslug)
|> Maybe.value("/articles");
let validArticleRoute = getArticleRoute("awesome");
Js.log(validArticleRoute); /* /articles/awesome */
let invalidArticleRoute = getArticleRoute("");
Js.log(invalidArticleRoute); /* /not_found */
Alternatively, you can import the equivalent infix operator <->:
let (<->) = Maybe.(<->);
let (|||>) = Maybe.(|||>);
let (>|) = Maybe.(>|);
/* Previously defined functions here */
let getArticleRoute = slug =>
Maybe.from(Some("/articles/"))
|||> addToRoute(slug)
|> (noslug <-> hasslug)
>| "/articles"
;
let validArticleRoute = getArticleRoute("awesome");
Js.log(validArticleRoute); /* /articles/awesome */
let invalidArticleRoute = getArticleRoute("");
Js.log(invalidArticleRoute); /* /not_found */
This form is less readable but more terse yields the same result.
cd reason-maybe.yarn.npm run build
npm run start
MIT
FAQs
A simple Maybe library in Reason.
We found that reason-maybe demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.