Comparing version 0.13.0 to 0.13.1
318
Either.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Maybe_1 = require("./Maybe"); | ||
var Maybe_1 = require("./Maybe"); | ||
exports.Either = { | ||
of(value) { | ||
of: function (value) { | ||
return right(value); | ||
}, | ||
lefts(list) { | ||
return list.filter(x => x.isLeft()).map(x => x.__value); | ||
lefts: function (list) { | ||
return list.filter(function (x) { return x.isLeft(); }).map(function (x) { return x.__value; }); | ||
}, | ||
rights(list) { | ||
return list.filter(x => x.isRight()).map(x => x.__value); | ||
rights: function (list) { | ||
return list.filter(function (x) { return x.isRight(); }).map(function (x) { return x.__value; }); | ||
}, | ||
encase(throwsF) { | ||
encase: function (throwsF) { | ||
try { | ||
@@ -22,231 +22,233 @@ return right(throwsF()); | ||
}, | ||
'fantasy-land/of'(value) { | ||
'fantasy-land/of': function (value) { | ||
return exports.Either.of(value); | ||
} | ||
}; | ||
class Right { | ||
constructor(value) { | ||
var Right = /** @class */ (function () { | ||
function Right(value) { | ||
this.__value = value; | ||
} | ||
isLeft() { | ||
Right.prototype.isLeft = function () { | ||
return false; | ||
} | ||
isRight() { | ||
}; | ||
Right.prototype.isRight = function () { | ||
return true; | ||
} | ||
toJSON() { | ||
}; | ||
Right.prototype.toJSON = function () { | ||
return this.__value; | ||
} | ||
inspect() { | ||
return `Right(${this.__value})`; | ||
} | ||
toString() { | ||
}; | ||
Right.prototype.inspect = function () { | ||
return "Right(" + this.__value + ")"; | ||
}; | ||
Right.prototype.toString = function () { | ||
return this.inspect(); | ||
} | ||
bimap(_, g) { | ||
}; | ||
Right.prototype.bimap = function (_, g) { | ||
return right(g(this.__value)); | ||
} | ||
map(f) { | ||
}; | ||
Right.prototype.map = function (f) { | ||
return right(f(this.__value)); | ||
} | ||
mapLeft(_) { | ||
}; | ||
Right.prototype.mapLeft = function (_) { | ||
return this; | ||
} | ||
ap(other) { | ||
}; | ||
Right.prototype.ap = function (other) { | ||
return other.isLeft() ? other : this.map(other.__value); | ||
} | ||
equals(other) { | ||
}; | ||
Right.prototype.equals = function (other) { | ||
return other.isRight() ? this.__value === other.__value : false; | ||
} | ||
chain(f) { | ||
}; | ||
Right.prototype.chain = function (f) { | ||
return f(this.__value); | ||
} | ||
join() { | ||
}; | ||
Right.prototype.join = function () { | ||
return this.__value; | ||
} | ||
alt(_) { | ||
}; | ||
Right.prototype.alt = function (_) { | ||
return this; | ||
} | ||
reduce(reducer, initialValue) { | ||
}; | ||
Right.prototype.reduce = function (reducer, initialValue) { | ||
return reducer(initialValue, this.__value); | ||
} | ||
extend(f) { | ||
}; | ||
Right.prototype.extend = function (f) { | ||
return right(f(this)); | ||
} | ||
unsafeCoerce() { | ||
}; | ||
Right.prototype.unsafeCoerce = function () { | ||
return this.__value; | ||
} | ||
caseOf(patterns) { | ||
}; | ||
Right.prototype.caseOf = function (patterns) { | ||
return '_' in patterns ? patterns._() : patterns.Right(this.__value); | ||
} | ||
leftOrDefault(defaultValue) { | ||
}; | ||
Right.prototype.leftOrDefault = function (defaultValue) { | ||
return defaultValue; | ||
} | ||
orDefault(_) { | ||
}; | ||
Right.prototype.orDefault = function (_) { | ||
return this.__value; | ||
} | ||
orDefaultLazy(_) { | ||
}; | ||
Right.prototype.orDefaultLazy = function (_) { | ||
return this.__value; | ||
} | ||
leftOrDefaultLazy(getDefaultValue) { | ||
}; | ||
Right.prototype.leftOrDefaultLazy = function (getDefaultValue) { | ||
return getDefaultValue(); | ||
} | ||
ifLeft(_) { | ||
}; | ||
Right.prototype.ifLeft = function (_) { | ||
return this; | ||
} | ||
ifRight(effect) { | ||
}; | ||
Right.prototype.ifRight = function (effect) { | ||
return effect(this.__value), this; | ||
} | ||
toMaybe() { | ||
}; | ||
Right.prototype.toMaybe = function () { | ||
return Maybe_1.Just(this.__value); | ||
} | ||
leftToMaybe() { | ||
}; | ||
Right.prototype.leftToMaybe = function () { | ||
return Maybe_1.Nothing; | ||
} | ||
either(_, ifRight) { | ||
}; | ||
Right.prototype.either = function (_, ifRight) { | ||
return ifRight(this.__value); | ||
} | ||
extract() { | ||
}; | ||
Right.prototype.extract = function () { | ||
return this.__value; | ||
} | ||
'fantasy-land/bimap'(f, g) { | ||
}; | ||
Right.prototype['fantasy-land/bimap'] = function (f, g) { | ||
return this.bimap(f, g); | ||
} | ||
'fantasy-land/map'(f) { | ||
}; | ||
Right.prototype['fantasy-land/map'] = function (f) { | ||
return this.map(f); | ||
} | ||
'fantasy-land/ap'(other) { | ||
}; | ||
Right.prototype['fantasy-land/ap'] = function (other) { | ||
return this.ap(other); | ||
} | ||
'fantasy-land/equals'(other) { | ||
}; | ||
Right.prototype['fantasy-land/equals'] = function (other) { | ||
return this.equals(other); | ||
} | ||
'fantasy-land/chain'(f) { | ||
}; | ||
Right.prototype['fantasy-land/chain'] = function (f) { | ||
return this.chain(f); | ||
} | ||
'fantasy-land/alt'(other) { | ||
}; | ||
Right.prototype['fantasy-land/alt'] = function (other) { | ||
return this.alt(other); | ||
} | ||
'fantasy-land/reduce'(reducer, initialValue) { | ||
}; | ||
Right.prototype['fantasy-land/reduce'] = function (reducer, initialValue) { | ||
return this.reduce(reducer, initialValue); | ||
} | ||
'fantasy-land/extend'(f) { | ||
}; | ||
Right.prototype['fantasy-land/extend'] = function (f) { | ||
return this.extend(f); | ||
} | ||
} | ||
}; | ||
return Right; | ||
}()); | ||
Right.prototype.constructor = exports.Either; | ||
class Left { | ||
constructor(value) { | ||
var Left = /** @class */ (function () { | ||
function Left(value) { | ||
this.__value = value; | ||
} | ||
isLeft() { | ||
Left.prototype.isLeft = function () { | ||
return true; | ||
} | ||
isRight() { | ||
}; | ||
Left.prototype.isRight = function () { | ||
return false; | ||
} | ||
toJSON() { | ||
}; | ||
Left.prototype.toJSON = function () { | ||
return this.__value; | ||
} | ||
inspect() { | ||
return `Left(${this.__value})`; | ||
} | ||
toString() { | ||
}; | ||
Left.prototype.inspect = function () { | ||
return "Left(" + this.__value + ")"; | ||
}; | ||
Left.prototype.toString = function () { | ||
return this.inspect(); | ||
} | ||
bimap(f, _) { | ||
}; | ||
Left.prototype.bimap = function (f, _) { | ||
return left(f(this.__value)); | ||
} | ||
map(_) { | ||
}; | ||
Left.prototype.map = function (_) { | ||
return this; | ||
} | ||
mapLeft(f) { | ||
}; | ||
Left.prototype.mapLeft = function (f) { | ||
return left(f(this.__value)); | ||
} | ||
ap(other) { | ||
}; | ||
Left.prototype.ap = function (other) { | ||
return other.isLeft() ? other : this; | ||
} | ||
equals(other) { | ||
}; | ||
Left.prototype.equals = function (other) { | ||
return other.isLeft() ? other.__value === this.__value : false; | ||
} | ||
chain(_) { | ||
}; | ||
Left.prototype.chain = function (_) { | ||
return this; | ||
} | ||
join() { | ||
}; | ||
Left.prototype.join = function () { | ||
return this; | ||
} | ||
alt(other) { | ||
}; | ||
Left.prototype.alt = function (other) { | ||
return other; | ||
} | ||
reduce(_, initialValue) { | ||
}; | ||
Left.prototype.reduce = function (_, initialValue) { | ||
return initialValue; | ||
} | ||
extend(_) { | ||
}; | ||
Left.prototype.extend = function (_) { | ||
return this; | ||
} | ||
unsafeCoerce() { | ||
}; | ||
Left.prototype.unsafeCoerce = function () { | ||
throw new Error('Either got coerced to a Left'); | ||
} | ||
caseOf(patterns) { | ||
}; | ||
Left.prototype.caseOf = function (patterns) { | ||
return '_' in patterns ? patterns._() : patterns.Left(this.__value); | ||
} | ||
leftOrDefault(_) { | ||
}; | ||
Left.prototype.leftOrDefault = function (_) { | ||
return this.__value; | ||
} | ||
orDefault(defaultValue) { | ||
}; | ||
Left.prototype.orDefault = function (defaultValue) { | ||
return defaultValue; | ||
} | ||
orDefaultLazy(getDefaultValue) { | ||
}; | ||
Left.prototype.orDefaultLazy = function (getDefaultValue) { | ||
return getDefaultValue(); | ||
} | ||
leftOrDefaultLazy(_) { | ||
}; | ||
Left.prototype.leftOrDefaultLazy = function (_) { | ||
return this.__value; | ||
} | ||
ifLeft(effect) { | ||
}; | ||
Left.prototype.ifLeft = function (effect) { | ||
return effect(this.__value), this; | ||
} | ||
ifRight(_) { | ||
}; | ||
Left.prototype.ifRight = function (_) { | ||
return this; | ||
} | ||
toMaybe() { | ||
}; | ||
Left.prototype.toMaybe = function () { | ||
return Maybe_1.Nothing; | ||
} | ||
leftToMaybe() { | ||
}; | ||
Left.prototype.leftToMaybe = function () { | ||
return Maybe_1.Just(this.__value); | ||
} | ||
either(ifLeft, _) { | ||
}; | ||
Left.prototype.either = function (ifLeft, _) { | ||
return ifLeft(this.__value); | ||
} | ||
extract() { | ||
}; | ||
Left.prototype.extract = function () { | ||
return this.__value; | ||
} | ||
'fantasy-land/bimap'(f, g) { | ||
}; | ||
Left.prototype['fantasy-land/bimap'] = function (f, g) { | ||
return this.bimap(f, g); | ||
} | ||
'fantasy-land/map'(f) { | ||
}; | ||
Left.prototype['fantasy-land/map'] = function (f) { | ||
return this.map(f); | ||
} | ||
'fantasy-land/ap'(other) { | ||
}; | ||
Left.prototype['fantasy-land/ap'] = function (other) { | ||
return this.ap(other); | ||
} | ||
'fantasy-land/equals'(other) { | ||
}; | ||
Left.prototype['fantasy-land/equals'] = function (other) { | ||
return this.equals(other); | ||
} | ||
'fantasy-land/chain'(f) { | ||
}; | ||
Left.prototype['fantasy-land/chain'] = function (f) { | ||
return this.chain(f); | ||
} | ||
'fantasy-land/alt'(other) { | ||
}; | ||
Left.prototype['fantasy-land/alt'] = function (other) { | ||
return this.alt(other); | ||
} | ||
'fantasy-land/reduce'(reducer, initialValue) { | ||
}; | ||
Left.prototype['fantasy-land/reduce'] = function (reducer, initialValue) { | ||
return this.reduce(reducer, initialValue); | ||
} | ||
'fantasy-land/extend'(f) { | ||
}; | ||
Left.prototype['fantasy-land/extend'] = function (f) { | ||
return this.extend(f); | ||
} | ||
} | ||
}; | ||
return Left; | ||
}()); | ||
Left.prototype.constructor = exports.Either; | ||
const left = (value) => new Left(value); | ||
var left = function (value) { return new Left(value); }; | ||
exports.Left = left; | ||
const right = (value) => new Right(value); | ||
var right = function (value) { return new Right(value); }; | ||
exports.Right = right; |
@@ -10,7 +10,34 @@ "use strict"; | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Either_1 = require("./Either"); | ||
const MaybeAsync_1 = require("./MaybeAsync"); | ||
const helpers = { | ||
liftEither(either) { | ||
var Either_1 = require("./Either"); | ||
var MaybeAsync_1 = require("./MaybeAsync"); | ||
var helpers = { | ||
liftEither: function (either) { | ||
if (either.isLeft()) { | ||
@@ -21,46 +48,76 @@ throw either.__value; | ||
}, | ||
fromPromise(promise) { | ||
fromPromise: function (promise) { | ||
return promise.then(helpers.liftEither); | ||
}, | ||
throwE(error) { | ||
throwE: function (error) { | ||
throw error; | ||
} | ||
}; | ||
class EitherAsyncImpl { | ||
constructor(runPromise) { | ||
var EitherAsyncImpl = /** @class */ (function () { | ||
function EitherAsyncImpl(runPromise) { | ||
this.runPromise = runPromise; | ||
} | ||
run() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
return Either_1.Right(yield this.runPromise(helpers)); | ||
} | ||
catch (e) { | ||
return Either_1.Left(e); | ||
} | ||
EitherAsyncImpl.prototype.run = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _a, e_1; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_b.trys.push([0, 2, , 3]); | ||
_a = Either_1.Right; | ||
return [4 /*yield*/, this.runPromise(helpers)]; | ||
case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])]; | ||
case 2: | ||
e_1 = _b.sent(); | ||
return [2 /*return*/, Either_1.Left(e_1)]; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
map(f) { | ||
return exports.EitherAsync(helpers => this.runPromise(helpers).then(f)); | ||
} | ||
chain(f) { | ||
return exports.EitherAsync((helpers) => __awaiter(this, void 0, void 0, function* () { | ||
const value = yield this.runPromise(helpers); | ||
return yield helpers.fromPromise(f(value).run()); | ||
})); | ||
} | ||
toMaybeAsync() { | ||
return MaybeAsync_1.MaybeAsync(({ liftMaybe }) => __awaiter(this, void 0, void 0, function* () { | ||
const either = yield this.run(); | ||
return liftMaybe(either.toMaybe()); | ||
})); | ||
} | ||
'fantasy-land/map'(f) { | ||
}; | ||
EitherAsyncImpl.prototype.map = function (f) { | ||
var _this = this; | ||
return exports.EitherAsync(function (helpers) { return _this.runPromise(helpers).then(f); }); | ||
}; | ||
EitherAsyncImpl.prototype.chain = function (f) { | ||
var _this = this; | ||
return exports.EitherAsync(function (helpers) { return __awaiter(_this, void 0, void 0, function () { | ||
var value; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.runPromise(helpers)]; | ||
case 1: | ||
value = _a.sent(); | ||
return [4 /*yield*/, helpers.fromPromise(f(value).run())]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); }); | ||
}; | ||
EitherAsyncImpl.prototype.toMaybeAsync = function () { | ||
var _this = this; | ||
return MaybeAsync_1.MaybeAsync(function (_a) { | ||
var liftMaybe = _a.liftMaybe; | ||
return __awaiter(_this, void 0, void 0, function () { | ||
var either; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, this.run()]; | ||
case 1: | ||
either = _b.sent(); | ||
return [2 /*return*/, liftMaybe(either.toMaybe())]; | ||
} | ||
}); | ||
}); | ||
}); | ||
}; | ||
EitherAsyncImpl.prototype['fantasy-land/map'] = function (f) { | ||
return this.map(f); | ||
} | ||
'fantasy-land/chain'(f) { | ||
}; | ||
EitherAsyncImpl.prototype['fantasy-land/chain'] = function (f) { | ||
return this.chain(f); | ||
} | ||
} | ||
}; | ||
return EitherAsyncImpl; | ||
}()); | ||
/** Constructs a EitherAsync object from a function that takes an object full of helpers that let you lift things into the EitherAsync context and returns a Promise */ | ||
exports.EitherAsync = (runPromise) => new EitherAsyncImpl(runPromise); | ||
exports.EitherAsync = function (runPromise) { return new EitherAsyncImpl(runPromise); }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** The identity function, returns the value it was given */ | ||
exports.identity = (x) => x; | ||
exports.identity = function (x) { return x; }; | ||
/** Returns a function that always returns the same value. Also known as `const` in other languages */ | ||
exports.always = (x) => () => x; | ||
exports.always = function (x) { return function () { return x; }; }; | ||
/** Compares two values using the default "<" and ">" operators */ | ||
exports.compare = (x, y) => { | ||
exports.compare = function (x, y) { | ||
if (x > y) { | ||
@@ -20,3 +20,3 @@ return "GT" /* GT */; | ||
/** Maps the Order enum to the values expected by the standard ECMAScript library when doing comparison (Array.prototype.sort, for example) */ | ||
exports.orderToNumber = (order) => { | ||
exports.orderToNumber = function (order) { | ||
switch (order) { | ||
@@ -23,0 +23,0 @@ case "LT" /* LT */: |
60
List.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Tuple_1 = require("./Tuple"); | ||
const Maybe_1 = require("./Maybe"); | ||
const Function_1 = require("./Function"); | ||
var Tuple_1 = require("./Tuple"); | ||
var Maybe_1 = require("./Maybe"); | ||
var Function_1 = require("./Function"); | ||
/** Returns Just the first element of an array or Nothing if there is none. If you don't want to work with a Maybe but still keep type safety, check out `NonEmptyList` */ | ||
const head = (list) => list.length > 0 ? Maybe_1.Just(list[0]) : Maybe_1.Nothing; | ||
var head = function (list) { | ||
return list.length > 0 ? Maybe_1.Just(list[0]) : Maybe_1.Nothing; | ||
}; | ||
/** Returns Just the last element of an array or Nothing if there is none */ | ||
const last = (list) => list.length > 0 ? Maybe_1.Just(list[list.length - 1]) : Maybe_1.Nothing; | ||
var last = function (list) { | ||
return list.length > 0 ? Maybe_1.Just(list[list.length - 1]) : Maybe_1.Nothing; | ||
}; | ||
/** Returns all elements of an array except the first */ | ||
const tail = (list) => list.length > 0 ? Maybe_1.Just(list.slice(1)) : Maybe_1.Nothing; | ||
var tail = function (list) { | ||
return list.length > 0 ? Maybe_1.Just(list.slice(1)) : Maybe_1.Nothing; | ||
}; | ||
/** Returns all elements of an array except the last */ | ||
const init = (list) => list.length > 0 ? Maybe_1.Just(list.slice(0, -1)) : Maybe_1.Nothing; | ||
var init = function (list) { | ||
return list.length > 0 ? Maybe_1.Just(list.slice(0, -1)) : Maybe_1.Nothing; | ||
}; | ||
/** Returns a tuple of an array's head and tail */ | ||
const uncons = (list) => list.length > 0 ? Maybe_1.Just(Tuple_1.Tuple(list[0], list.slice(1))) : Maybe_1.Nothing; | ||
var uncons = function (list) { | ||
return list.length > 0 ? Maybe_1.Just(Tuple_1.Tuple(list[0], list.slice(1))) : Maybe_1.Nothing; | ||
}; | ||
/* Returns the sum of all numbers inside an array */ | ||
const sum = (list) => list.reduce((acc, x) => acc + x, 0); | ||
var sum = function (list) { return list.reduce(function (acc, x) { return acc + x; }, 0); }; | ||
function find(f, list) { | ||
switch (arguments.length) { | ||
case 1: | ||
return (list) => find(f, list); | ||
return function (list) { return find(f, list); }; | ||
default: | ||
@@ -29,5 +39,5 @@ return Maybe_1.Maybe.fromNullable(list.find(f)); | ||
case 1: | ||
return (list) => findIndex(f, list); | ||
return function (list) { return findIndex(f, list); }; | ||
default: | ||
return Maybe_1.Maybe.fromPredicate(x => x !== -1, list.findIndex(f)); | ||
return Maybe_1.Maybe.fromPredicate(function (x) { return x !== -1; }, list.findIndex(f)); | ||
} | ||
@@ -38,3 +48,3 @@ } | ||
case 1: | ||
return (list) => at(index, list); | ||
return function (list) { return at(index, list); }; | ||
default: | ||
@@ -47,18 +57,18 @@ return list[index] === undefined ? Maybe_1.Nothing : Maybe_1.Just(list[index]); | ||
case 1: | ||
return (list) => sort(compare, list); | ||
return function (list) { return sort(compare, list); }; | ||
default: | ||
return [...list].sort((x, y) => Function_1.orderToNumber(compare(x, y))); | ||
return list.slice().sort(function (x, y) { return Function_1.orderToNumber(compare(x, y)); }); | ||
} | ||
} | ||
exports.List = { | ||
init, | ||
uncons, | ||
at, | ||
head, | ||
last, | ||
tail, | ||
find, | ||
findIndex, | ||
sum, | ||
sort | ||
init: init, | ||
uncons: uncons, | ||
at: at, | ||
head: head, | ||
last: last, | ||
tail: tail, | ||
find: find, | ||
findIndex: findIndex, | ||
sum: sum, | ||
sort: sort | ||
}; |
316
Maybe.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Either_1 = require("./Either"); | ||
var Either_1 = require("./Either"); | ||
exports.Maybe = { | ||
of(value) { | ||
of: function (value) { | ||
return just(value); | ||
}, | ||
empty() { | ||
empty: function () { | ||
return nothing; | ||
}, | ||
zero() { | ||
zero: function () { | ||
return nothing; | ||
}, | ||
fromNullable(value) { | ||
fromNullable: function (value) { | ||
return value == null ? nothing : just(value); | ||
}, | ||
fromFalsy(value) { | ||
fromFalsy: function (value) { | ||
return value ? just(value) : nothing; | ||
}, | ||
fromPredicate(pred, value) { | ||
fromPredicate: function (pred, value) { | ||
switch (arguments.length) { | ||
case 1: | ||
return (value) => exports.Maybe.fromPredicate(pred, value); | ||
return function (value) { return exports.Maybe.fromPredicate(pred, value); }; | ||
default: | ||
@@ -28,6 +28,6 @@ return pred(value) ? just(value) : nothing; | ||
}, | ||
mapMaybe(f, list) { | ||
mapMaybe: function (f, list) { | ||
switch (arguments.length) { | ||
case 1: | ||
return (list) => exports.Maybe.mapMaybe(f, list); | ||
return function (list) { return exports.Maybe.mapMaybe(f, list); }; | ||
default: | ||
@@ -37,6 +37,6 @@ return exports.Maybe.catMaybes(list.map(f)); | ||
}, | ||
catMaybes(list) { | ||
return list.filter(x => x.isJust()).map(x => x.__value); | ||
catMaybes: function (list) { | ||
return list.filter(function (x) { return x.isJust(); }).map(function (x) { return x.__value; }); | ||
}, | ||
encase(thunk) { | ||
encase: function (thunk) { | ||
try { | ||
@@ -49,224 +49,228 @@ return just(thunk()); | ||
}, | ||
'fantasy-land/of'(value) { | ||
'fantasy-land/of': function (value) { | ||
return this.of(value); | ||
}, | ||
'fantasy-land/empty'() { | ||
'fantasy-land/empty': function () { | ||
return this.empty(); | ||
}, | ||
'fantasy-land/zero'() { | ||
'fantasy-land/zero': function () { | ||
return this.zero(); | ||
} | ||
}; | ||
class Just { | ||
constructor(value) { | ||
var Just = /** @class */ (function () { | ||
function Just(value) { | ||
this.__value = value; | ||
} | ||
isJust() { | ||
Just.prototype.isJust = function () { | ||
return true; | ||
} | ||
isNothing() { | ||
}; | ||
Just.prototype.isNothing = function () { | ||
return false; | ||
} | ||
inspect() { | ||
return `Just(${this.__value})`; | ||
} | ||
toString() { | ||
}; | ||
Just.prototype.inspect = function () { | ||
return "Just(" + this.__value + ")"; | ||
}; | ||
Just.prototype.toString = function () { | ||
return this.inspect(); | ||
} | ||
toJSON() { | ||
}; | ||
Just.prototype.toJSON = function () { | ||
return this.__value; | ||
} | ||
equals(other) { | ||
}; | ||
Just.prototype.equals = function (other) { | ||
return this.__value === other.__value; | ||
} | ||
map(f) { | ||
}; | ||
Just.prototype.map = function (f) { | ||
return just(f(this.__value)); | ||
} | ||
ap(maybeF) { | ||
}; | ||
Just.prototype.ap = function (maybeF) { | ||
return maybeF.isNothing() ? nothing : this.map(maybeF.__value); | ||
} | ||
alt(_) { | ||
}; | ||
Just.prototype.alt = function (_) { | ||
return this; | ||
} | ||
chain(f) { | ||
}; | ||
Just.prototype.chain = function (f) { | ||
return f(this.__value); | ||
} | ||
chainNullable(f) { | ||
}; | ||
Just.prototype.chainNullable = function (f) { | ||
return exports.Maybe.fromNullable(f(this.__value)); | ||
} | ||
join() { | ||
}; | ||
Just.prototype.join = function () { | ||
return this.__value; | ||
} | ||
reduce(reducer, initialValue) { | ||
}; | ||
Just.prototype.reduce = function (reducer, initialValue) { | ||
return reducer(initialValue, this.__value); | ||
} | ||
extend(f) { | ||
}; | ||
Just.prototype.extend = function (f) { | ||
return just(f(this)); | ||
} | ||
unsafeCoerce() { | ||
}; | ||
Just.prototype.unsafeCoerce = function () { | ||
return this.__value; | ||
} | ||
caseOf(patterns) { | ||
}; | ||
Just.prototype.caseOf = function (patterns) { | ||
return '_' in patterns ? patterns._() : patterns.Just(this.__value); | ||
} | ||
orDefault(_) { | ||
}; | ||
Just.prototype.orDefault = function (_) { | ||
return this.__value; | ||
} | ||
orDefaultLazy(_) { | ||
}; | ||
Just.prototype.orDefaultLazy = function (_) { | ||
return this.__value; | ||
} | ||
toList() { | ||
}; | ||
Just.prototype.toList = function () { | ||
return [this.__value]; | ||
} | ||
mapOrDefault(f, _) { | ||
}; | ||
Just.prototype.mapOrDefault = function (f, _) { | ||
return f(this.__value); | ||
} | ||
extract() { | ||
}; | ||
Just.prototype.extract = function () { | ||
return this.__value; | ||
} | ||
extractNullable() { | ||
}; | ||
Just.prototype.extractNullable = function () { | ||
return this.__value; | ||
} | ||
toEither(_) { | ||
}; | ||
Just.prototype.toEither = function (_) { | ||
return Either_1.Right(this.__value); | ||
} | ||
ifJust(effect) { | ||
}; | ||
Just.prototype.ifJust = function (effect) { | ||
return effect(this.__value), this; | ||
} | ||
ifNothing(_) { | ||
}; | ||
Just.prototype.ifNothing = function (_) { | ||
return this; | ||
} | ||
filter(pred) { | ||
}; | ||
Just.prototype.filter = function (pred) { | ||
return pred(this.__value) ? just(this.__value) : nothing; | ||
} | ||
'fantasy-land/equals'(other) { | ||
}; | ||
Just.prototype['fantasy-land/equals'] = function (other) { | ||
return this.equals(other); | ||
} | ||
'fantasy-land/map'(f) { | ||
}; | ||
Just.prototype['fantasy-land/map'] = function (f) { | ||
return this.map(f); | ||
} | ||
'fantasy-land/ap'(maybeF) { | ||
}; | ||
Just.prototype['fantasy-land/ap'] = function (maybeF) { | ||
return this.ap(maybeF); | ||
} | ||
'fantasy-land/alt'(other) { | ||
}; | ||
Just.prototype['fantasy-land/alt'] = function (other) { | ||
return this.alt(other); | ||
} | ||
'fantasy-land/chain'(f) { | ||
}; | ||
Just.prototype['fantasy-land/chain'] = function (f) { | ||
return this.chain(f); | ||
} | ||
'fantasy-land/reduce'(reducer, initialValue) { | ||
}; | ||
Just.prototype['fantasy-land/reduce'] = function (reducer, initialValue) { | ||
return this.reduce(reducer, initialValue); | ||
} | ||
'fantasy-land/extend'(f) { | ||
}; | ||
Just.prototype['fantasy-land/extend'] = function (f) { | ||
return this.extend(f); | ||
}; | ||
return Just; | ||
}()); | ||
Just.prototype.constructor = exports.Maybe; | ||
var Nothing = /** @class */ (function () { | ||
function Nothing() { | ||
} | ||
} | ||
Just.prototype.constructor = exports.Maybe; | ||
class Nothing { | ||
isJust() { | ||
Nothing.prototype.isJust = function () { | ||
return false; | ||
} | ||
isNothing() { | ||
}; | ||
Nothing.prototype.isNothing = function () { | ||
return true; | ||
} | ||
inspect() { | ||
}; | ||
Nothing.prototype.inspect = function () { | ||
return 'Nothing'; | ||
} | ||
toString() { | ||
}; | ||
Nothing.prototype.toString = function () { | ||
return this.inspect(); | ||
} | ||
toJSON() { | ||
}; | ||
Nothing.prototype.toJSON = function () { | ||
return this.__value; | ||
} | ||
equals(other) { | ||
}; | ||
Nothing.prototype.equals = function (other) { | ||
return this.__value === other.__value; | ||
} | ||
map(_) { | ||
}; | ||
Nothing.prototype.map = function (_) { | ||
return nothing; | ||
} | ||
ap(_) { | ||
}; | ||
Nothing.prototype.ap = function (_) { | ||
return nothing; | ||
} | ||
alt(other) { | ||
}; | ||
Nothing.prototype.alt = function (other) { | ||
return other; | ||
} | ||
chain(_) { | ||
}; | ||
Nothing.prototype.chain = function (_) { | ||
return nothing; | ||
} | ||
chainNullable(_) { | ||
}; | ||
Nothing.prototype.chainNullable = function (_) { | ||
return nothing; | ||
} | ||
join() { | ||
}; | ||
Nothing.prototype.join = function () { | ||
return nothing; | ||
} | ||
reduce(_, initialValue) { | ||
}; | ||
Nothing.prototype.reduce = function (_, initialValue) { | ||
return initialValue; | ||
} | ||
extend(_) { | ||
}; | ||
Nothing.prototype.extend = function (_) { | ||
return nothing; | ||
} | ||
unsafeCoerce() { | ||
}; | ||
Nothing.prototype.unsafeCoerce = function () { | ||
throw new Error('Maybe got coerced to a null'); | ||
} | ||
caseOf(patterns) { | ||
}; | ||
Nothing.prototype.caseOf = function (patterns) { | ||
return '_' in patterns ? patterns._() : patterns.Nothing(); | ||
} | ||
orDefault(defaultValue) { | ||
}; | ||
Nothing.prototype.orDefault = function (defaultValue) { | ||
return defaultValue; | ||
} | ||
orDefaultLazy(getDefaultValue) { | ||
}; | ||
Nothing.prototype.orDefaultLazy = function (getDefaultValue) { | ||
return getDefaultValue(); | ||
} | ||
toList() { | ||
}; | ||
Nothing.prototype.toList = function () { | ||
return []; | ||
} | ||
mapOrDefault(_, defaultValue) { | ||
}; | ||
Nothing.prototype.mapOrDefault = function (_, defaultValue) { | ||
return defaultValue; | ||
} | ||
extract() { | ||
}; | ||
Nothing.prototype.extract = function () { | ||
return undefined; | ||
} | ||
extractNullable() { | ||
}; | ||
Nothing.prototype.extractNullable = function () { | ||
return null; | ||
} | ||
toEither(left) { | ||
}; | ||
Nothing.prototype.toEither = function (left) { | ||
return Either_1.Left(left); | ||
} | ||
ifJust(_) { | ||
}; | ||
Nothing.prototype.ifJust = function (_) { | ||
return this; | ||
} | ||
ifNothing(effect) { | ||
}; | ||
Nothing.prototype.ifNothing = function (effect) { | ||
return effect(), this; | ||
} | ||
filter(_) { | ||
}; | ||
Nothing.prototype.filter = function (_) { | ||
return nothing; | ||
} | ||
'fantasy-land/equals'(other) { | ||
}; | ||
Nothing.prototype['fantasy-land/equals'] = function (other) { | ||
return this.equals(other); | ||
} | ||
'fantasy-land/map'(f) { | ||
}; | ||
Nothing.prototype['fantasy-land/map'] = function (f) { | ||
return this.map(f); | ||
} | ||
'fantasy-land/ap'(maybeF) { | ||
}; | ||
Nothing.prototype['fantasy-land/ap'] = function (maybeF) { | ||
return this.ap(maybeF); | ||
} | ||
'fantasy-land/alt'(other) { | ||
}; | ||
Nothing.prototype['fantasy-land/alt'] = function (other) { | ||
return this.alt(other); | ||
} | ||
'fantasy-land/chain'(f) { | ||
}; | ||
Nothing.prototype['fantasy-land/chain'] = function (f) { | ||
return this.chain(f); | ||
} | ||
'fantasy-land/reduce'(reducer, initialValue) { | ||
}; | ||
Nothing.prototype['fantasy-land/reduce'] = function (reducer, initialValue) { | ||
return this.reduce(reducer, initialValue); | ||
} | ||
'fantasy-land/extend'(f) { | ||
}; | ||
Nothing.prototype['fantasy-land/extend'] = function (f) { | ||
return this.extend(f); | ||
} | ||
} | ||
}; | ||
return Nothing; | ||
}()); | ||
Nothing.prototype.constructor = exports.Maybe; | ||
/** Constructs a Just. Respents an optional value that exists. */ | ||
const just = (value) => new Just(value); | ||
var just = function (value) { return new Just(value); }; | ||
exports.Just = just; | ||
/** Represents a missing value, you can think of it as a smart 'null'. */ | ||
const nothing = new Nothing(); | ||
var nothing = new Nothing(); | ||
exports.Nothing = nothing; |
@@ -10,7 +10,34 @@ "use strict"; | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Maybe_1 = require("./Maybe"); | ||
const EitherAsync_1 = require("./EitherAsync"); | ||
const helpers = { | ||
liftMaybe(maybe) { | ||
var Maybe_1 = require("./Maybe"); | ||
var EitherAsync_1 = require("./EitherAsync"); | ||
var helpers = { | ||
liftMaybe: function (maybe) { | ||
if (maybe.isNothing()) { | ||
@@ -21,43 +48,73 @@ throw Maybe_1.Nothing; | ||
}, | ||
fromPromise(promise) { | ||
fromPromise: function (promise) { | ||
return promise.then(helpers.liftMaybe); | ||
} | ||
}; | ||
class MaybeAsyncImpl { | ||
constructor(runPromise) { | ||
var MaybeAsyncImpl = /** @class */ (function () { | ||
function MaybeAsyncImpl(runPromise) { | ||
this.runPromise = runPromise; | ||
} | ||
run() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
return Maybe_1.Just(yield this.runPromise(helpers)); | ||
} | ||
catch (_a) { | ||
return Maybe_1.Nothing; | ||
} | ||
MaybeAsyncImpl.prototype.run = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _a, _b; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
_c.trys.push([0, 2, , 3]); | ||
_a = Maybe_1.Just; | ||
return [4 /*yield*/, this.runPromise(helpers)]; | ||
case 1: return [2 /*return*/, _a.apply(void 0, [_c.sent()])]; | ||
case 2: | ||
_b = _c.sent(); | ||
return [2 /*return*/, Maybe_1.Nothing]; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
map(f) { | ||
return exports.MaybeAsync(helpers => this.runPromise(helpers).then(f)); | ||
} | ||
chain(f) { | ||
return exports.MaybeAsync((helpers) => __awaiter(this, void 0, void 0, function* () { | ||
const value = yield this.runPromise(helpers); | ||
return yield helpers.fromPromise(f(value).run()); | ||
})); | ||
} | ||
toEitherAsync(error) { | ||
return EitherAsync_1.EitherAsync(({ liftEither }) => __awaiter(this, void 0, void 0, function* () { | ||
const maybe = yield this.run(); | ||
return liftEither(maybe.toEither(error)); | ||
})); | ||
} | ||
'fantasy-land/map'(f) { | ||
}; | ||
MaybeAsyncImpl.prototype.map = function (f) { | ||
var _this = this; | ||
return exports.MaybeAsync(function (helpers) { return _this.runPromise(helpers).then(f); }); | ||
}; | ||
MaybeAsyncImpl.prototype.chain = function (f) { | ||
var _this = this; | ||
return exports.MaybeAsync(function (helpers) { return __awaiter(_this, void 0, void 0, function () { | ||
var value; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.runPromise(helpers)]; | ||
case 1: | ||
value = _a.sent(); | ||
return [4 /*yield*/, helpers.fromPromise(f(value).run())]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); }); | ||
}; | ||
MaybeAsyncImpl.prototype.toEitherAsync = function (error) { | ||
var _this = this; | ||
return EitherAsync_1.EitherAsync(function (_a) { | ||
var liftEither = _a.liftEither; | ||
return __awaiter(_this, void 0, void 0, function () { | ||
var maybe; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, this.run()]; | ||
case 1: | ||
maybe = _b.sent(); | ||
return [2 /*return*/, liftEither(maybe.toEither(error))]; | ||
} | ||
}); | ||
}); | ||
}); | ||
}; | ||
MaybeAsyncImpl.prototype['fantasy-land/map'] = function (f) { | ||
return this.map(f); | ||
} | ||
'fantasy-land/chain'(f) { | ||
}; | ||
MaybeAsyncImpl.prototype['fantasy-land/chain'] = function (f) { | ||
return this.chain(f); | ||
} | ||
} | ||
}; | ||
return MaybeAsyncImpl; | ||
}()); | ||
/** Constructs a MaybeAsync object from a function that takes an object full of helpers that let you lift things into the MaybeAsync context and returns a Promise */ | ||
exports.MaybeAsync = (runPromise) => new MaybeAsyncImpl(runPromise); | ||
exports.MaybeAsync = function (runPromise) { return new MaybeAsyncImpl(runPromise); }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Maybe_1 = require("./Maybe"); | ||
const NonEmptyListConstructor = (list) => list; | ||
var Maybe_1 = require("./Maybe"); | ||
var NonEmptyListConstructor = function (list) { return list; }; | ||
exports.NonEmptyList = Object.assign(NonEmptyListConstructor, { | ||
fromArray: (source) => exports.NonEmptyList.isNonEmpty(source) ? Maybe_1.Just(source) : Maybe_1.Nothing, | ||
unsafeCoerce: (source) => exports.NonEmptyList.isNonEmpty(source) | ||
? source | ||
: (() => { | ||
throw new Error('NonEmptyList#unsafeCoerce passed an empty array'); | ||
})(), | ||
fromTuple: (source) => exports.NonEmptyList(source.toArray()), | ||
head: (list) => list[0], | ||
last: (list) => list[list.length - 1], | ||
isNonEmpty: (list) => list.length > 0 | ||
fromArray: function (source) { | ||
return exports.NonEmptyList.isNonEmpty(source) ? Maybe_1.Just(source) : Maybe_1.Nothing; | ||
}, | ||
unsafeCoerce: function (source) { | ||
return exports.NonEmptyList.isNonEmpty(source) | ||
? source | ||
: (function () { | ||
throw new Error('NonEmptyList#unsafeCoerce passed an empty array'); | ||
})(); | ||
}, | ||
fromTuple: function (source) { | ||
return exports.NonEmptyList(source.toArray()); | ||
}, | ||
head: function (list) { return list[0]; }, | ||
last: function (list) { return list[list.length - 1]; }, | ||
isNonEmpty: function (list) { return list.length > 0; } | ||
}); |
{ | ||
"name": "purify-ts", | ||
"version": "0.13.0", | ||
"version": "0.13.1", | ||
"description": "Functional programming standard library for TypeScript ", | ||
@@ -33,5 +33,5 @@ "main": "lib/index.js", | ||
"ts-jest": "^24.0.0", | ||
"typescript": "3.5.2" | ||
"typescript": "3.5.3" | ||
}, | ||
"dependencies": {} | ||
} |
144
Tuple.js
"use strict"; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class TupleImpl { | ||
constructor(first, second) { | ||
var TupleImpl = /** @class */ (function () { | ||
function TupleImpl(first, second) { | ||
this.first = first; | ||
@@ -11,67 +38,82 @@ this.second = second; | ||
} | ||
*[Symbol.iterator]() { | ||
yield this.first; | ||
yield this.second; | ||
} | ||
toJSON() { | ||
TupleImpl.prototype[Symbol.iterator] = function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.first]; | ||
case 1: | ||
_a.sent(); | ||
return [4 /*yield*/, this.second]; | ||
case 2: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}; | ||
TupleImpl.prototype.toJSON = function () { | ||
return this.toArray(); | ||
} | ||
inspect() { | ||
return `Tuple(${this.first}, ${this.second})`; | ||
} | ||
toString() { | ||
}; | ||
TupleImpl.prototype.inspect = function () { | ||
return "Tuple(" + this.first + ", " + this.second + ")"; | ||
}; | ||
TupleImpl.prototype.toString = function () { | ||
return this.inspect(); | ||
} | ||
fst() { | ||
}; | ||
TupleImpl.prototype.fst = function () { | ||
return this.first; | ||
} | ||
snd() { | ||
}; | ||
TupleImpl.prototype.snd = function () { | ||
return this.second; | ||
} | ||
equals(other) { | ||
}; | ||
TupleImpl.prototype.equals = function (other) { | ||
return this.first === other.fst() && this.second === other.snd(); | ||
} | ||
bimap(f, g) { | ||
}; | ||
TupleImpl.prototype.bimap = function (f, g) { | ||
return exports.Tuple(f(this.first), g(this.second)); | ||
} | ||
mapFirst(f) { | ||
}; | ||
TupleImpl.prototype.mapFirst = function (f) { | ||
return exports.Tuple(f(this.first), this.second); | ||
} | ||
map(f) { | ||
}; | ||
TupleImpl.prototype.map = function (f) { | ||
return exports.Tuple(this.first, f(this.second)); | ||
} | ||
reduce(reducer, initialValue) { | ||
}; | ||
TupleImpl.prototype.reduce = function (reducer, initialValue) { | ||
return reducer(initialValue, this.second); | ||
} | ||
toArray() { | ||
}; | ||
TupleImpl.prototype.toArray = function () { | ||
return [this.first, this.second]; | ||
} | ||
swap() { | ||
}; | ||
TupleImpl.prototype.swap = function () { | ||
return exports.Tuple(this.second, this.first); | ||
} | ||
ap(f) { | ||
}; | ||
TupleImpl.prototype.ap = function (f) { | ||
return exports.Tuple(this.first, f.snd()(this.second)); | ||
} | ||
'fantasy-land/equals'(other) { | ||
}; | ||
TupleImpl.prototype['fantasy-land/equals'] = function (other) { | ||
return this.equals(other); | ||
} | ||
'fantasy-land/bimap'(f, g) { | ||
}; | ||
TupleImpl.prototype['fantasy-land/bimap'] = function (f, g) { | ||
return this.bimap(f, g); | ||
} | ||
'fantasy-land/map'(f) { | ||
}; | ||
TupleImpl.prototype['fantasy-land/map'] = function (f) { | ||
return this.map(f); | ||
} | ||
'fantasy-land/reduce'(reducer, initialValue) { | ||
}; | ||
TupleImpl.prototype['fantasy-land/reduce'] = function (reducer, initialValue) { | ||
return this.reduce(reducer, initialValue); | ||
} | ||
'fantasy-land/ap'(f) { | ||
}; | ||
TupleImpl.prototype['fantasy-land/ap'] = function (f) { | ||
return this.ap(f); | ||
} | ||
} | ||
exports.Tuple = Object.assign((fst, snd) => new TupleImpl(fst, snd), { | ||
fromArray: ([fst, snd]) => { | ||
}; | ||
return TupleImpl; | ||
}()); | ||
exports.Tuple = Object.assign(function (fst, snd) { return new TupleImpl(fst, snd); }, { | ||
fromArray: function (_a) { | ||
var fst = _a[0], snd = _a[1]; | ||
return exports.Tuple(fst, snd); | ||
}, | ||
fanout: (...args) => { | ||
const [f, g, value] = args; | ||
fanout: function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var f = args[0], g = args[1], value = args[2]; | ||
switch (args.length) { | ||
@@ -81,5 +123,7 @@ case 3: | ||
case 2: | ||
return (value) => exports.Tuple.fanout(f, g, value); | ||
return function (value) { return exports.Tuple.fanout(f, g, value); }; | ||
default: | ||
return (g) => (value) => exports.Tuple.fanout(f, g, value); | ||
return function (g) { return function (value) { | ||
return exports.Tuple.fanout(f, g, value); | ||
}; }; | ||
} | ||
@@ -86,0 +130,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
224724
1460