try-typescript
Advanced tools
Comparing version
@@ -96,3 +96,3 @@ "use strict"; | ||
if (this.isSuccess()) { | ||
if (!(yield executionElement.functionData.func(this.value))) { | ||
if (yield executionElement.functionData.func(this.value)) { | ||
yield executionElement.functionData.fallbackFunction(this.value); | ||
@@ -104,3 +104,3 @@ } | ||
if (this.isSuccess()) { | ||
if (yield executionElement.functionData.func(this.value)) { | ||
if (!(yield executionElement.functionData.func(this.value))) { | ||
yield executionElement.functionData.fallbackFunction(this.value); | ||
@@ -107,0 +107,0 @@ } |
@@ -93,9 +93,2 @@ "use strict"; | ||
})); | ||
test("map should transform the value of an async function inside Success", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const result = __1.Try.success(2) | ||
.map(v => v * 2) | ||
.map(v => v * 2); | ||
yield expect(result.get()).resolves.toBe(4); | ||
expect(result.isSuccess()).toBe(true); | ||
})); | ||
}); | ||
@@ -115,5 +108,5 @@ describe("Try.flatMap", () => { | ||
}); | ||
describe("Try.filter", () => { | ||
describe("Try.filterNot", () => { | ||
test("filter should return Failure if predicate does not hold", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const result = __1.Try.success(2).filter(v => v > 2); | ||
const result = __1.Try.success(2).filterNot(v => v > 2); | ||
yield expect(result.get()).rejects.toThrow("Predicate does not hold for 2"); | ||
@@ -123,3 +116,3 @@ expect(result.isFailure()).toBe(true); | ||
test("filter should throw custom exception if predicate does not hold", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const result = __1.Try.success(2).filter(v => v > 2, v => { throw new Error("Custom Predicate does not hold for " + v); }); | ||
const result = __1.Try.success(2).filterNot(v => v > 2, v => { throw new Error("Custom Predicate does not hold for " + v); }); | ||
yield expect(result.get()).rejects.toThrow("Custom Predicate does not hold for 2"); | ||
@@ -129,3 +122,3 @@ expect(result.isFailure()).toBe(true); | ||
test("filter should return Success if predicate holds", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const result = __1.Try.success(2).filter(v => v <= 2); | ||
const result = __1.Try.success(2).filterNot(v => v <= 2); | ||
yield expect(result.get()).resolves.toBe(2); | ||
@@ -135,5 +128,5 @@ expect(result.isSuccess()).toBe(true); | ||
}); | ||
describe("Try.filterNot", () => { | ||
describe("Try.filter", () => { | ||
test("filterNot should return Failure if predicate does not hold", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const result = __1.Try.success(2).filterNot(v => v <= 2); | ||
const result = __1.Try.success(2).filter(v => v <= 2); | ||
yield expect(result.get()).rejects.toThrow("Predicate does not hold for 2"); | ||
@@ -143,3 +136,3 @@ expect(result.isFailure()).toBe(true); | ||
test("filterNot should throw custom exception if predicate does not hold", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const result = __1.Try.success(2).filterNot(v => v <= 2, v => { throw new Error("Custom Predicate does not hold for " + v); }); | ||
const result = __1.Try.success(2).filter(v => v <= 2, v => { throw new Error("Custom Predicate does not hold for " + v); }); | ||
yield expect(result.get()).rejects.toThrow("Custom Predicate does not hold for 2"); | ||
@@ -149,3 +142,3 @@ expect(result.isFailure()).toBe(true); | ||
test("filterNot should return Success if predicate holds", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const result = __1.Try.success(2).filterNot(v => v > 2); | ||
const result = __1.Try.success(2).filter(v => v > 2); | ||
yield expect(result.get()).resolves.toBe(2); | ||
@@ -152,0 +145,0 @@ expect(result.isSuccess()).toBe(true); |
{ | ||
"name": "try-typescript", | ||
"version": "0.4.5", | ||
"version": "0.4.6", | ||
"description": "This repository implements a Try class inspired by the Vavr library in Java. The Try class is a functional programming construct for handling computations that may succeed or fail. It encapsulates exceptions and streamlines error handling, reducing boilerplate code and enhancing code readability. ", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
41360
-0.89%565
-1.22%