Skip to content

Instantly share code, notes, and snippets.

@ENAML
Created September 29, 2018 20:14
Show Gist options
  • Save ENAML/7baf86f4ff6ae50d67a12bce9a70cb57 to your computer and use it in GitHub Desktop.
Save ENAML/7baf86f4ff6ae50d67a12bce9a70cb57 to your computer and use it in GitHub Desktop.
custom operators in ReasonML
/*
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