This repository has been archived by the owner on Jul 25, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Merge pull request #10 from fantasyland/davidchambers/readme"
- Loading branch information
1 parent
7b7e89f
commit f1e38a2
Showing
4 changed files
with
115 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |