Created
September 29, 2018 20:14
-
-
Save ENAML/7baf86f4ff6ae50d67a12bce9a70cb57 to your computer and use it in GitHub Desktop.
custom operators 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
/* | |
See: http://2ality.com/2017/12/functions-reasonml.html#operators | |
*/ | |
module MapOps { | |
module HashMap = Belt.HashMap.String; | |
let ( @@ ) = (map, key) => { | |
map | |
|> HashMap.get(_, key) | |
|> Belt.Option.getExn | |
}; | |
let ( @ ) = (map, key) => { | |
let setter = HashMap.set(map, key); | |
setter | |
}; | |
let ( =: ) = (setter, bval) => { | |
setter(bval); | |
}; | |
/* Test: */ | |
if (true) { | |
let m = HashMap.make(~hintSize = 10); | |
m @ "one" =: 1; | |
Js.log(m@@"one"); | |
Js.log(m@@"two"); | |
let r = ref(1); | |
r := 2; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment