Skip to content
This repository has been archived by the owner on Jul 25, 2018. It is now read-only.

Commit

Permalink
Revert "Merge pull request #10 from fantasyland/davidchambers/readme"
Browse files Browse the repository at this point in the history
This reverts commit 7b7e89f, reversing
changes made to 2873043.
  • Loading branch information
SimonRichardson committed Jul 25, 2018
1 parent 7b7e89f commit f1e38a2
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules
10 changes: 0 additions & 10 deletions README.md

This file was deleted.

93 changes: 93 additions & 0 deletions index.js
@@ -0,0 +1,93 @@
function identity(a) {
return a;
}
exports.identity = identity;

function append(a, b) {
return a.concat(b);
}
exports.append = append;

function empty(m) {
return m.empty ? m.empty() : m.constructor.empty();
}
exports.empty = empty;

function map(m, f) {
if(m.map) return m.map(f);
return flatMap(m, function(a) {
return point(m, f(a));
});
}
exports.map = map;

function flatMap(m, f) {
return m.chain ? m.chain(f) : m.then(f);
}
exports.flatMap = flatMap;

function point(m, a) {
return m.of ? m.of(a) : m.constructor.of(a);
}
exports.point = point;

function join(m) {
return flatMap(m, identity);
}
exports.join = join;

function ap(a, f) {
if(f.ap) return f.ap(a);
return flatMap(f, function(f) {
return map(a, f);
});
}
exports.ap = ap;

function lift2(f, a, b) {
return ap(b, map(a, function(a) {
return function(b) {
return f(a, b);
};
}));
}
exports.lift2 = lift2;

function lift3(f, a, b, c) {
return ap(c, ap(b, map(a, function(a) {
return function(b) {
return function(c) {
return f(a, b, c);
};
};
})));
}
exports.lift3 = lift3;

function lift4(f, a, b, c, d) {
return ap(d, ap(c, ap(b, map(a, function(a) {
return function(b) {
return function(c) {
return function(d) {
return f(a, b, c, d);
};
};
};
}))));
}
exports.lift4 = lift4;

function lift5(f, a, b, c, d, e) {
return ap(e, ap(d, ap(c, ap(b, map(a, function(a) {
return function(b) {
return function(c) {
return function(d) {
return function(e) {
return f(a, b, c, d, e);
};
};
};
};
})))));
}
exports.lift5 = lift5;
21 changes: 21 additions & 0 deletions package.json
@@ -0,0 +1,21 @@
{
"name": "fantasy-sorcery",
"version": "0.0.1",
"description": "Common functions to work on Fantasy Land compatible structures.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/pufuwozu/fantasy-sorcery.git"
},
"keywords": [
"fantasyland",
"monad",
"functor"
],
"author": "Brian McKenna",
"license": "MIT",
"readmeFilename": "README.md"
}

0 comments on commit f1e38a2

Please sign in to comment.