Comparing version 0.14.1 to 0.15.0
@@ -20,4 +20,8 @@ import { Either } from './Either'; | ||
map<R2>(f: (value: R) => R2): EitherAsync<L, R2>; | ||
/** Maps the `Left` value of `this`, acts like an identity if `this` is `Right` */ | ||
mapLeft<L2>(f: (value: L) => L2): EitherAsync<L2, R>; | ||
/** Transforms `this` with a function that returns a `EitherAsync`. Behaviour is the same as the regular Either#chain */ | ||
chain<R2>(f: (value: R) => EitherAsync<L, R2>): EitherAsync<L, R2>; | ||
/** The same as EitherAsync#chain but executes the transformation function only if the value is Left. Useful for recovering from errors */ | ||
chainLeft<L2>(f: (value: L) => EitherAsync<L2, R>): EitherAsync<L2, R>; | ||
/** Converts `this` to a MaybeAsync, discarding any error values */ | ||
@@ -24,0 +28,0 @@ toMaybeAsync(): MaybeAsync<R>; |
@@ -81,2 +81,20 @@ "use strict"; | ||
}; | ||
EitherAsyncImpl.prototype.mapLeft = function (f) { | ||
var _this = this; | ||
return exports.EitherAsync(function (helpers) { return __awaiter(_this, void 0, void 0, function () { | ||
var e_2; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, this.runPromise(helpers)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
case 2: | ||
e_2 = _a.sent(); | ||
throw f(e_2); | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
}; | ||
EitherAsyncImpl.prototype.chain = function (f) { | ||
@@ -91,4 +109,3 @@ var _this = this; | ||
value = _a.sent(); | ||
return [4 /*yield*/, helpers.fromPromise(f(value).run())]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
return [2 /*return*/, helpers.fromPromise(f(value).run())]; | ||
} | ||
@@ -98,2 +115,20 @@ }); | ||
}; | ||
EitherAsyncImpl.prototype.chainLeft = function (f) { | ||
var _this = this; | ||
return exports.EitherAsync(function (helpers) { return __awaiter(_this, void 0, void 0, function () { | ||
var e_3; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, this.runPromise(helpers)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
case 2: | ||
e_3 = _a.sent(); | ||
return [2 /*return*/, helpers.fromPromise(f(e_3).run())]; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
}; | ||
EitherAsyncImpl.prototype.toMaybeAsync = function () { | ||
@@ -100,0 +135,0 @@ var _this = this; |
@@ -20,4 +20,8 @@ import { Either } from './Either'; | ||
map<R2>(f: (value: R) => R2): EitherAsync<L, R2>; | ||
/** Maps the `Left` value of `this`, acts like an identity if `this` is `Right` */ | ||
mapLeft<L2>(f: (value: L) => L2): EitherAsync<L2, R>; | ||
/** Transforms `this` with a function that returns a `EitherAsync`. Behaviour is the same as the regular Either#chain */ | ||
chain<R2>(f: (value: R) => EitherAsync<L, R2>): EitherAsync<L, R2>; | ||
/** The same as EitherAsync#chain but executes the transformation function only if the value is Left. Useful for recovering from errors */ | ||
chainLeft<L2>(f: (value: L) => EitherAsync<L2, R>): EitherAsync<L2, R>; | ||
/** Converts `this` to a MaybeAsync, discarding any error values */ | ||
@@ -24,0 +28,0 @@ toMaybeAsync(): MaybeAsync<R>; |
@@ -34,8 +34,28 @@ "use strict"; | ||
} | ||
mapLeft(f) { | ||
return exports.EitherAsync(async (helpers) => { | ||
try { | ||
return await this.runPromise(helpers); | ||
} | ||
catch (e) { | ||
throw f(e); | ||
} | ||
}); | ||
} | ||
chain(f) { | ||
return exports.EitherAsync(async (helpers) => { | ||
const value = await this.runPromise(helpers); | ||
return await helpers.fromPromise(f(value).run()); | ||
return helpers.fromPromise(f(value).run()); | ||
}); | ||
} | ||
chainLeft(f) { | ||
return exports.EitherAsync(async (helpers) => { | ||
try { | ||
return await this.runPromise(helpers); | ||
} | ||
catch (e) { | ||
return helpers.fromPromise(f(e).run()); | ||
} | ||
}); | ||
} | ||
toMaybeAsync() { | ||
@@ -42,0 +62,0 @@ return MaybeAsync_1.MaybeAsync(async ({ liftMaybe }) => { |
{ | ||
"name": "purify-ts", | ||
"version": "0.14.1", | ||
"version": "0.15.0", | ||
"description": "Functional programming standard library for TypeScript ", | ||
@@ -30,6 +30,6 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@types/jest": "^24.0.0", | ||
"jest": "^24.1.0", | ||
"@types/jest": "^25.1.1", | ||
"jest": "^25.1.0", | ||
"prettier": "^1.19.1", | ||
"ts-jest": "^24.0.0", | ||
"ts-jest": "^25.0.0", | ||
"typescript": "3.7.5" | ||
@@ -36,0 +36,0 @@ }, |
@@ -15,3 +15,3 @@ <h3 align="center"> | ||
Purify is a library for functional programming in TypeScript. | ||
It's purpose is to allow developers to use popular patterns and abstractions that are available in most functional languages. | ||
Its purpose is to allow developers to use popular patterns and abstractions that are available in most functional languages. | ||
It is also <a href="https://github.com/fantasyland/fantasy-land">Fantasy Land</a> conformant. | ||
@@ -18,0 +18,0 @@ |
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
162075
3633