Comparing version 3.0.1 to 3.0.2
88
adt.js
@@ -1,43 +0,25 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.tag = tag; | ||
exports.union = union; | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
// symbol :: Symbol | ||
var symbol = exports.symbol = Symbol('ADT.tag'); | ||
const symbol = Symbol('ADT.tag'); | ||
function tag(type) { | ||
for (var _len = arguments.length, params = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
params[_key - 1] = arguments[_key]; | ||
} | ||
function tag(type, ...params) { | ||
// Store the constructor on a temporary object so that | ||
// the constructor name will correctly match the type. | ||
var tmp = _defineProperty({}, type, function () { | ||
var _this = this; | ||
let tmp = { | ||
// eslint-disable-next-line object-shorthand, func-names, consistent-return | ||
[type]: function (...args) { | ||
// Call new here so the consumer doesn't have to. | ||
if (!(this instanceof Adt)) { | ||
return new Adt(...args); | ||
} | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
// Set all instance variables. | ||
params.forEach((param, idx) => { | ||
this[param] = args[idx]; | ||
}); | ||
}, | ||
}; | ||
// Call new here so the consumer doesn't have to. | ||
if (!(this instanceof Adt)) { | ||
return new (Function.prototype.bind.apply(Adt, [null].concat(args)))(); | ||
} | ||
// Set all instance variables. | ||
params.forEach(function (param, idx) { | ||
_this[param] = args[idx]; | ||
}); | ||
}); | ||
// Retrieve the constructor and send the temporary object to GC. | ||
var Adt = tmp[type]; | ||
const Adt = tmp[type]; | ||
tmp = null; | ||
@@ -49,10 +31,9 @@ | ||
Adt.prototype.toString = function toString() { | ||
var _this2 = this; | ||
const paramsList = params | ||
.map(param => this[param]) | ||
.join(', ') | ||
.trim(); | ||
var paramsList = params.map(function (param) { | ||
return _this2[param]; | ||
}).join(', ').trim(); | ||
var paramDisplay = params.length ? '(' + paramsList + ')' : ''; | ||
return '' + this[symbol] + paramDisplay; | ||
const paramDisplay = params.length ? `(${paramsList})` : ''; | ||
return `${this[symbol]}${paramDisplay}`; | ||
}; | ||
@@ -65,13 +46,13 @@ | ||
// Create the parent type. | ||
var Parent = tag(parentType); | ||
const Parent = tag(parentType); | ||
Object.keys(childTypes).forEach(function (childType) { | ||
Object.keys(childTypes).forEach((childType) => { | ||
// Get any params defined for the child. | ||
var params = childTypes[childType]; | ||
const params = childTypes[childType]; | ||
// Tag the child object. | ||
var Child = tag.apply(undefined, [childType].concat(_toConsumableArray(params))); | ||
const Child = tag(childType, ...params); | ||
// Inherit from the parent type. | ||
var ogProto = Child.prototype; | ||
const ogProto = Child.prototype; | ||
Child.prototype = Object.create(Parent.prototype); | ||
@@ -84,7 +65,3 @@ Child.prototype.constructor = Child; | ||
Child.prototype.cata = function cata(cases) { | ||
var _this3 = this; | ||
return cases[childType].apply(cases, _toConsumableArray(params.map(function (p) { | ||
return _this3[p]; | ||
}))); | ||
return cases[childType](...params.map(p => this[p])); | ||
}; | ||
@@ -98,2 +75,9 @@ | ||
return Parent; | ||
} | ||
} | ||
module.exports = { | ||
symbol, | ||
tag, | ||
union, | ||
}; |
69
core.js
@@ -1,53 +0,32 @@ | ||
'use strict'; | ||
const { curry } = require('./_tools'); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.andThen = exports.caseOf = exports.cata = exports.liftA4 = exports.liftA3 = exports.liftA2 = undefined; | ||
var _curry = require('ramda/src/curry'); | ||
var _curry2 = _interopRequireDefault(_curry); | ||
var _invoker = require('ramda/src/invoker'); | ||
var _invoker2 = _interopRequireDefault(_invoker); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
// liftA2 :: Monad m => (a -> b -> c) -> m a -> m b -> m c | ||
var liftA2 = exports.liftA2 = (0, _curry2.default)(function (callback, a1, a2) { | ||
return a1.chain(function (a) { | ||
return a2.map(function (b) { | ||
return callback(a, b); | ||
}); | ||
}); | ||
}); | ||
exports.liftA2 = curry((callback, a1, a2) => | ||
a1.chain(a => | ||
a2.map(b => | ||
callback(a, b)))); | ||
// liftA3 :: Monad m => (a -> b -> c -> d) -> m a -> m b -> m c -> m d | ||
var liftA3 = exports.liftA3 = (0, _curry2.default)(function (callback, a1, a2, a3) { | ||
return a1.chain(function (a) { | ||
return a2.chain(function (b) { | ||
return a3.map(function (c) { | ||
return callback(a, b, c); | ||
}); | ||
}); | ||
}); | ||
}); | ||
exports.liftA3 = curry((callback, a1, a2, a3) => | ||
a1.chain(a => | ||
a2.chain(b => | ||
a3.map(c => | ||
callback(a, b, c))))); | ||
// liftA3 :: Monad m => (a -> b -> c -> d -> e) -> m a -> m b -> m c -> m d -> m e | ||
var liftA4 = exports.liftA4 = (0, _curry2.default)(function (callback, a1, a2, a3, a4) { | ||
return a1.chain(function (a) { | ||
return a2.chain(function (b) { | ||
return a3.chain(function (c) { | ||
return a4.map(function (d) { | ||
return callback(a, b, c, d); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
exports.liftA4 = curry((callback, a1, a2, a3, a4) => | ||
a1.chain(a => | ||
a2.chain(b => | ||
a3.chain(c => | ||
a4.map(d => | ||
callback(a, b, c, d)))))); | ||
var cata = exports.cata = (0, _invoker2.default)(1, 'cata'); | ||
var caseOf = exports.caseOf = (0, _invoker2.default)(1, 'caseOf'); | ||
var andThen = exports.andThen = (0, _invoker2.default)(1, 'andThen'); | ||
exports.cata = curry((arg, object) => | ||
object.cata(arg)); | ||
exports.caseOf = curry((arg, object) => | ||
object.caseOf(arg)); | ||
exports.andThen = curry((arg, object) => | ||
object.andThen(arg)); |
131
either.js
@@ -1,30 +0,13 @@ | ||
'use strict'; | ||
const FL = require('fantasy-land'); | ||
var _fantasyLand = require('fantasy-land'); | ||
const { union } = require('./adt'); | ||
const { always, curry, compose } = require('./_tools'); | ||
var _fantasyLand2 = _interopRequireDefault(_fantasyLand); | ||
var _curry = require('ramda/src/curry'); | ||
var _curry2 = _interopRequireDefault(_curry); | ||
var _always = require('ramda/src/always'); | ||
var _always2 = _interopRequireDefault(_always); | ||
var _compose = require('ramda/src/compose'); | ||
var _compose2 = _interopRequireDefault(_compose); | ||
var _adt = require('./adt'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var Either = (0, _adt.union)('Either', { | ||
const Either = union('Either', { | ||
Right: ['value'], | ||
Left: ['value'] | ||
Left: ['value'], | ||
}); | ||
var Left = Either.Left, | ||
Right = Either.Right; | ||
const { Left, Right } = Either; | ||
@@ -38,24 +21,19 @@ /* | ||
// of :: b -> Either a b | ||
Either.of = value => | ||
Right(value); | ||
Either.of = function (value) { | ||
return Right(value); | ||
}; | ||
// of :: b -> Either a b | ||
Right.of = function (value) { | ||
return Right(value); | ||
}; | ||
Right.of = value => | ||
Right(value); | ||
// of :: a -> Either a b | ||
Left.of = function (value) { | ||
return Left(value); | ||
}; | ||
Left.of = value => | ||
Left(value); | ||
// chain :: (b -> Either a c) -> Either a b -> Either a c | ||
Either.chain = (0, _curry2.default)(function (transform, either) { | ||
return either.cata({ | ||
Left: (0, _always2.default)(either), | ||
Right: transform | ||
}); | ||
}); | ||
Either.chain = curry((transform, either) => | ||
either.cata({ | ||
Left: always(either), | ||
Right: transform, | ||
})); | ||
@@ -66,8 +44,7 @@ // andThen :: (b -> Either a c) -> Either a b -> Either a c | ||
// map :: (b -> c) -> Either a b -> Either a c | ||
Either.map = (0, _curry2.default)(function (transform, either) { | ||
return Either.chain((0, _compose2.default)(Right, transform), either); | ||
}); | ||
Either.map = curry((transform, either) => | ||
Either.chain(compose(Right, transform), either)); | ||
// ap :: Apply (b -> c) -> Either a b -> Either a c | ||
Either.ap = (0, _curry2.default)(function (left, right) { | ||
Either.ap = curry((left, right) => { | ||
if (left.isLeft() && right.isLeft()) return right; | ||
@@ -81,21 +58,16 @@ if (left.isLeft()) return left; | ||
// isLeft :: Either a b -> Bool | ||
Either.isLeft = function (either) { | ||
return either instanceof Left; | ||
}; | ||
Either.isLeft = either => either instanceof Left; | ||
// isRight :: Either a b -> Bool | ||
Either.isRight = function (either) { | ||
return either instanceof Right; | ||
}; | ||
Either.isRight = either => either instanceof Right; | ||
Either.try = function (callback) { | ||
return function () { | ||
try { | ||
return Right(callback.apply(undefined, arguments)); | ||
} catch (e) { | ||
return Left(e); | ||
} | ||
}; | ||
Either.try = callback => (...args) => { | ||
try { | ||
return Right(callback(...args)); | ||
} catch (e) { | ||
return Left(e); | ||
} | ||
}; | ||
/* | ||
@@ -108,15 +80,12 @@ |------------------------------------------------------------------------------ | ||
// of :: Either a b ~> d -> Either c d | ||
Either.prototype.of = function (value) { | ||
return Right(value); | ||
}; | ||
Either.prototype.of = value => | ||
Right(value); | ||
// of :: Either a b ~> d -> Either c d | ||
Right.prototype.of = function (value) { | ||
return Right(value); | ||
}; | ||
Right.prototype.of = value => | ||
Right(value); | ||
// of :: Either a b ~> c -> Either c d | ||
Left.prototype.of = function (value) { | ||
return Left(value); | ||
}; | ||
Left.prototype.of = value => | ||
Left(value); | ||
@@ -158,2 +127,3 @@ // caseOf :: Either a b ~> { Left: a -> c, Right: b -> c } -> c | ||
/* | ||
@@ -166,25 +136,28 @@ |------------------------------------------------------------------------------ | ||
// Either Applicative | ||
Either[_fantasyLand2.default.of] = Either.of; | ||
Either.prototype[_fantasyLand2.default.of] = Either.prototype.of; | ||
Either[FL.of] = Either.of; | ||
Either.prototype[FL.of] = Either.prototype.of; | ||
// Either Chain | ||
Either[_fantasyLand2.default.chain] = Either.chain; | ||
Either.prototype[_fantasyLand2.default.chain] = Either.prototype.chain; | ||
Either[FL.chain] = Either.chain; | ||
Either.prototype[FL.chain] = Either.prototype.chain; | ||
// Either Functor | ||
Either[_fantasyLand2.default.map] = Either.map; | ||
Either.prototype[_fantasyLand2.default.map] = Either.prototype.map; | ||
Either[FL.map] = Either.map; | ||
Either.prototype[FL.map] = Either.prototype.map; | ||
// Either Apply | ||
Either[_fantasyLand2.default.ap] = Either.ap; | ||
Either.prototype[_fantasyLand2.default.ap] = Either.prototype.ap; | ||
Either[FL.ap] = Either.ap; | ||
Either.prototype[FL.ap] = Either.prototype.ap; | ||
// Right Applicative | ||
Right[_fantasyLand2.default.of] = Right.of; | ||
Right.prototype[_fantasyLand2.default.of] = Right.prototype.of; | ||
Right[FL.of] = Right.of; | ||
Right.prototype[FL.of] = Right.prototype.of; | ||
// Left Applicative | ||
Left[_fantasyLand2.default.of] = Left.of; | ||
Left.prototype[_fantasyLand2.default.of] = Left.prototype.of; | ||
Left[FL.of] = Left.of; | ||
Left.prototype[FL.of] = Left.prototype.of; | ||
module.exports = Either; | ||
module.exports = Either; |
83
index.js
@@ -1,71 +0,12 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.Writer = exports.Validation = exports.Tuple = exports.Task = exports.Result = exports.RemoteData = exports.Reader = exports.Maybe = exports.IO = exports.Either = exports.core = exports.ADT = undefined; | ||
var _adt = require('./adt'); | ||
var ADT = _interopRequireWildcard(_adt); | ||
var _core = require('./core'); | ||
var core = _interopRequireWildcard(_core); | ||
var _either = require('./either'); | ||
var _either2 = _interopRequireDefault(_either); | ||
var _io = require('./io'); | ||
var _io2 = _interopRequireDefault(_io); | ||
var _maybe = require('./maybe'); | ||
var _maybe2 = _interopRequireDefault(_maybe); | ||
var _reader = require('./reader'); | ||
var _reader2 = _interopRequireDefault(_reader); | ||
var _remoteData = require('./remote-data'); | ||
var _remoteData2 = _interopRequireDefault(_remoteData); | ||
var _result = require('./result'); | ||
var _result2 = _interopRequireDefault(_result); | ||
var _task = require('./task'); | ||
var _task2 = _interopRequireDefault(_task); | ||
var _tuple = require('./tuple'); | ||
var _tuple2 = _interopRequireDefault(_tuple); | ||
var _validation = require('./validation'); | ||
var _validation2 = _interopRequireDefault(_validation); | ||
var _writer = require('./writer'); | ||
var _writer2 = _interopRequireDefault(_writer); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
exports.ADT = ADT; | ||
exports.core = core; | ||
exports.Either = _either2.default; | ||
exports.IO = _io2.default; | ||
exports.Maybe = _maybe2.default; | ||
exports.Reader = _reader2.default; | ||
exports.RemoteData = _remoteData2.default; | ||
exports.Result = _result2.default; | ||
exports.Task = _task2.default; | ||
exports.Tuple = _tuple2.default; | ||
exports.Validation = _validation2.default; | ||
exports.Writer = _writer2.default; | ||
exports.ADT = require('./adt'); | ||
exports.core = require('./core'); | ||
exports.Either = require('./either'); | ||
exports.IO = require('./io'); | ||
exports.Maybe = require('./maybe'); | ||
exports.Reader = require('./reader'); | ||
exports.RemoteData = require('./remote-data'); | ||
exports.Result = require('./result'); | ||
exports.Task = require('./task'); | ||
exports.Tuple = require('./tuple'); | ||
exports.Validation = require('./validation'); | ||
exports.Writer = require('./writer'); |
66
io.js
@@ -1,21 +0,10 @@ | ||
'use strict'; | ||
const FL = require('fantasy-land'); | ||
var _fantasyLand = require('fantasy-land'); | ||
const { tag } = require('./adt'); | ||
const { __, curry } = require('./_tools'); | ||
var _fantasyLand2 = _interopRequireDefault(_fantasyLand); | ||
var _ = require('ramda/src/__'); | ||
const IO = tag('IO', 'run'); | ||
var _2 = _interopRequireDefault(_); | ||
var _curry = require('ramda/src/curry'); | ||
var _curry2 = _interopRequireDefault(_curry); | ||
var _adt = require('./adt'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var IO = (0, _adt.tag)('IO', 'run'); | ||
/* | ||
@@ -28,14 +17,8 @@ |------------------------------------------------------------------------------ | ||
// of :: a -> IO a | ||
IO.of = function (value) { | ||
return IO(function () { | ||
return value; | ||
}); | ||
}; | ||
IO.of = value => | ||
IO(() => value); | ||
// chain :: (a -> IO b) -> IO a -> IO b | ||
IO.chain = (0, _curry2.default)(function (transform, io) { | ||
return IO(function (env) { | ||
return transform(io.run(env)).run(env); | ||
}); | ||
}); | ||
IO.chain = curry((transform, io) => | ||
IO(env => transform(io.run(env)).run(env))); | ||
@@ -46,13 +29,10 @@ // andThen :: (a -> IO b) -> IO a -> IO b | ||
// map :: (a -> b) -> IO a -> IO b | ||
IO.map = (0, _curry2.default)(function (transform, io) { | ||
return IO.chain(function (x) { | ||
return IO.of(transform(x)); | ||
}, io); | ||
}); | ||
IO.map = curry((transform, io) => | ||
IO.chain(x => IO.of(transform(x)), io)); | ||
// ap :: Apply (a -> b) -> IO a -> IO b | ||
IO.ap = (0, _curry2.default)(function (apply, io) { | ||
return IO.chain(IO.map(_2.default, io), apply); | ||
}); | ||
IO.ap = curry((apply, io) => | ||
IO.chain(IO.map(__, io), apply)); | ||
/* | ||
@@ -87,2 +67,3 @@ |------------------------------------------------------------------------------ | ||
/* | ||
@@ -95,17 +76,18 @@ |------------------------------------------------------------------------------ | ||
// IO Applicative | ||
IO[_fantasyLand2.default.of] = IO.of; | ||
IO.prototype[_fantasyLand2.default.of] = IO.prototype.of; | ||
IO[FL.of] = IO.of; | ||
IO.prototype[FL.of] = IO.prototype.of; | ||
// IO Chain | ||
IO[_fantasyLand2.default.chain] = IO.chain; | ||
IO.prototype[_fantasyLand2.default.chain] = IO.prototype.chain; | ||
IO[FL.chain] = IO.chain; | ||
IO.prototype[FL.chain] = IO.prototype.chain; | ||
// IO Functor | ||
IO[_fantasyLand2.default.map] = IO.map; | ||
IO.prototype[_fantasyLand2.default.map] = IO.prototype.map; | ||
IO[FL.map] = IO.map; | ||
IO.prototype[FL.map] = IO.prototype.map; | ||
// IO Apply | ||
IO[_fantasyLand2.default.ap] = IO.ap; | ||
IO.prototype[_fantasyLand2.default.ap] = IO.prototype.ap; | ||
IO[FL.ap] = IO.ap; | ||
IO.prototype[FL.ap] = IO.prototype.ap; | ||
module.exports = IO; | ||
module.exports = IO; |
107
maybe.js
@@ -1,35 +0,16 @@ | ||
'use strict'; | ||
const FL = require('fantasy-land'); | ||
var _fantasyLand = require('fantasy-land'); | ||
const { union } = require('./adt'); | ||
const { __, curry, always, compose } = require('./_tools'); | ||
var _fantasyLand2 = _interopRequireDefault(_fantasyLand); | ||
var _ = require('ramda/src/__'); | ||
var _2 = _interopRequireDefault(_); | ||
var _curry = require('ramda/src/curry'); | ||
var _curry2 = _interopRequireDefault(_curry); | ||
var _always = require('ramda/src/always'); | ||
var _always2 = _interopRequireDefault(_always); | ||
var _compose = require('ramda/src/compose'); | ||
var _compose2 = _interopRequireDefault(_compose); | ||
var _adt = require('./adt'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var Maybe = (0, _adt.union)('Maybe', { | ||
const Maybe = union('Maybe', { | ||
Just: ['value'], | ||
Nothing: [] | ||
Nothing: [], | ||
}); | ||
var Just = Maybe.Just; | ||
var Nothing = Maybe.Nothing; | ||
const Just = Maybe.Just; | ||
const Nothing = Maybe.Nothing; | ||
/* | ||
@@ -57,8 +38,7 @@ |------------------------------------------------------------------------------ | ||
// chain :: (a -> Maybe b) -> Maybe a -> Maybe b | ||
Maybe.chain = (0, _curry2.default)(function (transform, maybe) { | ||
return maybe.cata({ | ||
Nothing: (0, _always2.default)(maybe), | ||
Just: transform | ||
}); | ||
}); | ||
Maybe.chain = curry((transform, maybe) => | ||
maybe.cata({ | ||
Nothing: always(maybe), | ||
Just: transform, | ||
})); | ||
@@ -69,23 +49,17 @@ // andThen :: (a -> Maybe b) -> Maybe a -> Maybe b | ||
// map :: (a -> b) -> Maybe a -> Maybe b | ||
Maybe.map = (0, _curry2.default)(function (transform, maybe) { | ||
return Maybe.chain((0, _compose2.default)(Maybe.of, transform), maybe); | ||
}); | ||
Maybe.map = curry((transform, maybe) => | ||
Maybe.chain(compose(Maybe.of, transform), maybe)); | ||
// ap :: Apply (a -> b) -> Maybe a -> Maybe b | ||
Maybe.ap = (0, _curry2.default)(function (left, right) { | ||
return Maybe.chain(Maybe.map(_2.default, right), left); | ||
}); | ||
Maybe.ap = curry((left, right) => | ||
Maybe.chain(Maybe.map(__, right), left)); | ||
// isNothing :: Maybe a -> Bool | ||
Maybe.isNothing = function (maybe) { | ||
return maybe === Maybe.Nothing; | ||
}; | ||
Maybe.isNothing = maybe => maybe === Maybe.Nothing; | ||
// isJust :: Maybe a -> Bool | ||
Maybe.isJust = function (maybe) { | ||
return maybe instanceof Maybe.Just; | ||
}; | ||
Maybe.isJust = maybe => maybe instanceof Maybe.Just; | ||
// fromNullable :: a -> Maybe a | ||
Maybe.fromNullable = function (value) { | ||
Maybe.fromNullable = (value) => { | ||
if (value === null || value === undefined) { | ||
@@ -99,13 +73,9 @@ return Maybe.Nothing; | ||
// withDefault :: a -> Maybe a -> a | ||
Maybe.withDefault = (0, _curry2.default)(function (defaultValue, maybe) { | ||
return maybe.cata({ | ||
Just: function Just(value) { | ||
return value; | ||
}, | ||
Nothing: function Nothing() { | ||
return defaultValue; | ||
} | ||
}); | ||
}); | ||
Maybe.withDefault = curry((defaultValue, maybe) => | ||
maybe.cata({ | ||
Just: value => value, | ||
Nothing: () => defaultValue, | ||
})); | ||
/* | ||
@@ -162,2 +132,3 @@ |------------------------------------------------------------------------------ | ||
/* | ||
@@ -170,23 +141,25 @@ |------------------------------------------------------------------------------ | ||
// Maybe Applicative | ||
Maybe[_fantasyLand2.default.of] = Maybe.of; | ||
Maybe[FL.of] = Maybe.of; | ||
// Maybe Chain | ||
Maybe[_fantasyLand2.default.chain] = Maybe.chain; | ||
Maybe.prototype[_fantasyLand2.default.chain] = Maybe.prototype.chain; | ||
Maybe[FL.chain] = Maybe.chain; | ||
Maybe.prototype[FL.chain] = Maybe.prototype.chain; | ||
// Maybe Functor | ||
Maybe[_fantasyLand2.default.map] = Maybe.map; | ||
Maybe.prototype[_fantasyLand2.default.map] = Maybe.prototype.map; | ||
Maybe[FL.map] = Maybe.map; | ||
Maybe.prototype[FL.map] = Maybe.prototype.map; | ||
// Maybe Apply | ||
Maybe[_fantasyLand2.default.ap] = Maybe.ap; | ||
Maybe.prototype[_fantasyLand2.default.ap] = Maybe.prototype.ap; | ||
Maybe[FL.ap] = Maybe.ap; | ||
Maybe.prototype[FL.ap] = Maybe.prototype.ap; | ||
// Just Applicative | ||
Maybe.Just[_fantasyLand2.default.of] = Maybe.Just.of; | ||
Maybe.Just.prototype[_fantasyLand2.default.of] = Maybe.Just.prototype.of; | ||
Maybe.Just[FL.of] = Maybe.Just.of; | ||
Maybe.Just.prototype[FL.of] = Maybe.Just.prototype.of; | ||
// Nothing Applicative | ||
Maybe.Nothing[_fantasyLand2.default.of] = Maybe.Nothing.of; | ||
Maybe.Nothing[FL.of] = Maybe.Nothing.of; | ||
module.exports = Maybe; | ||
module.exports = Maybe; |
{ | ||
"name": "zoomjs", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "Helpful abstractions for functional programming in javascript.", | ||
"main": "index.js", | ||
"scripts": { | ||
"build:node": "bin/build:node", | ||
"build:browser": "bin/build:browser", | ||
"build": "bin/build", | ||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", | ||
@@ -18,22 +17,13 @@ "coverage": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", | ||
"devDependencies": { | ||
"babel-cli": "^6.24.1", | ||
"babel-core": "^6.25.0", | ||
"babel-loader": "^7.1.1", | ||
"babel-plugin-add-module-exports": "^0.2.1", | ||
"babel-preset-es2015": "^6.24.1", | ||
"bower": "^1.8.0", | ||
"conventional-changelog-cli": "^1.3.2", | ||
"coveralls": "^2.13.1", | ||
"coveralls": "^3.0.11", | ||
"eslint": "^3.19.0", | ||
"eslint-config-airbnb-base": "^11.2.0", | ||
"eslint-loader": "^1.8.0", | ||
"eslint-plugin-import": "^2.6.1", | ||
"ink-docstrap": "^1.3.0", | ||
"jest": "^20.0.4", | ||
"jsdoc": "^3.4.3", | ||
"webpack": "^3.0.0" | ||
"jest": "^25.3.0", | ||
"jsdoc": "^3.6.4" | ||
}, | ||
"dependencies": { | ||
"fantasy-land": "^3.3.0", | ||
"ramda": "^0.24.1" | ||
"fantasy-land": "^4.0.1" | ||
}, | ||
@@ -40,0 +30,0 @@ "repository": { |
130
reader.js
@@ -1,29 +0,10 @@ | ||
'use strict'; | ||
const FL = require('fantasy-land'); | ||
var _fantasyLand = require('fantasy-land'); | ||
const { tag, symbol } = require('./adt'); | ||
const { __, curry, always, compose } = require('./_tools'); | ||
var _fantasyLand2 = _interopRequireDefault(_fantasyLand); | ||
var _ = require('ramda/src/__'); | ||
const Reader = tag('Reader', 'run'); | ||
var _2 = _interopRequireDefault(_); | ||
var _curry = require('ramda/src/curry'); | ||
var _curry2 = _interopRequireDefault(_curry); | ||
var _always = require('ramda/src/always'); | ||
var _always2 = _interopRequireDefault(_always); | ||
var _compose = require('ramda/src/compose'); | ||
var _compose2 = _interopRequireDefault(_compose); | ||
var _adt = require('./adt'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var Reader = (0, _adt.tag)('Reader', 'run'); | ||
/* | ||
@@ -36,14 +17,8 @@ |------------------------------------------------------------------------------ | ||
// of :: a -> Reader e a | ||
Reader.of = function (value) { | ||
return Reader(function () { | ||
return value; | ||
}); | ||
}; | ||
Reader.of = value => | ||
Reader(() => value); | ||
// chain :: (a -> Reader e b) -> Reader e a -> Reader e b | ||
Reader.chain = (0, _curry2.default)(function (transform, reader) { | ||
return Reader(function (env) { | ||
return transform(reader.run(env)).run(env); | ||
}); | ||
}); | ||
Reader.chain = curry((transform, reader) => | ||
Reader(env => transform(reader.run(env)).run(env))); | ||
@@ -54,13 +29,10 @@ // andThen :: (a -> Reader e b) -> Reader e a -> Reader e b | ||
// map :: (a -> b) -> Reader e a -> Reader e b | ||
Reader.map = (0, _curry2.default)(function (transform, reader) { | ||
return Reader.chain(function (x) { | ||
return Reader.of(transform(x)); | ||
}, reader); | ||
}); | ||
Reader.map = curry((transform, reader) => | ||
Reader.chain(x => Reader.of(transform(x)), reader)); | ||
// ap :: Apply (a -> b) -> Reader e a -> Reader e b | ||
Reader.ap = (0, _curry2.default)(function (apply, reader) { | ||
return Reader.chain(Reader.map(_2.default, reader), apply); | ||
}); | ||
Reader.ap = curry((apply, reader) => | ||
Reader.chain(Reader.map(__, reader), apply)); | ||
/* | ||
@@ -95,2 +67,3 @@ |------------------------------------------------------------------------------ | ||
/* | ||
@@ -102,4 +75,4 @@ |------------------------------------------------------------------------------ | ||
Reader.T = function (M) { | ||
var ReaderT = (0, _adt.tag)('Reader[' + M[_adt.symbol] + ']', 'run'); | ||
Reader.T = (M) => { | ||
const ReaderT = tag(`Reader[${M[symbol]}]`, 'run'); | ||
@@ -113,19 +86,11 @@ // Static | ||
// lift :: Monad m => m a -> ReaderT e m a | ||
ReaderT.lift = (0, _compose2.default)(ReaderT, _always2.default); | ||
ReaderT.lift = compose(ReaderT, always); | ||
// of :: Monad m => a -> ReaderT e m a | ||
ReaderT.of = function (value) { | ||
return ReaderT(function () { | ||
return M.of(value); | ||
}); | ||
}; | ||
ReaderT.of = value => | ||
ReaderT(() => M.of(value)); | ||
// chain :: Monad m => (a -> ReaderT e m b) -> ReaderT e m a -> ReaderT e m b | ||
ReaderT.chain = (0, _curry2.default)(function (callback, readerT) { | ||
return ReaderT(function (e) { | ||
return readerT.run(e).chain(function (a) { | ||
return callback(a).run(e); | ||
}); | ||
}); | ||
}); | ||
ReaderT.chain = curry((callback, readerT) => | ||
ReaderT(e => readerT.run(e).chain(a => callback(a).run(e)))); | ||
@@ -136,15 +101,10 @@ // andThen :: Monad m => (a -> ReaderT e m b) -> ReaderT e m a -> ReaderT e m b | ||
// map :: Monad m => (a -> b) -> ReaderT e m a -> ReaderT e m b | ||
ReaderT.map = (0, _curry2.default)(function (callback, readerT) { | ||
return readerT.chain(function (x) { | ||
return ReaderT.of(callback(x)); | ||
}); | ||
}); | ||
ReaderT.map = curry((callback, readerT) => | ||
readerT.chain(x => ReaderT.of(callback(x)))); | ||
// ap :: Monad m => Apply (a -> b) -> ReaderT e m a -> ReaderT e m b | ||
ReaderT.ap = (0, _curry2.default)(function (apply, readerT) { | ||
return ReaderT(function (e) { | ||
return readerT.run(e).ap(apply.run(e)); | ||
}); | ||
}); | ||
ReaderT.ap = curry((apply, readerT) => | ||
ReaderT(e => readerT.run(e).ap(apply.run(e)))); | ||
// Instance | ||
@@ -176,17 +136,20 @@ // -------- | ||
// Static Monad | ||
ReaderT[_fantasyLand2.default.of] = ReaderT.of; | ||
ReaderT[_fantasyLand2.default.chain] = ReaderT.chain; | ||
ReaderT[_fantasyLand2.default.map] = ReaderT.map; | ||
ReaderT[_fantasyLand2.default.ap] = ReaderT.ap; | ||
ReaderT[FL.of] = ReaderT.of; | ||
ReaderT[FL.chain] = ReaderT.chain; | ||
ReaderT[FL.map] = ReaderT.map; | ||
ReaderT[FL.ap] = ReaderT.ap; | ||
// Instance Monad | ||
ReaderT.prototype[_fantasyLand2.default.of] = ReaderT.prototype.of; | ||
ReaderT.prototype[_fantasyLand2.default.chain] = ReaderT.prototype.chain; | ||
ReaderT.prototype[_fantasyLand2.default.map] = ReaderT.prototype.map; | ||
ReaderT.prototype[_fantasyLand2.default.ap] = ReaderT.prototype.ap; | ||
ReaderT.prototype[FL.of] = ReaderT.prototype.of; | ||
ReaderT.prototype[FL.chain] = ReaderT.prototype.chain; | ||
ReaderT.prototype[FL.map] = ReaderT.prototype.map; | ||
ReaderT.prototype[FL.ap] = ReaderT.prototype.ap; | ||
return ReaderT; | ||
}; | ||
/* | ||
@@ -199,17 +162,18 @@ |------------------------------------------------------------------------------ | ||
// Reader Applicative | ||
Reader[_fantasyLand2.default.of] = Reader.of; | ||
Reader.prototype[_fantasyLand2.default.of] = Reader.prototype.of; | ||
Reader[FL.of] = Reader.of; | ||
Reader.prototype[FL.of] = Reader.prototype.of; | ||
// Reader Chain | ||
Reader[_fantasyLand2.default.chain] = Reader.chain; | ||
Reader.prototype[_fantasyLand2.default.chain] = Reader.prototype.chain; | ||
Reader[FL.chain] = Reader.chain; | ||
Reader.prototype[FL.chain] = Reader.prototype.chain; | ||
// Reader Functor | ||
Reader[_fantasyLand2.default.map] = Reader.map; | ||
Reader.prototype[_fantasyLand2.default.map] = Reader.prototype.map; | ||
Reader[FL.map] = Reader.map; | ||
Reader.prototype[FL.map] = Reader.prototype.map; | ||
// Reader Apply | ||
Reader[_fantasyLand2.default.ap] = Reader.ap; | ||
Reader.prototype[_fantasyLand2.default.ap] = Reader.prototype.ap; | ||
Reader[FL.ap] = Reader.ap; | ||
Reader.prototype[FL.ap] = Reader.prototype.ap; | ||
module.exports = Reader; | ||
module.exports = Reader; |
@@ -13,7 +13,5 @@ # Zoom . js | ||
Zoom is a collection tools to help javascript developers write safe, reliable | ||
Zoom is a collection of tools to help javascript developers write safe, reliable | ||
code that is easy to read and easy to refactor. | ||
###### Zoom <3's [Fantasy Land JS](https://github.com/fantasyland/fantasy-land). | ||
--- | ||
@@ -47,4 +45,1 @@ #### Helpers | ||
`$ npm install --save zoomjs` | ||
##### bower | ||
`$ bower --save install zoom` |
@@ -1,39 +0,22 @@ | ||
'use strict'; | ||
const FL = require('fantasy-land'); | ||
var _fantasyLand = require('fantasy-land'); | ||
const { union } = require('./adt'); | ||
const { __, curry, always, compose } = require('./_tools'); | ||
var _fantasyLand2 = _interopRequireDefault(_fantasyLand); | ||
var _ = require('ramda/src/__'); | ||
var _2 = _interopRequireDefault(_); | ||
var _curry = require('ramda/src/curry'); | ||
var _curry2 = _interopRequireDefault(_curry); | ||
var _always = require('ramda/src/always'); | ||
var _always2 = _interopRequireDefault(_always); | ||
var _compose = require('ramda/src/compose'); | ||
var _compose2 = _interopRequireDefault(_compose); | ||
var _adt = require('./adt'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var RemoteData = (0, _adt.union)('RemoteData', { | ||
const RemoteData = union('RemoteData', { | ||
NotAsked: [], | ||
Loading: [], | ||
Failure: ['value'], | ||
Success: ['value'] | ||
Success: ['value'], | ||
}); | ||
var NotAsked = RemoteData.NotAsked, | ||
Loading = RemoteData.Loading, | ||
Failure = RemoteData.Failure, | ||
Success = RemoteData.Success; | ||
const { | ||
NotAsked, | ||
Loading, | ||
Failure, | ||
Success, | ||
} = RemoteData; | ||
/* | ||
@@ -45,10 +28,6 @@ |------------------------------------------------------------------------------ | ||
RemoteData.NotAsked.of = (0, _always2.default)(RemoteData.NotAsked); | ||
RemoteData.Loading.of = (0, _always2.default)(RemoteData.Loading); | ||
RemoteData.Success.of = function (v) { | ||
return Success(v); | ||
}; | ||
RemoteData.Failure.of = function (v) { | ||
return Failure(v); | ||
}; | ||
RemoteData.NotAsked.of = always(RemoteData.NotAsked); | ||
RemoteData.Loading.of = always(RemoteData.Loading); | ||
RemoteData.Success.of = v => Success(v); | ||
RemoteData.Failure.of = v => Failure(v); | ||
@@ -61,7 +40,4 @@ // of :: b -> RemoteData a b | ||
// chain :: (b -> RemoteData a c) -> RemoteData a b -> RemoteData a c | ||
RemoteData.chain = (0, _curry2.default)(function (callback, remote) { | ||
return (// eslint-disable-line no-confusing-arrow | ||
remote.isSuccess() ? callback(remote.value) : remote | ||
); | ||
}); | ||
RemoteData.chain = curry((callback, remote) => // eslint-disable-line no-confusing-arrow | ||
remote.isSuccess() ? callback(remote.value) : remote); | ||
@@ -72,13 +48,11 @@ // andThen :: (b -> RemoteData a c) -> RemoteData a b -> RemoteData a b | ||
// map :: (b -> c) -> RemoteData a b -> RemoteData a c | ||
RemoteData.map = (0, _curry2.default)(function (transform, maybe) { | ||
return RemoteData.chain((0, _compose2.default)(RemoteData.of, transform), maybe); | ||
}); | ||
RemoteData.map = curry((transform, remote) => | ||
RemoteData.chain(compose(RemoteData.of, transform), remote)); | ||
// ap :: Apply (b -> c) -> RemoteData a b -> RemoteData a c | ||
RemoteData.ap = (0, _curry2.default)(function (left, right) { | ||
return RemoteData.chain(RemoteData.map(_2.default, right), left); | ||
}); | ||
RemoteData.ap = curry((left, right) => | ||
RemoteData.chain(RemoteData.map(__, right), left)); | ||
// concat :: RemoteData e a -> RemoteData e a -> RemoteData e a | ||
RemoteData.concat = (0, _curry2.default)(function (left, right) { | ||
RemoteData.concat = curry((left, right) => { | ||
// Priority one | ||
@@ -100,28 +74,18 @@ if (left.isNotAsked()) return left; | ||
// isNotAsked :: RemoteData a b -> Bool | ||
RemoteData.isNotAsked = function (remote) { | ||
return remote === NotAsked; | ||
}; | ||
RemoteData.isNotAsked = remote => remote === NotAsked; | ||
// isLoading :: RemoteData a b -> Bool | ||
RemoteData.isLoading = function (remote) { | ||
return remote === Loading; | ||
}; | ||
RemoteData.isLoading = remote => remote === Loading; | ||
// isFailure :: RemoteData a b -> Bool | ||
RemoteData.isFailure = function (remote) { | ||
return remote instanceof Failure; | ||
}; | ||
RemoteData.isFailure = remote => remote instanceof Failure; | ||
// isSuccess :: RemoteData a b -> Bool | ||
RemoteData.isSuccess = function (remote) { | ||
return remote instanceof Success; | ||
}; | ||
RemoteData.isSuccess = remote => remote instanceof Success; | ||
// withDefault :: b -> RemoteData a b -> b | ||
RemoteData.withDefault = (0, _curry2.default)(function (defaultValue, remote) { | ||
return (// eslint-disable-line no-confusing-arrow | ||
remote.isSuccess() ? remote.value : defaultValue | ||
); | ||
}); | ||
RemoteData.withDefault = curry((defaultValue, remote) => // eslint-disable-line no-confusing-arrow | ||
remote.isSuccess() ? remote.value : defaultValue); | ||
/* | ||
@@ -193,2 +157,3 @@ |------------------------------------------------------------------------------ | ||
/* | ||
@@ -201,21 +166,22 @@ |------------------------------------------------------------------------------ | ||
// RemoteData Applicative | ||
RemoteData[_fantasyLand2.default.of] = RemoteData.of; | ||
RemoteData.prototype[_fantasyLand2.default.of] = RemoteData.prototype.of; | ||
RemoteData[FL.of] = RemoteData.of; | ||
RemoteData.prototype[FL.of] = RemoteData.prototype.of; | ||
// RemoteData Chain | ||
RemoteData[_fantasyLand2.default.chain] = RemoteData.chain; | ||
RemoteData.prototype[_fantasyLand2.default.chain] = RemoteData.prototype.chain; | ||
RemoteData[FL.chain] = RemoteData.chain; | ||
RemoteData.prototype[FL.chain] = RemoteData.prototype.chain; | ||
// RemoteData Functor | ||
RemoteData[_fantasyLand2.default.map] = RemoteData.map; | ||
RemoteData.prototype[_fantasyLand2.default.map] = RemoteData.prototype.map; | ||
RemoteData[FL.map] = RemoteData.map; | ||
RemoteData.prototype[FL.map] = RemoteData.prototype.map; | ||
// RemoteData Apply | ||
RemoteData[_fantasyLand2.default.ap] = RemoteData.ap; | ||
RemoteData.prototype[_fantasyLand2.default.ap] = RemoteData.prototype.ap; | ||
RemoteData[FL.ap] = RemoteData.ap; | ||
RemoteData.prototype[FL.ap] = RemoteData.prototype.ap; | ||
// RemoteData Semigroup | ||
RemoteData[_fantasyLand2.default.concat] = RemoteData.concat; | ||
RemoteData.prototype[_fantasyLand2.default.concat] = RemoteData.prototype.concat; | ||
RemoteData[FL.concat] = RemoteData.concat; | ||
RemoteData.prototype[FL.concat] = RemoteData.prototype.concat; | ||
module.exports = RemoteData; | ||
module.exports = RemoteData; |
@@ -1,34 +0,14 @@ | ||
'use strict'; | ||
const FL = require('fantasy-land'); | ||
var _fantasyLand = require('fantasy-land'); | ||
const { union } = require('./adt'); | ||
const { __, curry, always, compose } = require('./_tools'); | ||
var _fantasyLand2 = _interopRequireDefault(_fantasyLand); | ||
var _ = require('ramda/src/__'); | ||
var _2 = _interopRequireDefault(_); | ||
var _curry = require('ramda/src/curry'); | ||
var _curry2 = _interopRequireDefault(_curry); | ||
var _always = require('ramda/src/always'); | ||
var _always2 = _interopRequireDefault(_always); | ||
var _compose = require('ramda/src/compose'); | ||
var _compose2 = _interopRequireDefault(_compose); | ||
var _adt = require('./adt'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var Result = (0, _adt.union)('Result', { | ||
const Result = union('Result', { | ||
Ok: ['value'], | ||
Err: ['value'] | ||
Err: ['value'], | ||
}); | ||
var Ok = Result.Ok; | ||
var Err = Result.Err; | ||
const Ok = Result.Ok; | ||
const Err = Result.Err; | ||
@@ -57,8 +37,7 @@ /* | ||
// chain :: (b -> Result a c) -> Result a b -> Result a c | ||
Result.chain = (0, _curry2.default)(function (transform, result) { | ||
return result.cata({ | ||
Err: (0, _always2.default)(result), | ||
Ok: transform | ||
}); | ||
}); | ||
Result.chain = curry((transform, result) => | ||
result.cata({ | ||
Err: always(result), | ||
Ok: transform, | ||
})); | ||
@@ -69,21 +48,16 @@ // andThen :: (b -> Result a c) -> Result a b -> Result a c | ||
// map :: (b -> c) -> Result a b -> Result a c | ||
Result.map = (0, _curry2.default)(function (transform, result) { | ||
return Result.chain((0, _compose2.default)(Result.of, transform), result); | ||
}); | ||
Result.map = curry((transform, result) => | ||
Result.chain(compose(Result.of, transform), result)); | ||
// map :: Apply (b -> c) -> Result a b -> Result a c | ||
Result.ap = (0, _curry2.default)(function (left, right) { | ||
return Result.chain(Result.map(_2.default, right), left); | ||
}); | ||
Result.ap = curry((left, right) => | ||
Result.chain(Result.map(__, right), left)); | ||
// isErr :: Result a b -> Bool | ||
Result.isErr = function (result) { | ||
return result instanceof Result.Err; | ||
}; | ||
Result.isErr = result => result instanceof Result.Err; | ||
// isOk :: Result a b -> Bool | ||
Result.isOk = function (result) { | ||
return result instanceof Result.Ok; | ||
}; | ||
Result.isOk = result => result instanceof Result.Ok; | ||
/* | ||
@@ -147,24 +121,26 @@ |------------------------------------------------------------------------------ | ||
// Result Applicative | ||
Result[_fantasyLand2.default.of] = Result.of; | ||
Result[FL.of] = Result.of; | ||
// Result Chain | ||
Result[_fantasyLand2.default.chain] = Result.chain; | ||
Result.prototype[_fantasyLand2.default.chain] = Result.prototype.chain; | ||
Result[FL.chain] = Result.chain; | ||
Result.prototype[FL.chain] = Result.prototype.chain; | ||
// Result Functor | ||
Result[_fantasyLand2.default.map] = Result.map; | ||
Result.prototype[_fantasyLand2.default.map] = Result.prototype.map; | ||
Result[FL.map] = Result.map; | ||
Result.prototype[FL.map] = Result.prototype.map; | ||
// Result Apply | ||
Result[_fantasyLand2.default.ap] = Result.ap; | ||
Result.prototype[_fantasyLand2.default.ap] = Result.prototype.ap; | ||
Result[FL.ap] = Result.ap; | ||
Result.prototype[FL.ap] = Result.prototype.ap; | ||
// Ok Applicative | ||
Result.Ok[_fantasyLand2.default.of] = Result.Ok.of; | ||
Result.Ok.prototype[_fantasyLand2.default.of] = Result.Ok.prototype.of; | ||
Result.Ok[FL.of] = Result.Ok.of; | ||
Result.Ok.prototype[FL.of] = Result.Ok.prototype.of; | ||
// Err Applicative | ||
Result.Err[_fantasyLand2.default.of] = Result.Err.of; | ||
Result.Err.prototype[_fantasyLand2.default.of] = Result.Err.prototype.of; | ||
Result.Err[FL.of] = Result.Err.of; | ||
Result.Err.prototype[FL.of] = Result.Err.prototype.of; | ||
module.exports = Result; | ||
module.exports = Result; |
157
task.js
@@ -1,17 +0,10 @@ | ||
'use strict'; | ||
const FL = require('fantasy-land'); | ||
var _fantasyLand = require('fantasy-land'); | ||
const { tag } = require('./adt'); | ||
const { curry } = require('./_tools'); | ||
var _fantasyLand2 = _interopRequireDefault(_fantasyLand); | ||
var _curry = require('ramda/src/curry'); | ||
const Task = tag('Task', 'fork'); | ||
var _curry2 = _interopRequireDefault(_curry); | ||
var _adt = require('./adt'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var Task = (0, _adt.tag)('Task', 'fork'); | ||
/* | ||
@@ -24,28 +17,18 @@ |------------------------------------------------------------------------------ | ||
// of :: b -> Task a b | ||
Task.of = function (value) { | ||
return Task(function (_, resolve) { | ||
return resolve(value); | ||
}); | ||
}; | ||
Task.of = value => | ||
Task((_, resolve) => resolve(value)); | ||
// of :: a -> Task a b | ||
Task.reject = function (value) { | ||
return Task(function (reject) { | ||
return reject(value); | ||
}); | ||
}; | ||
Task.reject = value => | ||
Task(reject => reject(value)); | ||
// fork :: (a -> c) -> (b -> c) -> Task a b -> d | ||
Task.fork = (0, _curry2.default)(function (reject, resolve, task) { | ||
return task.fork(reject, resolve); | ||
}); | ||
Task.fork = curry((reject, resolve, task) => | ||
task.fork(reject, resolve)); | ||
// chain :: (b -> Task a c) -> Task a b -> Task a c | ||
Task.chain = (0, _curry2.default)(function (transform, task) { | ||
return Task(function (reject, resolve) { | ||
return task.fork(reject, function (value) { | ||
return transform(value).fork(reject, resolve); | ||
}); | ||
}); | ||
}); | ||
Task.chain = curry((transform, task) => | ||
Task((reject, resolve) => | ||
task.fork(reject, value => | ||
transform(value).fork(reject, resolve)))); | ||
@@ -56,45 +39,33 @@ // andThen :: (b -> Task a c) -> Task a b -> Task a c | ||
// map :: (b -> c) -> Task a b -> Task a c | ||
Task.map = (0, _curry2.default)(function (transform, task) { | ||
return Task.chain(function (x) { | ||
return Task.of(transform(x)); | ||
}, task); | ||
}); | ||
Task.map = curry((transform, task) => | ||
Task.chain(x => Task.of(transform(x)), task)); | ||
// ap :: Apply (b -> c) -> Task a b -> Task a c | ||
Task.ap = (0, _curry2.default)(function (apply, task) { | ||
return Task.chain(function (transform) { | ||
return task.map(transform); | ||
}, apply); | ||
}); | ||
Task.ap = curry((apply, task) => | ||
Task.chain(transform => task.map(transform), apply)); | ||
// toPromise :: Task a b -> Promise a b | ||
Task.toPromise = function (task) { | ||
var Promise = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : global.Promise; | ||
return new Promise(function (resolve, reject) { | ||
return task.fork(reject, resolve); | ||
}); | ||
}; | ||
Task.toPromise = (task, Promise = global.Promise) => | ||
new Promise((resolve, reject) => | ||
task.fork(reject, resolve)); | ||
// recover :: (a -> Task d c) -> Task a b -> Task d c | ||
Task.recover = (0, _curry2.default)(function (transform, task) { | ||
return Task(function (reject, resolve) { | ||
return task.fork(function (error) { | ||
return transform(error).fork(reject, resolve); | ||
}, resolve); | ||
}); | ||
}); | ||
Task.recover = curry((transform, task) => | ||
Task((reject, resolve) => | ||
task.fork(error => | ||
transform(error).fork(reject, resolve), resolve))); | ||
// parallel :: [Task a b] -> Task a [b] | ||
Task.parallel = function (tasks) { | ||
return Task(function (reject, resolve) { | ||
var remaining = tasks.length; | ||
var rejected = false; | ||
var rejectedError = void 0; | ||
Task.parallel = tasks => | ||
Task((reject, resolve) => { | ||
let remaining = tasks.length; | ||
let rejected = false; | ||
let rejectedError; | ||
// Create the results array. | ||
var results = Array(tasks.length); | ||
const results = Array(tasks.length); | ||
// Fork each task | ||
tasks.forEach(function (task, idx) { | ||
task.fork(function (error) { | ||
tasks.forEach((task, idx) => { | ||
task.fork((error) => { | ||
if (!rejected) { | ||
@@ -107,3 +78,3 @@ rejected = true; | ||
return rejectedError; | ||
}, function (value) { | ||
}, (value) => { | ||
// Decrement the pending count | ||
@@ -121,34 +92,17 @@ remaining -= 1; | ||
}); | ||
}; | ||
// lift :: (a -> b) -> (a -> Task b) | ||
Task.lift = function (func) { | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
Task.lift = func => (...args) => | ||
Task((_, resolve) => resolve(func(...args))); | ||
return Task(function (_, resolve) { | ||
return resolve(func.apply(undefined, args)); | ||
}); | ||
}; | ||
}; | ||
// liftNode :: (a, (b, c) -> d) -> (a -> Task b c) | ||
Task.liftNode = function (func) { | ||
return function () { | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
Task.liftNode = func => (...args) => | ||
Task((reject, resolve) => | ||
func(...args, (error, data) => { | ||
if (error) { | ||
return reject(error); | ||
} | ||
return resolve(data); | ||
})); | ||
return Task(function (reject, resolve) { | ||
return func.apply(undefined, args.concat([function (error, data) { | ||
if (error) { | ||
return reject(error); | ||
} | ||
return resolve(data); | ||
}])); | ||
}); | ||
}; | ||
}; | ||
@@ -185,5 +139,3 @@ /* | ||
// toPromise :: Task a b -> c -> Promise b | ||
Task.prototype.toPromise = function toPromise() { | ||
var Promise = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : global.Promise; | ||
Task.prototype.toPromise = function toPromise(Promise = global.Promise) { | ||
return Task.toPromise(this, Promise); | ||
@@ -204,13 +156,14 @@ }; | ||
// Static Monad | ||
Task[_fantasyLand2.default.of] = Task.of; | ||
Task[_fantasyLand2.default.chain] = Task.chain; | ||
Task[_fantasyLand2.default.map] = Task.map; | ||
Task[_fantasyLand2.default.ap] = Task.ap; | ||
Task[FL.of] = Task.of; | ||
Task[FL.chain] = Task.chain; | ||
Task[FL.map] = Task.map; | ||
Task[FL.ap] = Task.ap; | ||
// Instance Monad | ||
Task.prototype[_fantasyLand2.default.of] = Task.prototype.of; | ||
Task.prototype[_fantasyLand2.default.chain] = Task.prototype.chain; | ||
Task.prototype[_fantasyLand2.default.map] = Task.prototype.map; | ||
Task.prototype[_fantasyLand2.default.ap] = Task.prototype.ap; | ||
Task.prototype[FL.of] = Task.prototype.of; | ||
Task.prototype[FL.chain] = Task.prototype.chain; | ||
Task.prototype[FL.map] = Task.prototype.map; | ||
Task.prototype[FL.ap] = Task.prototype.ap; | ||
module.exports = Task; | ||
module.exports = Task; |
62
tuple.js
@@ -1,17 +0,9 @@ | ||
'use strict'; | ||
const FL = require('fantasy-land'); | ||
var _fantasyLand = require('fantasy-land'); | ||
const { tag } = require('./adt'); | ||
const { curry } = require('./_tools'); | ||
var _fantasyLand2 = _interopRequireDefault(_fantasyLand); | ||
const Tuple = tag('Tuple', 'left', 'right'); | ||
var _curry = require('ramda/src/curry'); | ||
var _curry2 = _interopRequireDefault(_curry); | ||
var _adt = require('./adt'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var Tuple = (0, _adt.tag)('Tuple', 'left', 'right'); | ||
/* | ||
@@ -24,26 +16,20 @@ |------------------------------------------------------------------------------ | ||
// fst :: (a, b) -> a | ||
Tuple.fst = function (tuple) { | ||
return tuple.left; | ||
}; | ||
Tuple.fst = tuple => tuple.left; | ||
// snd :: (a, b) -> b | ||
Tuple.snd = function (tuple) { | ||
return tuple.right; | ||
}; | ||
Tuple.snd = tuple => tuple.right; | ||
// equals :: (a, b) -> (a, b) -> Bool | ||
Tuple.equals = (0, _curry2.default)(function (left, right) { | ||
return left.left === right.left && left.right === right.right; | ||
}); | ||
Tuple.equals = curry((left, right) => | ||
left.left === right.left && left.right === right.right); | ||
// map :: (b -> c) -> (a, b) -> (a, c) | ||
Tuple.map = (0, _curry2.default)(function (transform, tuple) { | ||
return Tuple(tuple.left, transform(tuple.right)); | ||
}); | ||
Tuple.map = curry((transform, tuple) => | ||
Tuple(tuple.left, transform(tuple.right))); | ||
// mapLeft :: (a -> c) -> (a, b) -> (c, b) | ||
Tuple.mapLeft = (0, _curry2.default)(function (transform, tuple) { | ||
return Tuple(transform(tuple.left), tuple.right); | ||
}); | ||
Tuple.mapLeft = curry((transform, tuple) => | ||
Tuple(transform(tuple.left), tuple.right)); | ||
/* | ||
@@ -82,3 +68,3 @@ |------------------------------------------------------------------------------ | ||
Tuple.prototype.toString = function toString() { | ||
return '(' + this.left.toString() + ', ' + this.right.toString() + ')'; | ||
return `(${this.left.toString()}, ${this.right.toString()})`; | ||
}; | ||
@@ -88,6 +74,6 @@ | ||
Tuple.prototype[Symbol.iterator] = function iterator() { | ||
var pending = ['left', 'right']; | ||
var tuple = this; | ||
const pending = ['left', 'right']; | ||
const tuple = this; | ||
return { | ||
next: function next() { | ||
next() { | ||
if (pending.length) { | ||
@@ -97,6 +83,7 @@ return { value: tuple[pending.shift()] }; | ||
return { done: true }; | ||
} | ||
}, | ||
}; | ||
}; | ||
/* | ||
@@ -109,9 +96,10 @@ |------------------------------------------------------------------------------ | ||
// Tuple Applicative | ||
Tuple[_fantasyLand2.default.equals] = Tuple.equals; | ||
Tuple.prototype[_fantasyLand2.default.equals] = Tuple.prototype.equals; | ||
Tuple[FL.equals] = Tuple.equals; | ||
Tuple.prototype[FL.equals] = Tuple.prototype.equals; | ||
// Tuple Functor | ||
Tuple[_fantasyLand2.default.map] = Tuple.map; | ||
Tuple.prototype[_fantasyLand2.default.map] = Tuple.prototype.map; | ||
Tuple[FL.map] = Tuple.map; | ||
Tuple.prototype[FL.map] = Tuple.prototype.map; | ||
module.exports = Tuple; | ||
module.exports = Tuple; |
@@ -1,34 +0,14 @@ | ||
'use strict'; | ||
const FL = require('fantasy-land'); | ||
var _fantasyLand = require('fantasy-land'); | ||
const { union } = require('./adt'); | ||
const { __, curry, always, compose } = require('./_tools'); | ||
var _fantasyLand2 = _interopRequireDefault(_fantasyLand); | ||
var _ = require('ramda/src/__'); | ||
var _2 = _interopRequireDefault(_); | ||
var _curry = require('ramda/src/curry'); | ||
var _curry2 = _interopRequireDefault(_curry); | ||
var _compose = require('ramda/src/compose'); | ||
var _compose2 = _interopRequireDefault(_compose); | ||
var _always = require('ramda/src/always'); | ||
var _always2 = _interopRequireDefault(_always); | ||
var _adt = require('./adt'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var Validation = (0, _adt.union)('Validation', { | ||
const Validation = union('Validation', { | ||
Success: ['value'], | ||
Failure: ['value'] | ||
Failure: ['value'], | ||
}); | ||
var Success = Validation.Success; | ||
var Failure = Validation.Failure; | ||
const Success = Validation.Success; | ||
const Failure = Validation.Failure; | ||
@@ -57,8 +37,7 @@ /* | ||
// chain :: Validation v => (b -> v a c) -> v a b -> v a c | ||
Validation.chain = (0, _curry2.default)(function (transform, validation) { | ||
return validation.cata({ | ||
Failure: (0, _always2.default)(validation), | ||
Success: transform | ||
}); | ||
}); | ||
Validation.chain = curry((transform, validation) => | ||
validation.cata({ | ||
Failure: always(validation), | ||
Success: transform, | ||
})); | ||
@@ -69,49 +48,36 @@ // andThen :: Validation v => (b -> v a c) -> v a b -> v a c | ||
// map :: Validation v => (b -> c) -> v a b -> v a c | ||
Validation.map = (0, _curry2.default)(function (transform, validation) { | ||
return Validation.chain((0, _compose2.default)(Validation.of, transform), validation); | ||
}); | ||
Validation.map = curry((transform, validation) => | ||
Validation.chain(compose(Validation.of, transform), validation)); | ||
// ap :: Validation v => Apply (b -> c) -> v a b -> v a c | ||
Validation.ap = (0, _curry2.default)(function (left, right) { | ||
return Validation.chain(Validation.map(_2.default, right), left); | ||
}); | ||
Validation.ap = curry((left, right) => | ||
Validation.chain(Validation.map(__, right), left)); | ||
// isFailure :: Validation a b -> Bool | ||
Validation.isFailure = function (validation) { | ||
return validation instanceof Validation.Failure; | ||
}; | ||
Validation.isFailure = validation => validation instanceof Validation.Failure; | ||
// isSuccess :: Validation a b -> Bool | ||
Validation.isSuccess = function (validation) { | ||
return validation instanceof Validation.Success; | ||
}; | ||
Validation.isSuccess = validation => validation instanceof Validation.Success; | ||
// concat :: Validation v => v a b -> v a b -> v a b | ||
Validation.concat = (0, _curry2.default)(function (left, right) { | ||
return left.cata({ | ||
Failure: function Failure(value) { | ||
return right.cata({ | ||
Success: (0, _always2.default)(left), | ||
Failure: function Failure(x) { | ||
return Validation.Failure(value.concat(x)); | ||
} | ||
}); | ||
}, | ||
Validation.concat = curry((left, right) => | ||
left.cata({ | ||
Failure: value => | ||
right.cata({ | ||
Success: always(left), | ||
Failure: x => Validation.Failure(value.concat(x)), | ||
}), | ||
Success: function Success(value) { | ||
return right.cata({ | ||
Success: function Success(x) { | ||
return Validation.Success(value.concat(x)); | ||
}, | ||
Failure: (0, _always2.default)(right) | ||
}); | ||
} | ||
}); | ||
}); | ||
Success: value => | ||
right.cata({ | ||
Success: x => Validation.Success(value.concat(x)), | ||
Failure: always(right), | ||
}), | ||
})); | ||
// empty :: a -> Validation b [c] | ||
Validation.empty = function () { | ||
return Validation.Success([]); | ||
}; | ||
Validation.empty = () => | ||
Validation.Success([]); | ||
/* | ||
@@ -188,33 +154,35 @@ |------------------------------------------------------------------------------ | ||
// Validation Applicative | ||
Validation[_fantasyLand2.default.of] = Validation.of; | ||
Validation.prototype[_fantasyLand2.default.of] = Validation.prototype.of; | ||
Validation[FL.of] = Validation.of; | ||
Validation.prototype[FL.of] = Validation.prototype.of; | ||
// Validation Chain | ||
Validation[_fantasyLand2.default.chain] = Validation.chain; | ||
Validation.prototype[_fantasyLand2.default.chain] = Validation.prototype.chain; | ||
Validation[FL.chain] = Validation.chain; | ||
Validation.prototype[FL.chain] = Validation.prototype.chain; | ||
// Validation Functor | ||
Validation[_fantasyLand2.default.map] = Validation.map; | ||
Validation.prototype[_fantasyLand2.default.map] = Validation.prototype.map; | ||
Validation[FL.map] = Validation.map; | ||
Validation.prototype[FL.map] = Validation.prototype.map; | ||
// Validation Apply | ||
Validation[_fantasyLand2.default.ap] = Validation.ap; | ||
Validation.prototype[_fantasyLand2.default.ap] = Validation.prototype.ap; | ||
Validation[FL.ap] = Validation.ap; | ||
Validation.prototype[FL.ap] = Validation.prototype.ap; | ||
// Validation Semigroup | ||
Validation[_fantasyLand2.default.concat] = Validation.concat; | ||
Validation.prototype[_fantasyLand2.default.concat] = Validation.prototype.concat; | ||
Validation[FL.concat] = Validation.concat; | ||
Validation.prototype[FL.concat] = Validation.prototype.concat; | ||
// Validation Monoid | ||
Validation[_fantasyLand2.default.empty] = Validation.empty; | ||
Validation.prototype[_fantasyLand2.default.empty] = Validation.prototype.empty; | ||
Validation[FL.empty] = Validation.empty; | ||
Validation.prototype[FL.empty] = Validation.prototype.empty; | ||
// Success Applicative | ||
Validation.Success[_fantasyLand2.default.of] = Validation.Success.of; | ||
Validation.Success.prototype[_fantasyLand2.default.of] = Validation.Success.prototype.of; | ||
Validation.Success[FL.of] = Validation.Success.of; | ||
Validation.Success.prototype[FL.of] = Validation.Success.prototype.of; | ||
// Failure Applicative | ||
Validation.Failure[_fantasyLand2.default.of] = Validation.Failure.of; | ||
Validation.Failure.prototype[_fantasyLand2.default.of] = Validation.Failure.prototype.of; | ||
Validation.Failure[FL.of] = Validation.Failure.of; | ||
Validation.Failure.prototype[FL.of] = Validation.Failure.prototype.of; | ||
module.exports = Validation; | ||
module.exports = Validation; |
@@ -1,27 +0,11 @@ | ||
'use strict'; | ||
const FL = require('fantasy-land'); | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
const Tuple = require('./tuple'); | ||
const { tag } = require('./adt'); | ||
const { __, curry } = require('./_tools'); | ||
var _fantasyLand = require('fantasy-land'); | ||
var _fantasyLand2 = _interopRequireDefault(_fantasyLand); | ||
const Writer = tag('Writer', 'value'); | ||
var _ = require('ramda/src/__'); | ||
var _2 = _interopRequireDefault(_); | ||
var _curry = require('ramda/src/curry'); | ||
var _curry2 = _interopRequireDefault(_curry); | ||
var _tuple = require('./tuple'); | ||
var _tuple2 = _interopRequireDefault(_tuple); | ||
var _adt = require('./adt'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var Writer = (0, _adt.tag)('Writer', 'value'); | ||
/* | ||
@@ -34,22 +18,15 @@ |------------------------------------------------------------------------------ | ||
// of :: a -> Writer w a | ||
Writer.of = function (value) { | ||
return Writer((0, _tuple2.default)(value, [])); | ||
}; | ||
Writer.of = value => | ||
Writer(Tuple(value, [])); | ||
// tell :: w -> Writer w a -> Writer w a | ||
Writer.tell = (0, _curry2.default)(function (value, writer) { | ||
return Writer((0, _tuple2.default)(_tuple2.default.fst(writer.value), _tuple2.default.snd(writer.value).concat(value))); | ||
}); | ||
Writer.tell = curry((value, writer) => | ||
Writer(Tuple(Tuple.fst(writer.value), Tuple.snd(writer.value).concat(value)))); | ||
// chain :: (a -> Writer w b) -> Writer w a -> Writer w b | ||
Writer.chain = (0, _curry2.default)(function (transform, writer) { | ||
var _writer$value = _slicedToArray(writer.value, 2), | ||
value = _writer$value[0], | ||
currentLogs = _writer$value[1]; | ||
Writer.chain = curry((transform, writer) => { | ||
const [value, currentLogs] = writer.value; | ||
const [newVal, newLogs] = transform(value).value; | ||
var _transform$value = _slicedToArray(transform(value).value, 2), | ||
newVal = _transform$value[0], | ||
newLogs = _transform$value[1]; | ||
return Writer((0, _tuple2.default)(newVal, currentLogs.concat(newLogs))); | ||
return Writer(Tuple(newVal, currentLogs.concat(newLogs))); | ||
}); | ||
@@ -61,13 +38,10 @@ | ||
// map :: (a -> b) -> Writer w a -> Writer w b | ||
Writer.map = (0, _curry2.default)(function (transform, writer) { | ||
return Writer.chain(function (x) { | ||
return Writer.of(transform(x)); | ||
}, writer); | ||
}); | ||
Writer.map = curry((transform, writer) => | ||
Writer.chain(x => Writer.of(transform(x)), writer)); | ||
// ap :: Apply (a -> b) -> Writer w a -> Writer w b | ||
Writer.ap = (0, _curry2.default)(function (apply, writer) { | ||
return Writer.chain(Writer.map(_2.default, writer), apply); | ||
}); | ||
Writer.ap = curry((apply, writer) => | ||
Writer.chain(Writer.map(__, writer), apply)); | ||
/* | ||
@@ -114,13 +88,14 @@ |------------------------------------------------------------------------------ | ||
// Static Monad | ||
Writer[_fantasyLand2.default.of] = Writer.of; | ||
Writer[_fantasyLand2.default.chain] = Writer.chain; | ||
Writer[_fantasyLand2.default.map] = Writer.map; | ||
Writer[_fantasyLand2.default.ap] = Writer.ap; | ||
Writer[FL.of] = Writer.of; | ||
Writer[FL.chain] = Writer.chain; | ||
Writer[FL.map] = Writer.map; | ||
Writer[FL.ap] = Writer.ap; | ||
// Instance Monad | ||
Writer.prototype[_fantasyLand2.default.of] = Writer.prototype.of; | ||
Writer.prototype[_fantasyLand2.default.chain] = Writer.prototype.chain; | ||
Writer.prototype[_fantasyLand2.default.map] = Writer.prototype.map; | ||
Writer.prototype[_fantasyLand2.default.ap] = Writer.prototype.ap; | ||
Writer.prototype[FL.of] = Writer.prototype.of; | ||
Writer.prototype[FL.chain] = Writer.prototype.chain; | ||
Writer.prototype[FL.map] = Writer.prototype.map; | ||
Writer.prototype[FL.ap] = Writer.prototype.ap; | ||
module.exports = Writer; | ||
module.exports = Writer; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1
8
17
0
46622
1224
44
+ Addedfantasy-land@4.1.0(transitive)
- Removedramda@^0.24.1
- Removeddaggy@0.0.1(transitive)
- Removedfantasy-combinators@0.0.1(transitive)
- Removedfantasy-land@3.5.0(transitive)
- Removedramda@0.24.1(transitive)
Updatedfantasy-land@^4.0.1