Skip to content

Instantly share code, notes, and snippets.

@eyeccc
Last active July 9, 2018 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eyeccc/ecf0584199ec4f74cce9ae427a723337 to your computer and use it in GitHub Desktop.
Save eyeccc/ecf0584199ec4f74cce9ae427a723337 to your computer and use it in GitHub Desktop.
Customize operator in reasonml
open CustomizedOperator.Op; /* In order to use operator from another file. */
Js.Dict.empty()
>>= ((obj) => { Js.Dict.set(obj, "title", "myTitle"); obj}, 1 == 2)
>>= ((obj) => { Js.Dict.set(obj, "id", 123); obj}, true = true);
/*
Result will be:
{id: 123}
*/
module Op = {
let (>>=) = (obj, (func, cond)) => cond ? func(obj) : obj;
};
/* Inspired by: https://twitter.com/_astrocoders/status/1013466409156870147 */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment