Context
I'm trying to understand the problematic that monades try to solve and I'm a bit confused while trying to compose a container and a promise.
Example
For the purpose of the exercise, I've modified the chain method of my monad to a then, so that I can compose promises with my custom container:
const assert = require("assert");
const R = require("ramda");
const makeMonad = value => ({
get: () => value,
map: transform => makeMonad(transform(value)),
then: createMonad => makeMonad(createMonad(value).get())
});
const asyncAdd2 = x => Promise.resolve(x + 2);
const composeP = R.composeWith((f, last) => last.then(f));
const asyncResult = composeP([asyncAdd2, makeMonad])(1);
asyncResult.then(x => assert.equal(x, 3));
console.log("Passed");
In this example, I have an error thrown because the Promise API doesn't own a get function. In fact, I need this get function in my custom then function to allow composability.
So at the end of the application execution, depending on the order of my arguments in the composeWith call, I'm in a promise world or in a custom monad world.
Questions
I m now wondering if I have to lift everything (even promises?) while I'm working and trying to compose monades?
What is the impact if I'm working with 10 kind of different monades? I mean, depending on the order, I'll probably change the world I'm working on no?
Is this something common to create monades creators? I mean creating the monade definition like the
makeMonadI've written
Thanks for your help, I hope I've been clear ^^'