Use a Lodash function in ReasonML w/Interop
This is my attempt to get into javascript interop in ReasonML. Really, you probably have enough tools in ReasonML to avoid using any Lodash functions but I'm using it to learn.
[@bs.module "lodash"] external myMin : array('a) => 'a = "min";
let result = myMin([|1, 2, 3|]);
/* result is 1 */
The bs.module
syntax is not very well documented and a little obtuse.
[@bs.module "lodash"]
will turn into the require statement in JS.
external myMin
is where you name the function you'll be using in Reason.
array('a) => 'a
declares the type signature and return value.
= "min"
is where we declare what the function is on the javascript side.
There are some parentheses missing that might help you read and parse this differently. Here is what the same statement looks like with added parentheses.
[@bs.module("lodash")] external myMin : (array('a) => 'a) = "min";
Tweet