Last active
July 9, 2018 09:47
-
-
Save eyeccc/ecf0584199ec4f74cce9ae427a723337 to your computer and use it in GitHub Desktop.
Customize operator in reasonml
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 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} | |
*/ |
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
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