Aug 8, 2017 · 1 min read
Interesting idea using functions as a composable datatypes. Ability to call a datatype as function opens-up the whole new world of possiblities. I would go even further and propose the use of fantasy-land specification for interoperability with ramda and ramda-adjunct.
This way we can use standard functions and lift them into moneysafe context. Let’s assume that moneysafe implements Applicative fantasy land specification. We can lift any existing function from ramda to work with moneysafe without need to define the logic again.
const { $ } = require('moneysafe');
const { sum, add, unapply } = require('ramda');
const { liftFN, liftF } = require('ramda-adjunct');
const a = $.of(1);
const b = $.of(2);
const c = $.of(3);
const sumM = (...args) => liftFN(args.length, unapply(sum))(...args);
const addM = liftF(add);
sumM(a, b, c); //=> $(6)
addM(a, b); //=> $(3)By implementing Semigroup fantasy-land specification we would be able to do the following:
const { $ } = require('moneysafe');
const { concat } = require('ramda');concat($.of(1), $.of(2)); //=> $(3)
And we can go on and on… Great job on the article!