Skip to content

Instantly share code, notes, and snippets.

@muadjb
Last active Sep 20, 2020
Embed
What would you like to do?
ReasonML binding to curried JS function
// add.js
const addU = (a, b) => a + b
const addC = a => b => a + b
module.exports = { addC, addU }
type returnedFunc = int => int;
type curriedFunc = int => returnedFunc;
[@bs.module "./add.js"] external addU: (int, int) => int = "addU";
[@bs.module "./add.js"] external addC: curriedFunc = "addC";
let addFive = addC(5);
Js.log(addFive); // [Function]
let result = addFive(10);
Js.log(result); // 15
Js.log(addU(4, 4)); // 8
Js.log(addC(2, 2)); // 4
const { addC, addU } = require('./add')
const addFive = addC(5)
console.log(addFive) // [Function]
const result = addFive(10)
console.log(result) // 15
console.log(addU(2, 2)) // 4
[@bs.module "./add.js"] external addU: (int, int) => int = "addU";
[@bs.module "./add.js"] external addC: (int, int) => int = "addC";
let addFive = addC(5);
Js.log(addFive); // [Function: addFive]
let result = addFive(10);
Js.log(result); // [Function]
Js.log(addU(4, 4)); // 8
Js.log(addC(2, 2)); // [Function]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment