Skip to content

Instantly share code, notes, and snippets.

@vmarcosp
Last active January 13, 2020 00:01
Show Gist options
  • Save vmarcosp/65d4cd0290f2c17f4b941fcceaee8cbd to your computer and use it in GitHub Desktop.
Save vmarcosp/65d4cd0290f2c17f4b941fcceaee8cbd to your computer and use it in GitHub Desktop.
open Belt;
let person = Js.Nullable.return({ "name": "marcos"})->Js.Nullable.toOption;
person
->Option.map(person => person##name)
-> Option.getWithDefault("");
let (>=) = (maybe, func) => maybe->Option.map(func);
let (>?) = (maybe, defaultValue) => maybe->Option.getWithDefault(defaultValue);
let name = person
>= (person => person##name)
>? "nulo";
let name = person
>= (person => person##name)
>? "nulo";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment