Skip to content

Instantly share code, notes, and snippets.

@jadbox
Created May 17, 2016 21:53
Show Gist options
  • Save jadbox/8fed38ae730e8fb6a909edb9f6deae0c to your computer and use it in GitHub Desktop.
Save jadbox/8fed38ae730e8fb6a909edb9f6deae0c to your computer and use it in GitHub Desktop.
import most, {
create, of, from
}
from 'most';
function fromNodeCallback(fun) {
return (...x) => create((add, end, error) => {
x.push(handleNodeCB);
fun.apply(null, x);
});
}
function flatMapNode(fun) {
return this.flatMap(x =>
create((add, end, error) => {
fun(x, handleNodeCB);
})
);
}
function handleNodeCB(add, end, error) {
return (err, res) => {
if (err) error(err);
else {
add(res);
end();
}
};
}
module.exports = {
node: fromNodeCallback,
fromNodeCallback, // alias
bindNodeCallback: fromNodeCallback, // alias
flatMapNode,
chainNode: flatMapNode,
create,
of,
most,
from
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment