return-style
Advanced tools
Comparing version 0.12.3 to 0.12.4
@@ -5,2 +5,4 @@ # Changelog | ||
### [0.12.4](https://github.com/BlackGlory/return-style/compare/v0.12.3...v0.12.4) (2021-10-14) | ||
### [0.12.3](https://github.com/BlackGlory/return-style/compare/v0.12.2...v0.12.3) (2021-03-20) | ||
@@ -7,0 +9,0 @@ |
@@ -5,3 +5,3 @@ (function (global, factory) { | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReturnStyle = {}, global.go)); | ||
}(this, (function (exports, go) { 'use strict'; | ||
})(this, (function (exports, go) { 'use strict'; | ||
@@ -63,15 +63,13 @@ function getErrorResult(fn) { | ||
function __classPrivateFieldGet(receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
function __classPrivateFieldGet(receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
} | ||
function __classPrivateFieldSet(receiver, privateMap, value) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to set private field on non-instance"); | ||
} | ||
privateMap.set(receiver, value); | ||
return value; | ||
function __classPrivateFieldSet(receiver, state, value, kind, f) { | ||
if (kind === "m") throw new TypeError("Private method is not writable"); | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
} | ||
@@ -363,3 +361,3 @@ | ||
var _value$1, _value_1; | ||
var _Ok_value, _Err_value; | ||
class Result { | ||
@@ -376,4 +374,4 @@ static Ok(value) { | ||
super(); | ||
_value$1.set(this, void 0); | ||
__classPrivateFieldSet(this, _value$1, value); | ||
_Ok_value.set(this, void 0); | ||
__classPrivateFieldSet(this, _Ok_value, value, "f"); | ||
} | ||
@@ -390,24 +388,24 @@ static of(value) { | ||
onOk(callback) { | ||
callback(__classPrivateFieldGet(this, _value$1)); | ||
return Ok.of(__classPrivateFieldGet(this, _value$1)); | ||
callback(__classPrivateFieldGet(this, _Ok_value, "f")); | ||
return Ok.of(__classPrivateFieldGet(this, _Ok_value, "f")); | ||
} | ||
onErr() { | ||
return Ok.of(__classPrivateFieldGet(this, _value$1)); | ||
return Ok.of(__classPrivateFieldGet(this, _Ok_value, "f")); | ||
} | ||
orElse() { | ||
return Ok.of(__classPrivateFieldGet(this, _value$1)); | ||
return Ok.of(__classPrivateFieldGet(this, _Ok_value, "f")); | ||
} | ||
map(fn) { | ||
return Ok.of(fn(__classPrivateFieldGet(this, _value$1))); | ||
return Ok.of(fn(__classPrivateFieldGet(this, _Ok_value, "f"))); | ||
} | ||
get() { | ||
return __classPrivateFieldGet(this, _value$1); | ||
return __classPrivateFieldGet(this, _Ok_value, "f"); | ||
} | ||
} | ||
_value$1 = new WeakMap(); | ||
_Ok_value = new WeakMap(); | ||
class Err extends Result { | ||
constructor(err) { | ||
super(); | ||
_value_1.set(this, void 0); | ||
__classPrivateFieldSet(this, _value_1, err); | ||
_Err_value.set(this, void 0); | ||
__classPrivateFieldSet(this, _Err_value, err, "f"); | ||
} | ||
@@ -424,7 +422,7 @@ static of(error) { | ||
onOk() { | ||
return Err.of(__classPrivateFieldGet(this, _value_1)); | ||
return Err.of(__classPrivateFieldGet(this, _Err_value, "f")); | ||
} | ||
onErr(callback) { | ||
callback(__classPrivateFieldGet(this, _value_1)); | ||
return Err.of(__classPrivateFieldGet(this, _value_1)); | ||
callback(__classPrivateFieldGet(this, _Err_value, "f")); | ||
return Err.of(__classPrivateFieldGet(this, _Err_value, "f")); | ||
} | ||
@@ -435,9 +433,9 @@ orElse(defaultValue) { | ||
map() { | ||
return Err.of(__classPrivateFieldGet(this, _value_1)); | ||
return Err.of(__classPrivateFieldGet(this, _Err_value, "f")); | ||
} | ||
get() { | ||
throw __classPrivateFieldGet(this, _value_1); | ||
throw __classPrivateFieldGet(this, _Err_value, "f"); | ||
} | ||
} | ||
_value_1 = new WeakMap(); | ||
_Err_value = new WeakMap(); | ||
@@ -454,7 +452,7 @@ function toResult(fn) { | ||
var _promise$1; | ||
var _AsyncResult_promise; | ||
class AsyncResult { | ||
constructor(promise) { | ||
_promise$1.set(this, void 0); | ||
__classPrivateFieldSet(this, _promise$1, Promise.resolve(promise)); | ||
_AsyncResult_promise.set(this, void 0); | ||
__classPrivateFieldSet(this, _AsyncResult_promise, Promise.resolve(promise), "f"); | ||
} | ||
@@ -468,3 +466,3 @@ static Ok(value) { | ||
get then() { | ||
const promise = __classPrivateFieldGet(this, _promise$1).then(x => Result.Ok(x), x => Result.Err(x)); | ||
const promise = __classPrivateFieldGet(this, _AsyncResult_promise, "f").then(x => Result.Ok(x), x => Result.Err(x)); | ||
return promise.then.bind(promise); | ||
@@ -474,19 +472,19 @@ } | ||
go.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const [succ, ret] = yield getSuccessPromise(__classPrivateFieldGet(this, _promise$1)); | ||
const [succ, ret] = yield getSuccessPromise(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
if (succ) | ||
callback(ret); | ||
})); | ||
return new AsyncResult(__classPrivateFieldGet(this, _promise$1)); | ||
return new AsyncResult(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
} | ||
onErr(callback) { | ||
go.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const [fail, err] = yield getFailurePromise(__classPrivateFieldGet(this, _promise$1)); | ||
const [fail, err] = yield getFailurePromise(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
if (fail) | ||
callback(err); | ||
})); | ||
return new AsyncResult(__classPrivateFieldGet(this, _promise$1)); | ||
return new AsyncResult(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
} | ||
isOk() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield isSuccessPromise(__classPrivateFieldGet(this, _promise$1)); | ||
return yield isSuccessPromise(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
}); | ||
@@ -496,3 +494,3 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield isFailurePromise(__classPrivateFieldGet(this, _promise$1)); | ||
return yield isFailurePromise(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
}); | ||
@@ -503,3 +501,3 @@ } | ||
try { | ||
return yield __classPrivateFieldGet(this, _promise$1); | ||
return yield __classPrivateFieldGet(this, _AsyncResult_promise, "f"); | ||
} | ||
@@ -514,3 +512,3 @@ catch (_a) { | ||
const promise = go.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise$1); | ||
const result = yield __classPrivateFieldGet(this, _AsyncResult_promise, "f"); | ||
return mapper(result); | ||
@@ -522,7 +520,7 @@ })); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield __classPrivateFieldGet(this, _promise$1); | ||
return yield __classPrivateFieldGet(this, _AsyncResult_promise, "f"); | ||
}); | ||
} | ||
} | ||
_promise$1 = new WeakMap(); | ||
_AsyncResult_promise = new WeakMap(); | ||
class AsyncOk extends AsyncResult { | ||
@@ -559,3 +557,3 @@ static of(value) { | ||
var _value; | ||
var _Some_value; | ||
class Optional { | ||
@@ -572,4 +570,4 @@ static Some(value) { | ||
super(); | ||
_value.set(this, void 0); | ||
__classPrivateFieldSet(this, _value, value); | ||
_Some_value.set(this, void 0); | ||
__classPrivateFieldSet(this, _Some_value, value, "f"); | ||
} | ||
@@ -586,17 +584,17 @@ static of(value) { | ||
onSome(callback) { | ||
callback(__classPrivateFieldGet(this, _value)); | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
callback(__classPrivateFieldGet(this, _Some_value, "f")); | ||
return Some.of(__classPrivateFieldGet(this, _Some_value, "f")); | ||
} | ||
onNone() { | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
return Some.of(__classPrivateFieldGet(this, _Some_value, "f")); | ||
} | ||
orElse() { | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
return Some.of(__classPrivateFieldGet(this, _Some_value, "f")); | ||
} | ||
map(mapper) { | ||
return Some.of(mapper(__classPrivateFieldGet(this, _value))); | ||
return Some.of(mapper(__classPrivateFieldGet(this, _Some_value, "f"))); | ||
} | ||
filter(predicate) { | ||
if (predicate(__classPrivateFieldGet(this, _value))) { | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
if (predicate(__classPrivateFieldGet(this, _Some_value, "f"))) { | ||
return Some.of(__classPrivateFieldGet(this, _Some_value, "f")); | ||
} | ||
@@ -608,6 +606,6 @@ else { | ||
get() { | ||
return __classPrivateFieldGet(this, _value); | ||
return __classPrivateFieldGet(this, _Some_value, "f"); | ||
} | ||
} | ||
_value = new WeakMap(); | ||
_Some_value = new WeakMap(); | ||
class None extends Optional { | ||
@@ -660,8 +658,8 @@ static of() { | ||
var _promise; | ||
var _AsyncOptional_promise; | ||
const Nil = Symbol(); | ||
class AsyncOptional { | ||
constructor(promise) { | ||
_promise.set(this, void 0); | ||
__classPrivateFieldSet(this, _promise, Promise.resolve(promise)); | ||
_AsyncOptional_promise.set(this, void 0); | ||
__classPrivateFieldSet(this, _AsyncOptional_promise, Promise.resolve(promise), "f"); | ||
} | ||
@@ -675,3 +673,3 @@ static Some(value) { | ||
get then() { | ||
const promise = __classPrivateFieldGet(this, _promise).then(x => x === Nil | ||
const promise = __classPrivateFieldGet(this, _AsyncOptional_promise, "f").then(x => x === Nil | ||
? Optional.None() | ||
@@ -683,19 +681,19 @@ : Optional.Some(x)); | ||
go.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
const result = yield __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result !== Nil) | ||
callback(result); | ||
})); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _promise)); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _AsyncOptional_promise, "f")); | ||
} | ||
onNone(callback) { | ||
go.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
const result = yield __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result === Nil) | ||
callback(); | ||
})); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _promise)); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _AsyncOptional_promise, "f")); | ||
} | ||
isSome() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
const result = yield __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
return result !== Nil; | ||
@@ -706,3 +704,3 @@ }); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
const result = yield __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
return result === Nil; | ||
@@ -713,3 +711,3 @@ }); | ||
const promise = go.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
const result = yield __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result === Nil) | ||
@@ -723,3 +721,3 @@ return defaultValue; | ||
const promise = go.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
const result = yield __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result === Nil) | ||
@@ -733,3 +731,3 @@ return Nil; | ||
const promise = go.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
const result = yield __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result === Nil) | ||
@@ -745,3 +743,3 @@ return Nil; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
const result = yield __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result === Nil) | ||
@@ -753,3 +751,3 @@ throw new Error('Cannot get value from None'); | ||
} | ||
_promise = new WeakMap(); | ||
_AsyncOptional_promise = new WeakMap(); | ||
class AsyncNone extends AsyncOptional { | ||
@@ -834,3 +832,3 @@ static of() { | ||
}))); | ||
})); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -16,3 +16,3 @@ !function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@blackglory/go")):"function"==typeof define&&define.amd?define(["exports","@blackglory/go"],r):r((t="undefined"!=typeof globalThis?globalThis:t||self).ReturnStyle={},t.go)}(this,(function(t,r){"use strict"; | ||
***************************************************************************** */ | ||
function n(t,r,n,e){return new(n||(n=Promise))((function(o,i){function u(t){try{c(e.next(t))}catch(t){i(t)}}function s(t){try{c(e.throw(t))}catch(t){i(t)}}function c(t){var r;t.done?o(t.value):(r=t.value,r instanceof n?r:new n((function(t){t(r)}))).then(u,s)}c((e=e.apply(t,r||[])).next())}))}function e(t){var r="function"==typeof Symbol&&Symbol.iterator,n=r&&t[r],e=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],done:!t}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")}function o(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,n=t[Symbol.asyncIterator];return n?n.call(t):(t=e(t),r={},o("next"),o("throw"),o("return"),r[Symbol.asyncIterator]=function(){return this},r);function o(n){r[n]=t[n]&&function(r){return new Promise((function(e,o){(function(t,r,n,e){Promise.resolve(e).then((function(r){t({value:r,done:n})}),r)})(e,o,(r=t[n](r)).done,r.value)}))}}}function i(t,r){if(!r.has(t))throw new TypeError("attempted to get private field on non-instance");return r.get(t)}function u(t,r,n){if(!r.has(t))throw new TypeError("attempted to set private field on non-instance");return r.set(t,n),n}function s(t){return n(this,void 0,void 0,(function*(){try{return[!0,yield t]}catch(t){return[!1,void 0]}}))}function c(t){return n(this,void 0,void 0,(function*(){try{return yield t,[!1,void 0]}catch(t){return[!0,t]}}))}function d(t){return n(this,void 0,void 0,(function*(){try{return yield t,!0}catch(t){return!1}}))}function f(t){return n(this,void 0,void 0,(function*(){try{return yield t,!1}catch(t){return!0}}))}var a,h,l,v,y;class g{static Ok(t){return m.of(t)}static Err(t){return p.of(t)}}class m extends g{constructor(t){super(),a.set(this,void 0),u(this,a,t)}static of(t){return new m(t)}isOk(){return!0}isErr(){return!1}onOk(t){return t(i(this,a)),m.of(i(this,a))}onErr(){return m.of(i(this,a))}orElse(){return m.of(i(this,a))}map(t){return m.of(t(i(this,a)))}get(){return i(this,a)}}a=new WeakMap;class p extends g{constructor(t){super(),h.set(this,void 0),u(this,h,t)}static of(t){return new p(t)}isOk(){return!1}isErr(){return!0}onOk(){return p.of(i(this,h))}onErr(t){return t(i(this,h)),p.of(i(this,h))}orElse(t){return m.of(t)}map(){return p.of(i(this,h))}get(){throw i(this,h)}}h=new WeakMap;class w{constructor(t){l.set(this,void 0),u(this,l,Promise.resolve(t))}static Ok(t){return E.of(t)}static Err(t){return S.of(t)}get then(){const t=i(this,l).then((t=>g.Ok(t)),(t=>g.Err(t)));return t.then.bind(t)}onOk(t){return r.go((()=>n(this,void 0,void 0,(function*(){const[r,n]=yield s(i(this,l));r&&t(n)})))),new w(i(this,l))}onErr(t){return r.go((()=>n(this,void 0,void 0,(function*(){const[r,n]=yield c(i(this,l));r&&t(n)})))),new w(i(this,l))}isOk(){return n(this,void 0,void 0,(function*(){return yield d(i(this,l))}))}isErr(){return n(this,void 0,void 0,(function*(){return yield f(i(this,l))}))}orElse(t){const e=r.go((()=>n(this,void 0,void 0,(function*(){try{return yield i(this,l)}catch(r){return t}}))));return new w(e)}map(t){const e=r.go((()=>n(this,void 0,void 0,(function*(){const r=yield i(this,l);return t(r)}))));return new w(e)}get(){return n(this,void 0,void 0,(function*(){return yield i(this,l)}))}}l=new WeakMap;class E extends w{static of(t){return new E(t)}constructor(t){super(Promise.resolve(t))}}class S extends w{static of(t){return new S(t)}constructor(t){super(Promise.reject(t))}}class P{static Some(t){return b.of(t)}static None(){return O.of()}}class b extends P{constructor(t){super(),v.set(this,void 0),u(this,v,t)}static of(t){return new b(t)}isSome(){return!0}isNone(){return!1}onSome(t){return t(i(this,v)),b.of(i(this,v))}onNone(){return b.of(i(this,v))}orElse(){return b.of(i(this,v))}map(t){return b.of(t(i(this,v)))}filter(t){return t(i(this,v))?b.of(i(this,v)):O.of()}get(){return i(this,v)}}v=new WeakMap;class O extends P{static of(){return new O}constructor(){super()}isSome(){return!1}isNone(){return!0}onSome(){return O.of()}onNone(t){return t(),O.of()}orElse(t){return b.of(t)}map(){return O.of()}filter(){return O.of()}get(){throw new Error("Cannot get value from None")}}function k(t,r){const n=t();return r(n)?P.None():P.Some(n)}const x=Symbol();class R{constructor(t){y.set(this,void 0),u(this,y,Promise.resolve(t))}static Some(t){return N.of(t)}static None(){return A.of()}get then(){const t=i(this,y).then((t=>t===x?P.None():P.Some(t)));return t.then.bind(t)}onSome(t){return r.go((()=>n(this,void 0,void 0,(function*(){const r=yield i(this,y);r!==x&&t(r)})))),new R(i(this,y))}onNone(t){return r.go((()=>n(this,void 0,void 0,(function*(){(yield i(this,y))===x&&t()})))),new R(i(this,y))}isSome(){return n(this,void 0,void 0,(function*(){return(yield i(this,y))!==x}))}isNone(){return n(this,void 0,void 0,(function*(){return(yield i(this,y))===x}))}orElse(t){const e=r.go((()=>n(this,void 0,void 0,(function*(){const r=yield i(this,y);return r===x?t:r}))));return new R(e)}map(t){const e=r.go((()=>n(this,void 0,void 0,(function*(){const r=yield i(this,y);return r===x?x:t(r)}))));return new R(e)}filter(t){const e=r.go((()=>n(this,void 0,void 0,(function*(){const r=yield i(this,y);return r===x?x:t(r)?r:x}))));return new R(e)}get(){return n(this,void 0,void 0,(function*(){const t=yield i(this,y);if(t===x)throw new Error("Cannot get value from None");return t}))}}y=new WeakMap;class A extends R{static of(){return new A}constructor(){super(Promise.resolve(x))}}class N extends R{static of(t){return new N(t)}constructor(t){super(Promise.resolve(t))}}function F(t,e){const o=r.go((()=>n(this,void 0,void 0,(function*(){const r=yield t();return e(r)?x:r}))));return new R(o)}function M(t,e){return new R(r.go((()=>n(this,void 0,void 0,(function*(){const r=yield t;return e(r)?x:r})))))}t.getError=function(t){try{t()}catch(t){return t}},t.getErrorAsync=function(t){return n(this,void 0,void 0,(function*(){try{yield t()}catch(t){return t}}))},t.getErrorAsyncIterable=function(t){var r,e,i,u;return n(this,void 0,void 0,(function*(){try{try{for(r=o(t);!(e=yield r.next()).done;){e.value}}catch(t){i={error:t}}finally{try{e&&!e.done&&(u=r.return)&&(yield u.call(r))}finally{if(i)throw i.error}}}catch(t){return t}}))},t.getErrorPromise=function(t){return n(this,void 0,void 0,(function*(){try{yield t}catch(t){return t}}))},t.getErrorResult=function(t){try{return[void 0,t()]}catch(t){return[t,void 0]}},t.getErrorResultAsync=function(t){return n(this,void 0,void 0,(function*(){try{return[void 0,yield t()]}catch(t){return[t,void 0]}}))},t.getErrorResultPromise=function(t){return n(this,void 0,void 0,(function*(){try{return[void 0,yield t]}catch(t){return[t,void 0]}}))},t.getFailure=function(t){try{return t(),[!1,void 0]}catch(t){return[!0,t]}},t.getFailureAsync=function(t){return n(this,void 0,void 0,(function*(){try{return yield t(),[!1,void 0]}catch(t){return[!0,t]}}))},t.getFailurePromise=c,t.getResult=function(t){try{return t()}catch(t){return}},t.getResultAsync=function(t){return n(this,void 0,void 0,(function*(){try{return yield t()}catch(t){return}}))},t.getResultError=function(t){try{return[t(),void 0]}catch(t){return[void 0,t]}},t.getResultErrorAsync=function(t){return n(this,void 0,void 0,(function*(){try{return[yield t(),void 0]}catch(t){return[void 0,t]}}))},t.getResultErrorPromise=function(t){return n(this,void 0,void 0,(function*(){try{return[yield t,void 0]}catch(t){return[void 0,t]}}))},t.getResultPromise=function(t){return n(this,void 0,void 0,(function*(){try{return yield t}catch(t){return}}))},t.getSuccess=function(t){try{return[!0,t()]}catch(t){return[!1,void 0]}},t.getSuccessAsync=function(t){return n(this,void 0,void 0,(function*(){try{return[!0,yield t()]}catch(t){return[!1,void 0]}}))},t.getSuccessPromise=s,t.isFailure=function(t){try{return t(),!1}catch(t){return!0}},t.isFailureAsync=function(t){return n(this,void 0,void 0,(function*(){try{return yield t(),!1}catch(t){return!0}}))},t.isFailurePromise=f,t.isSuccess=function(t){try{return t(),!0}catch(t){return!1}},t.isSuccessAsync=function(t){return n(this,void 0,void 0,(function*(){try{return yield t(),!0}catch(t){return!1}}))},t.isSuccessPromise=d,t.toOptional=k,t.toOptionalAsync=F,t.toOptionalAsyncPartial=function(t){return r=>F(r,t)},t.toOptionalPartial=function(t){return r=>k(r,t)},t.toOptionalPromise=M,t.toOptionalPromisePartial=function(t){return r=>M(r,t)},t.toResult=function(t){try{const r=t();return g.Ok(r)}catch(t){return g.Err(t)}},t.toResultAsync=function(t){try{const r=t();return new w(r)}catch(t){return w.Err(t)}},t.toResultPromise=function(t){return new w(t)},Object.defineProperty(t,"__esModule",{value:!0})})); | ||
function n(t,r,n,e){return new(n||(n=Promise))((function(o,i){function u(t){try{c(e.next(t))}catch(t){i(t)}}function s(t){try{c(e.throw(t))}catch(t){i(t)}}function c(t){var r;t.done?o(t.value):(r=t.value,r instanceof n?r:new n((function(t){t(r)}))).then(u,s)}c((e=e.apply(t,r||[])).next())}))}function e(t){var r="function"==typeof Symbol&&Symbol.iterator,n=r&&t[r],e=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],done:!t}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")}function o(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,n=t[Symbol.asyncIterator];return n?n.call(t):(t=e(t),r={},o("next"),o("throw"),o("return"),r[Symbol.asyncIterator]=function(){return this},r);function o(n){r[n]=t[n]&&function(r){return new Promise((function(e,o){(function(t,r,n,e){Promise.resolve(e).then((function(r){t({value:r,done:n})}),r)})(e,o,(r=t[n](r)).done,r.value)}))}}}function i(t,r,n,e){if("a"===n&&!e)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof r?t!==r||!e:!r.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?e:"a"===n?e.call(t):e?e.value:r.get(t)}function u(t,r,n,e,o){if("m"===e)throw new TypeError("Private method is not writable");if("a"===e&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof r?t!==r||!o:!r.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===e?o.call(t,n):o?o.value=n:r.set(t,n),n}function s(t){return n(this,void 0,void 0,(function*(){try{return[!0,yield t]}catch(t){return[!1,void 0]}}))}function c(t){return n(this,void 0,void 0,(function*(){try{return yield t,[!1,void 0]}catch(t){return[!0,t]}}))}function f(t){return n(this,void 0,void 0,(function*(){try{return yield t,!0}catch(t){return!1}}))}function d(t){return n(this,void 0,void 0,(function*(){try{return yield t,!1}catch(t){return!0}}))}var a,h,l,v,y;class w{static Ok(t){return m.of(t)}static Err(t){return g.of(t)}}class m extends w{constructor(t){super(),a.set(this,void 0),u(this,a,t,"f")}static of(t){return new m(t)}isOk(){return!0}isErr(){return!1}onOk(t){return t(i(this,a,"f")),m.of(i(this,a,"f"))}onErr(){return m.of(i(this,a,"f"))}orElse(){return m.of(i(this,a,"f"))}map(t){return m.of(t(i(this,a,"f")))}get(){return i(this,a,"f")}}a=new WeakMap;class g extends w{constructor(t){super(),h.set(this,void 0),u(this,h,t,"f")}static of(t){return new g(t)}isOk(){return!1}isErr(){return!0}onOk(){return g.of(i(this,h,"f"))}onErr(t){return t(i(this,h,"f")),g.of(i(this,h,"f"))}orElse(t){return m.of(t)}map(){return g.of(i(this,h,"f"))}get(){throw i(this,h,"f")}}h=new WeakMap;class p{constructor(t){l.set(this,void 0),u(this,l,Promise.resolve(t),"f")}static Ok(t){return E.of(t)}static Err(t){return P.of(t)}get then(){const t=i(this,l,"f").then((t=>w.Ok(t)),(t=>w.Err(t)));return t.then.bind(t)}onOk(t){return r.go((()=>n(this,void 0,void 0,(function*(){const[r,n]=yield s(i(this,l,"f"));r&&t(n)})))),new p(i(this,l,"f"))}onErr(t){return r.go((()=>n(this,void 0,void 0,(function*(){const[r,n]=yield c(i(this,l,"f"));r&&t(n)})))),new p(i(this,l,"f"))}isOk(){return n(this,void 0,void 0,(function*(){return yield f(i(this,l,"f"))}))}isErr(){return n(this,void 0,void 0,(function*(){return yield d(i(this,l,"f"))}))}orElse(t){const e=r.go((()=>n(this,void 0,void 0,(function*(){try{return yield i(this,l,"f")}catch(r){return t}}))));return new p(e)}map(t){const e=r.go((()=>n(this,void 0,void 0,(function*(){const r=yield i(this,l,"f");return t(r)}))));return new p(e)}get(){return n(this,void 0,void 0,(function*(){return yield i(this,l,"f")}))}}l=new WeakMap;class E extends p{static of(t){return new E(t)}constructor(t){super(Promise.resolve(t))}}class P extends p{static of(t){return new P(t)}constructor(t){super(Promise.reject(t))}}class b{static Some(t){return S.of(t)}static None(){return O.of()}}class S extends b{constructor(t){super(),v.set(this,void 0),u(this,v,t,"f")}static of(t){return new S(t)}isSome(){return!0}isNone(){return!1}onSome(t){return t(i(this,v,"f")),S.of(i(this,v,"f"))}onNone(){return S.of(i(this,v,"f"))}orElse(){return S.of(i(this,v,"f"))}map(t){return S.of(t(i(this,v,"f")))}filter(t){return t(i(this,v,"f"))?S.of(i(this,v,"f")):O.of()}get(){return i(this,v,"f")}}v=new WeakMap;class O extends b{static of(){return new O}constructor(){super()}isSome(){return!1}isNone(){return!0}onSome(){return O.of()}onNone(t){return t(),O.of()}orElse(t){return S.of(t)}map(){return O.of()}filter(){return O.of()}get(){throw new Error("Cannot get value from None")}}function k(t,r){const n=t();return r(n)?b.None():b.Some(n)}const x=Symbol();class R{constructor(t){y.set(this,void 0),u(this,y,Promise.resolve(t),"f")}static Some(t){return N.of(t)}static None(){return A.of()}get then(){const t=i(this,y,"f").then((t=>t===x?b.None():b.Some(t)));return t.then.bind(t)}onSome(t){return r.go((()=>n(this,void 0,void 0,(function*(){const r=yield i(this,y,"f");r!==x&&t(r)})))),new R(i(this,y,"f"))}onNone(t){return r.go((()=>n(this,void 0,void 0,(function*(){(yield i(this,y,"f"))===x&&t()})))),new R(i(this,y,"f"))}isSome(){return n(this,void 0,void 0,(function*(){return(yield i(this,y,"f"))!==x}))}isNone(){return n(this,void 0,void 0,(function*(){return(yield i(this,y,"f"))===x}))}orElse(t){const e=r.go((()=>n(this,void 0,void 0,(function*(){const r=yield i(this,y,"f");return r===x?t:r}))));return new R(e)}map(t){const e=r.go((()=>n(this,void 0,void 0,(function*(){const r=yield i(this,y,"f");return r===x?x:t(r)}))));return new R(e)}filter(t){const e=r.go((()=>n(this,void 0,void 0,(function*(){const r=yield i(this,y,"f");return r===x?x:t(r)?r:x}))));return new R(e)}get(){return n(this,void 0,void 0,(function*(){const t=yield i(this,y,"f");if(t===x)throw new Error("Cannot get value from None");return t}))}}y=new WeakMap;class A extends R{static of(){return new A}constructor(){super(Promise.resolve(x))}}class N extends R{static of(t){return new N(t)}constructor(t){super(Promise.resolve(t))}}function T(t,e){const o=r.go((()=>n(this,void 0,void 0,(function*(){const r=yield t();return e(r)?x:r}))));return new R(o)}function j(t,e){return new R(r.go((()=>n(this,void 0,void 0,(function*(){const r=yield t;return e(r)?x:r})))))}t.getError=function(t){try{t()}catch(t){return t}},t.getErrorAsync=function(t){return n(this,void 0,void 0,(function*(){try{yield t()}catch(t){return t}}))},t.getErrorAsyncIterable=function(t){var r,e,i,u;return n(this,void 0,void 0,(function*(){try{try{for(r=o(t);!(e=yield r.next()).done;){e.value}}catch(t){i={error:t}}finally{try{e&&!e.done&&(u=r.return)&&(yield u.call(r))}finally{if(i)throw i.error}}}catch(t){return t}}))},t.getErrorPromise=function(t){return n(this,void 0,void 0,(function*(){try{yield t}catch(t){return t}}))},t.getErrorResult=function(t){try{return[void 0,t()]}catch(t){return[t,void 0]}},t.getErrorResultAsync=function(t){return n(this,void 0,void 0,(function*(){try{return[void 0,yield t()]}catch(t){return[t,void 0]}}))},t.getErrorResultPromise=function(t){return n(this,void 0,void 0,(function*(){try{return[void 0,yield t]}catch(t){return[t,void 0]}}))},t.getFailure=function(t){try{return t(),[!1,void 0]}catch(t){return[!0,t]}},t.getFailureAsync=function(t){return n(this,void 0,void 0,(function*(){try{return yield t(),[!1,void 0]}catch(t){return[!0,t]}}))},t.getFailurePromise=c,t.getResult=function(t){try{return t()}catch(t){return}},t.getResultAsync=function(t){return n(this,void 0,void 0,(function*(){try{return yield t()}catch(t){return}}))},t.getResultError=function(t){try{return[t(),void 0]}catch(t){return[void 0,t]}},t.getResultErrorAsync=function(t){return n(this,void 0,void 0,(function*(){try{return[yield t(),void 0]}catch(t){return[void 0,t]}}))},t.getResultErrorPromise=function(t){return n(this,void 0,void 0,(function*(){try{return[yield t,void 0]}catch(t){return[void 0,t]}}))},t.getResultPromise=function(t){return n(this,void 0,void 0,(function*(){try{return yield t}catch(t){return}}))},t.getSuccess=function(t){try{return[!0,t()]}catch(t){return[!1,void 0]}},t.getSuccessAsync=function(t){return n(this,void 0,void 0,(function*(){try{return[!0,yield t()]}catch(t){return[!1,void 0]}}))},t.getSuccessPromise=s,t.isFailure=function(t){try{return t(),!1}catch(t){return!0}},t.isFailureAsync=function(t){return n(this,void 0,void 0,(function*(){try{return yield t(),!1}catch(t){return!0}}))},t.isFailurePromise=d,t.isSuccess=function(t){try{return t(),!0}catch(t){return!1}},t.isSuccessAsync=function(t){return n(this,void 0,void 0,(function*(){try{return yield t(),!0}catch(t){return!1}}))},t.isSuccessPromise=f,t.toOptional=k,t.toOptionalAsync=T,t.toOptionalAsyncPartial=function(t){return r=>T(r,t)},t.toOptionalPartial=function(t){return r=>k(r,t)},t.toOptionalPromise=j,t.toOptionalPromisePartial=function(t){return r=>j(r,t)},t.toResult=function(t){try{const r=t();return w.Ok(r)}catch(t){return w.Err(t)}},t.toResultAsync=function(t){try{const r=t();return new p(r)}catch(t){return p.Err(t)}},t.toResultPromise=function(t){return new p(t)},Object.defineProperty(t,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.umd.min.js.map |
@@ -5,3 +5,3 @@ (function (global, factory) { | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReturnStyle = {}, global.go)); | ||
}(this, (function (exports, go) { 'use strict'; | ||
})(this, (function (exports, go) { 'use strict'; | ||
@@ -270,18 +270,16 @@ function getErrorResult(fn) { | ||
function __classPrivateFieldGet(receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
function __classPrivateFieldGet(receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
} | ||
function __classPrivateFieldSet(receiver, privateMap, value) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to set private field on non-instance"); | ||
} | ||
privateMap.set(receiver, value); | ||
return value; | ||
function __classPrivateFieldSet(receiver, state, value, kind, f) { | ||
if (kind === "m") throw new TypeError("Private method is not writable"); | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
} | ||
var _value$1, _value_1; | ||
var _Ok_value, _Err_value; | ||
class Result { | ||
@@ -298,4 +296,4 @@ static Ok(value) { | ||
super(); | ||
_value$1.set(this, void 0); | ||
__classPrivateFieldSet(this, _value$1, value); | ||
_Ok_value.set(this, void 0); | ||
__classPrivateFieldSet(this, _Ok_value, value, "f"); | ||
} | ||
@@ -312,24 +310,24 @@ static of(value) { | ||
onOk(callback) { | ||
callback(__classPrivateFieldGet(this, _value$1)); | ||
return Ok.of(__classPrivateFieldGet(this, _value$1)); | ||
callback(__classPrivateFieldGet(this, _Ok_value, "f")); | ||
return Ok.of(__classPrivateFieldGet(this, _Ok_value, "f")); | ||
} | ||
onErr() { | ||
return Ok.of(__classPrivateFieldGet(this, _value$1)); | ||
return Ok.of(__classPrivateFieldGet(this, _Ok_value, "f")); | ||
} | ||
orElse() { | ||
return Ok.of(__classPrivateFieldGet(this, _value$1)); | ||
return Ok.of(__classPrivateFieldGet(this, _Ok_value, "f")); | ||
} | ||
map(fn) { | ||
return Ok.of(fn(__classPrivateFieldGet(this, _value$1))); | ||
return Ok.of(fn(__classPrivateFieldGet(this, _Ok_value, "f"))); | ||
} | ||
get() { | ||
return __classPrivateFieldGet(this, _value$1); | ||
return __classPrivateFieldGet(this, _Ok_value, "f"); | ||
} | ||
} | ||
_value$1 = new WeakMap(); | ||
_Ok_value = new WeakMap(); | ||
class Err extends Result { | ||
constructor(err) { | ||
super(); | ||
_value_1.set(this, void 0); | ||
__classPrivateFieldSet(this, _value_1, err); | ||
_Err_value.set(this, void 0); | ||
__classPrivateFieldSet(this, _Err_value, err, "f"); | ||
} | ||
@@ -346,7 +344,7 @@ static of(error) { | ||
onOk() { | ||
return Err.of(__classPrivateFieldGet(this, _value_1)); | ||
return Err.of(__classPrivateFieldGet(this, _Err_value, "f")); | ||
} | ||
onErr(callback) { | ||
callback(__classPrivateFieldGet(this, _value_1)); | ||
return Err.of(__classPrivateFieldGet(this, _value_1)); | ||
callback(__classPrivateFieldGet(this, _Err_value, "f")); | ||
return Err.of(__classPrivateFieldGet(this, _Err_value, "f")); | ||
} | ||
@@ -357,9 +355,9 @@ orElse(defaultValue) { | ||
map() { | ||
return Err.of(__classPrivateFieldGet(this, _value_1)); | ||
return Err.of(__classPrivateFieldGet(this, _Err_value, "f")); | ||
} | ||
get() { | ||
throw __classPrivateFieldGet(this, _value_1); | ||
throw __classPrivateFieldGet(this, _Err_value, "f"); | ||
} | ||
} | ||
_value_1 = new WeakMap(); | ||
_Err_value = new WeakMap(); | ||
@@ -376,7 +374,7 @@ function toResult(fn) { | ||
var _promise$1; | ||
var _AsyncResult_promise; | ||
class AsyncResult { | ||
constructor(promise) { | ||
_promise$1.set(this, void 0); | ||
__classPrivateFieldSet(this, _promise$1, Promise.resolve(promise)); | ||
_AsyncResult_promise.set(this, void 0); | ||
__classPrivateFieldSet(this, _AsyncResult_promise, Promise.resolve(promise), "f"); | ||
} | ||
@@ -390,3 +388,3 @@ static Ok(value) { | ||
get then() { | ||
const promise = __classPrivateFieldGet(this, _promise$1).then(x => Result.Ok(x), x => Result.Err(x)); | ||
const promise = __classPrivateFieldGet(this, _AsyncResult_promise, "f").then(x => Result.Ok(x), x => Result.Err(x)); | ||
return promise.then.bind(promise); | ||
@@ -396,21 +394,21 @@ } | ||
go.go(async () => { | ||
const [succ, ret] = await getSuccessPromise(__classPrivateFieldGet(this, _promise$1)); | ||
const [succ, ret] = await getSuccessPromise(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
if (succ) | ||
callback(ret); | ||
}); | ||
return new AsyncResult(__classPrivateFieldGet(this, _promise$1)); | ||
return new AsyncResult(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
} | ||
onErr(callback) { | ||
go.go(async () => { | ||
const [fail, err] = await getFailurePromise(__classPrivateFieldGet(this, _promise$1)); | ||
const [fail, err] = await getFailurePromise(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
if (fail) | ||
callback(err); | ||
}); | ||
return new AsyncResult(__classPrivateFieldGet(this, _promise$1)); | ||
return new AsyncResult(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
} | ||
async isOk() { | ||
return await isSuccessPromise(__classPrivateFieldGet(this, _promise$1)); | ||
return await isSuccessPromise(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
} | ||
async isErr() { | ||
return await isFailurePromise(__classPrivateFieldGet(this, _promise$1)); | ||
return await isFailurePromise(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
} | ||
@@ -420,3 +418,3 @@ orElse(defaultValue) { | ||
try { | ||
return await __classPrivateFieldGet(this, _promise$1); | ||
return await __classPrivateFieldGet(this, _AsyncResult_promise, "f"); | ||
} | ||
@@ -431,3 +429,3 @@ catch (_a) { | ||
const promise = go.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise$1); | ||
const result = await __classPrivateFieldGet(this, _AsyncResult_promise, "f"); | ||
return mapper(result); | ||
@@ -438,6 +436,6 @@ }); | ||
async get() { | ||
return await __classPrivateFieldGet(this, _promise$1); | ||
return await __classPrivateFieldGet(this, _AsyncResult_promise, "f"); | ||
} | ||
} | ||
_promise$1 = new WeakMap(); | ||
_AsyncResult_promise = new WeakMap(); | ||
class AsyncOk extends AsyncResult { | ||
@@ -474,3 +472,3 @@ static of(value) { | ||
var _value; | ||
var _Some_value; | ||
class Optional { | ||
@@ -487,4 +485,4 @@ static Some(value) { | ||
super(); | ||
_value.set(this, void 0); | ||
__classPrivateFieldSet(this, _value, value); | ||
_Some_value.set(this, void 0); | ||
__classPrivateFieldSet(this, _Some_value, value, "f"); | ||
} | ||
@@ -501,17 +499,17 @@ static of(value) { | ||
onSome(callback) { | ||
callback(__classPrivateFieldGet(this, _value)); | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
callback(__classPrivateFieldGet(this, _Some_value, "f")); | ||
return Some.of(__classPrivateFieldGet(this, _Some_value, "f")); | ||
} | ||
onNone() { | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
return Some.of(__classPrivateFieldGet(this, _Some_value, "f")); | ||
} | ||
orElse() { | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
return Some.of(__classPrivateFieldGet(this, _Some_value, "f")); | ||
} | ||
map(mapper) { | ||
return Some.of(mapper(__classPrivateFieldGet(this, _value))); | ||
return Some.of(mapper(__classPrivateFieldGet(this, _Some_value, "f"))); | ||
} | ||
filter(predicate) { | ||
if (predicate(__classPrivateFieldGet(this, _value))) { | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
if (predicate(__classPrivateFieldGet(this, _Some_value, "f"))) { | ||
return Some.of(__classPrivateFieldGet(this, _Some_value, "f")); | ||
} | ||
@@ -523,6 +521,6 @@ else { | ||
get() { | ||
return __classPrivateFieldGet(this, _value); | ||
return __classPrivateFieldGet(this, _Some_value, "f"); | ||
} | ||
} | ||
_value = new WeakMap(); | ||
_Some_value = new WeakMap(); | ||
class None extends Optional { | ||
@@ -575,8 +573,8 @@ static of() { | ||
var _promise; | ||
var _AsyncOptional_promise; | ||
const Nil = Symbol(); | ||
class AsyncOptional { | ||
constructor(promise) { | ||
_promise.set(this, void 0); | ||
__classPrivateFieldSet(this, _promise, Promise.resolve(promise)); | ||
_AsyncOptional_promise.set(this, void 0); | ||
__classPrivateFieldSet(this, _AsyncOptional_promise, Promise.resolve(promise), "f"); | ||
} | ||
@@ -590,3 +588,3 @@ static Some(value) { | ||
get then() { | ||
const promise = __classPrivateFieldGet(this, _promise).then(x => x === Nil | ||
const promise = __classPrivateFieldGet(this, _AsyncOptional_promise, "f").then(x => x === Nil | ||
? Optional.None() | ||
@@ -598,22 +596,22 @@ : Optional.Some(x)); | ||
go.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
const result = await __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result !== Nil) | ||
callback(result); | ||
}); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _promise)); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _AsyncOptional_promise, "f")); | ||
} | ||
onNone(callback) { | ||
go.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
const result = await __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result === Nil) | ||
callback(); | ||
}); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _promise)); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _AsyncOptional_promise, "f")); | ||
} | ||
async isSome() { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
const result = await __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
return result !== Nil; | ||
} | ||
async isNone() { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
const result = await __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
return result === Nil; | ||
@@ -623,3 +621,3 @@ } | ||
const promise = go.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
const result = await __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result === Nil) | ||
@@ -633,3 +631,3 @@ return defaultValue; | ||
const promise = go.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
const result = await __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result === Nil) | ||
@@ -643,3 +641,3 @@ return Nil; | ||
const promise = go.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
const result = await __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result === Nil) | ||
@@ -654,3 +652,3 @@ return Nil; | ||
async get() { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
const result = await __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result === Nil) | ||
@@ -661,3 +659,3 @@ throw new Error('Cannot get value from None'); | ||
} | ||
_promise = new WeakMap(); | ||
_AsyncOptional_promise = new WeakMap(); | ||
class AsyncNone extends AsyncOptional { | ||
@@ -742,3 +740,3 @@ static of() { | ||
}))); | ||
})); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -1,2 +0,2 @@ | ||
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@blackglory/go")):"function"==typeof define&&define.amd?define(["exports","@blackglory/go"],r):r((t="undefined"!=typeof globalThis?globalThis:t||self).ReturnStyle={},t.go)}(this,(function(t,r){"use strict";async function n(t){try{return[!0,await t]}catch(t){return[!1,void 0]}}async function e(t){try{return await t,[!1,void 0]}catch(t){return[!0,t]}}async function o(t){try{return await t,!0}catch(t){return!1}}async function s(t){try{return await t,!1}catch(t){return!0}} | ||
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@blackglory/go")):"function"==typeof define&&define.amd?define(["exports","@blackglory/go"],r):r((t="undefined"!=typeof globalThis?globalThis:t||self).ReturnStyle={},t.go)}(this,(function(t,r){"use strict";async function e(t){try{return[!0,await t]}catch(t){return[!1,void 0]}}async function n(t){try{return await t,[!1,void 0]}catch(t){return[!0,t]}}async function o(t){try{return await t,!0}catch(t){return!1}}async function s(t){try{return await t,!1}catch(t){return!0}} | ||
/*! ***************************************************************************** | ||
@@ -16,3 +16,3 @@ Copyright (c) Microsoft Corporation. | ||
***************************************************************************** */ | ||
function i(t,r){if(!r.has(t))throw new TypeError("attempted to get private field on non-instance");return r.get(t)}function c(t,r,n){if(!r.has(t))throw new TypeError("attempted to set private field on non-instance");return r.set(t,n),n}var u,a,f,h,y;class l{static Ok(t){return w.of(t)}static Err(t){return g.of(t)}}class w extends l{constructor(t){super(),u.set(this,void 0),c(this,u,t)}static of(t){return new w(t)}isOk(){return!0}isErr(){return!1}onOk(t){return t(i(this,u)),w.of(i(this,u))}onErr(){return w.of(i(this,u))}orElse(){return w.of(i(this,u))}map(t){return w.of(t(i(this,u)))}get(){return i(this,u)}}u=new WeakMap;class g extends l{constructor(t){super(),a.set(this,void 0),c(this,a,t)}static of(t){return new g(t)}isOk(){return!1}isErr(){return!0}onOk(){return g.of(i(this,a))}onErr(t){return t(i(this,a)),g.of(i(this,a))}orElse(t){return w.of(t)}map(){return g.of(i(this,a))}get(){throw i(this,a)}}a=new WeakMap;class d{constructor(t){f.set(this,void 0),c(this,f,Promise.resolve(t))}static Ok(t){return m.of(t)}static Err(t){return p.of(t)}get then(){const t=i(this,f).then((t=>l.Ok(t)),(t=>l.Err(t)));return t.then.bind(t)}onOk(t){return r.go((async()=>{const[r,e]=await n(i(this,f));r&&t(e)})),new d(i(this,f))}onErr(t){return r.go((async()=>{const[r,n]=await e(i(this,f));r&&t(n)})),new d(i(this,f))}async isOk(){return await o(i(this,f))}async isErr(){return await s(i(this,f))}orElse(t){const n=r.go((async()=>{try{return await i(this,f)}catch(r){return t}}));return new d(n)}map(t){const n=r.go((async()=>{const r=await i(this,f);return t(r)}));return new d(n)}async get(){return await i(this,f)}}f=new WeakMap;class m extends d{static of(t){return new m(t)}constructor(t){super(Promise.resolve(t))}}class p extends d{static of(t){return new p(t)}constructor(t){super(Promise.reject(t))}}class v{static Some(t){return E.of(t)}static None(){return P.of()}}class E extends v{constructor(t){super(),h.set(this,void 0),c(this,h,t)}static of(t){return new E(t)}isSome(){return!0}isNone(){return!1}onSome(t){return t(i(this,h)),E.of(i(this,h))}onNone(){return E.of(i(this,h))}orElse(){return E.of(i(this,h))}map(t){return E.of(t(i(this,h)))}filter(t){return t(i(this,h))?E.of(i(this,h)):P.of()}get(){return i(this,h)}}h=new WeakMap;class P extends v{static of(){return new P}constructor(){super()}isSome(){return!1}isNone(){return!0}onSome(){return P.of()}onNone(t){return t(),P.of()}orElse(t){return E.of(t)}map(){return P.of()}filter(){return P.of()}get(){throw new Error("Cannot get value from None")}}function S(t,r){const n=t();return r(n)?v.None():v.Some(n)}const k=Symbol();class O{constructor(t){y.set(this,void 0),c(this,y,Promise.resolve(t))}static Some(t){return A.of(t)}static None(){return R.of()}get then(){const t=i(this,y).then((t=>t===k?v.None():v.Some(t)));return t.then.bind(t)}onSome(t){return r.go((async()=>{const r=await i(this,y);r!==k&&t(r)})),new O(i(this,y))}onNone(t){return r.go((async()=>{await i(this,y)===k&&t()})),new O(i(this,y))}async isSome(){return await i(this,y)!==k}async isNone(){return await i(this,y)===k}orElse(t){const n=r.go((async()=>{const r=await i(this,y);return r===k?t:r}));return new O(n)}map(t){const n=r.go((async()=>{const r=await i(this,y);return r===k?k:t(r)}));return new O(n)}filter(t){const n=r.go((async()=>{const r=await i(this,y);return r===k?k:t(r)?r:k}));return new O(n)}async get(){const t=await i(this,y);if(t===k)throw new Error("Cannot get value from None");return t}}y=new WeakMap;class R extends O{static of(){return new R}constructor(){super(Promise.resolve(k))}}class A extends O{static of(t){return new A(t)}constructor(t){super(Promise.resolve(t))}}function N(t,n){const e=r.go((async()=>{const r=await t();return n(r)?k:r}));return new O(e)}function x(t,n){return new O(r.go((async()=>{const r=await t;return n(r)?k:r})))}t.getError=function(t){try{t()}catch(t){return t}},t.getErrorAsync=async function(t){try{await t()}catch(t){return t}},t.getErrorAsyncIterable=async function(t){try{for await(const r of t);}catch(t){return t}},t.getErrorPromise=async function(t){try{await t}catch(t){return t}},t.getErrorResult=function(t){try{return[void 0,t()]}catch(t){return[t,void 0]}},t.getErrorResultAsync=async function(t){try{return[void 0,await t()]}catch(t){return[t,void 0]}},t.getErrorResultPromise=async function(t){try{return[void 0,await t]}catch(t){return[t,void 0]}},t.getFailure=function(t){try{return t(),[!1,void 0]}catch(t){return[!0,t]}},t.getFailureAsync=async function(t){try{return await t(),[!1,void 0]}catch(t){return[!0,t]}},t.getFailurePromise=e,t.getResult=function(t){try{return t()}catch(t){return}},t.getResultAsync=async function(t){try{return await t()}catch(t){return}},t.getResultError=function(t){try{return[t(),void 0]}catch(t){return[void 0,t]}},t.getResultErrorAsync=async function(t){try{return[await t(),void 0]}catch(t){return[void 0,t]}},t.getResultErrorPromise=async function(t){try{return[await t,void 0]}catch(t){return[void 0,t]}},t.getResultPromise=async function(t){try{return await t}catch(t){return}},t.getSuccess=function(t){try{return[!0,t()]}catch(t){return[!1,void 0]}},t.getSuccessAsync=async function(t){try{return[!0,await t()]}catch(t){return[!1,void 0]}},t.getSuccessPromise=n,t.isFailure=function(t){try{return t(),!1}catch(t){return!0}},t.isFailureAsync=async function(t){try{return await t(),!1}catch(t){return!0}},t.isFailurePromise=s,t.isSuccess=function(t){try{return t(),!0}catch(t){return!1}},t.isSuccessAsync=async function(t){try{return await t(),!0}catch(t){return!1}},t.isSuccessPromise=o,t.toOptional=S,t.toOptionalAsync=N,t.toOptionalAsyncPartial=function(t){return r=>N(r,t)},t.toOptionalPartial=function(t){return r=>S(r,t)},t.toOptionalPromise=x,t.toOptionalPromisePartial=function(t){return r=>x(r,t)},t.toResult=function(t){try{const r=t();return l.Ok(r)}catch(t){return l.Err(t)}},t.toResultAsync=function(t){try{const r=t();return new d(r)}catch(t){return d.Err(t)}},t.toResultPromise=function(t){return new d(t)},Object.defineProperty(t,"__esModule",{value:!0})})); | ||
function i(t,r,e,n){if("a"===e&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof r?t!==r||!n:!r.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===e?n:"a"===e?n.call(t):n?n.value:r.get(t)}function c(t,r,e,n,o){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof r?t!==r||!o:!r.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?o.call(t,e):o?o.value=e:r.set(t,e),e}var a,u,f,h,y;class w{static Ok(t){return l.of(t)}static Err(t){return d.of(t)}}class l extends w{constructor(t){super(),a.set(this,void 0),c(this,a,t,"f")}static of(t){return new l(t)}isOk(){return!0}isErr(){return!1}onOk(t){return t(i(this,a,"f")),l.of(i(this,a,"f"))}onErr(){return l.of(i(this,a,"f"))}orElse(){return l.of(i(this,a,"f"))}map(t){return l.of(t(i(this,a,"f")))}get(){return i(this,a,"f")}}a=new WeakMap;class d extends w{constructor(t){super(),u.set(this,void 0),c(this,u,t,"f")}static of(t){return new d(t)}isOk(){return!1}isErr(){return!0}onOk(){return d.of(i(this,u,"f"))}onErr(t){return t(i(this,u,"f")),d.of(i(this,u,"f"))}orElse(t){return l.of(t)}map(){return d.of(i(this,u,"f"))}get(){throw i(this,u,"f")}}u=new WeakMap;class g{constructor(t){f.set(this,void 0),c(this,f,Promise.resolve(t),"f")}static Ok(t){return m.of(t)}static Err(t){return p.of(t)}get then(){const t=i(this,f,"f").then((t=>w.Ok(t)),(t=>w.Err(t)));return t.then.bind(t)}onOk(t){return r.go((async()=>{const[r,n]=await e(i(this,f,"f"));r&&t(n)})),new g(i(this,f,"f"))}onErr(t){return r.go((async()=>{const[r,e]=await n(i(this,f,"f"));r&&t(e)})),new g(i(this,f,"f"))}async isOk(){return await o(i(this,f,"f"))}async isErr(){return await s(i(this,f,"f"))}orElse(t){const e=r.go((async()=>{try{return await i(this,f,"f")}catch(r){return t}}));return new g(e)}map(t){const e=r.go((async()=>{const r=await i(this,f,"f");return t(r)}));return new g(e)}async get(){return await i(this,f,"f")}}f=new WeakMap;class m extends g{static of(t){return new m(t)}constructor(t){super(Promise.resolve(t))}}class p extends g{static of(t){return new p(t)}constructor(t){super(Promise.reject(t))}}class v{static Some(t){return E.of(t)}static None(){return P.of()}}class E extends v{constructor(t){super(),h.set(this,void 0),c(this,h,t,"f")}static of(t){return new E(t)}isSome(){return!0}isNone(){return!1}onSome(t){return t(i(this,h,"f")),E.of(i(this,h,"f"))}onNone(){return E.of(i(this,h,"f"))}orElse(){return E.of(i(this,h,"f"))}map(t){return E.of(t(i(this,h,"f")))}filter(t){return t(i(this,h,"f"))?E.of(i(this,h,"f")):P.of()}get(){return i(this,h,"f")}}h=new WeakMap;class P extends v{static of(){return new P}constructor(){super()}isSome(){return!1}isNone(){return!0}onSome(){return P.of()}onNone(t){return t(),P.of()}orElse(t){return E.of(t)}map(){return P.of()}filter(){return P.of()}get(){throw new Error("Cannot get value from None")}}function S(t,r){const e=t();return r(e)?v.None():v.Some(e)}const k=Symbol();class O{constructor(t){y.set(this,void 0),c(this,y,Promise.resolve(t),"f")}static Some(t){return R.of(t)}static None(){return b.of()}get then(){const t=i(this,y,"f").then((t=>t===k?v.None():v.Some(t)));return t.then.bind(t)}onSome(t){return r.go((async()=>{const r=await i(this,y,"f");r!==k&&t(r)})),new O(i(this,y,"f"))}onNone(t){return r.go((async()=>{await i(this,y,"f")===k&&t()})),new O(i(this,y,"f"))}async isSome(){return await i(this,y,"f")!==k}async isNone(){return await i(this,y,"f")===k}orElse(t){const e=r.go((async()=>{const r=await i(this,y,"f");return r===k?t:r}));return new O(e)}map(t){const e=r.go((async()=>{const r=await i(this,y,"f");return r===k?k:t(r)}));return new O(e)}filter(t){const e=r.go((async()=>{const r=await i(this,y,"f");return r===k?k:t(r)?r:k}));return new O(e)}async get(){const t=await i(this,y,"f");if(t===k)throw new Error("Cannot get value from None");return t}}y=new WeakMap;class b extends O{static of(){return new b}constructor(){super(Promise.resolve(k))}}class R extends O{static of(t){return new R(t)}constructor(t){super(Promise.resolve(t))}}function A(t,e){const n=r.go((async()=>{const r=await t();return e(r)?k:r}));return new O(n)}function N(t,e){return new O(r.go((async()=>{const r=await t;return e(r)?k:r})))}t.getError=function(t){try{t()}catch(t){return t}},t.getErrorAsync=async function(t){try{await t()}catch(t){return t}},t.getErrorAsyncIterable=async function(t){try{for await(const r of t);}catch(t){return t}},t.getErrorPromise=async function(t){try{await t}catch(t){return t}},t.getErrorResult=function(t){try{return[void 0,t()]}catch(t){return[t,void 0]}},t.getErrorResultAsync=async function(t){try{return[void 0,await t()]}catch(t){return[t,void 0]}},t.getErrorResultPromise=async function(t){try{return[void 0,await t]}catch(t){return[t,void 0]}},t.getFailure=function(t){try{return t(),[!1,void 0]}catch(t){return[!0,t]}},t.getFailureAsync=async function(t){try{return await t(),[!1,void 0]}catch(t){return[!0,t]}},t.getFailurePromise=n,t.getResult=function(t){try{return t()}catch(t){return}},t.getResultAsync=async function(t){try{return await t()}catch(t){return}},t.getResultError=function(t){try{return[t(),void 0]}catch(t){return[void 0,t]}},t.getResultErrorAsync=async function(t){try{return[await t(),void 0]}catch(t){return[void 0,t]}},t.getResultErrorPromise=async function(t){try{return[await t,void 0]}catch(t){return[void 0,t]}},t.getResultPromise=async function(t){try{return await t}catch(t){return}},t.getSuccess=function(t){try{return[!0,t()]}catch(t){return[!1,void 0]}},t.getSuccessAsync=async function(t){try{return[!0,await t()]}catch(t){return[!1,void 0]}},t.getSuccessPromise=e,t.isFailure=function(t){try{return t(),!1}catch(t){return!0}},t.isFailureAsync=async function(t){try{return await t(),!1}catch(t){return!0}},t.isFailurePromise=s,t.isSuccess=function(t){try{return t(),!0}catch(t){return!1}},t.isSuccessAsync=async function(t){try{return await t(),!0}catch(t){return!1}},t.isSuccessPromise=o,t.toOptional=S,t.toOptionalAsync=A,t.toOptionalAsyncPartial=function(t){return r=>A(r,t)},t.toOptionalPartial=function(t){return r=>S(r,t)},t.toOptionalPromise=N,t.toOptionalPromisePartial=function(t){return r=>N(r,t)},t.toResult=function(t){try{const r=t();return w.Ok(r)}catch(t){return w.Err(t)}},t.toResultAsync=function(t){try{const r=t();return new g(r)}catch(t){return g.Err(t)}},t.toResultPromise=function(t){return new g(t)},Object.defineProperty(t,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.umd.min.js.map |
@@ -11,16 +11,14 @@ "use strict"; | ||
}; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to set private field on non-instance"); | ||
} | ||
privateMap.set(receiver, value); | ||
return value; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
if (kind === "m") throw new TypeError("Private method is not writable"); | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
}; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
}; | ||
var _promise; | ||
var _AsyncOptional_promise; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -33,4 +31,4 @@ exports.AsyncOptional = exports.Nil = void 0; | ||
constructor(promise) { | ||
_promise.set(this, void 0); | ||
__classPrivateFieldSet(this, _promise, Promise.resolve(promise)); | ||
_AsyncOptional_promise.set(this, void 0); | ||
__classPrivateFieldSet(this, _AsyncOptional_promise, Promise.resolve(promise), "f"); | ||
} | ||
@@ -44,3 +42,3 @@ static Some(value) { | ||
get then() { | ||
const promise = __classPrivateFieldGet(this, _promise).then(x => x === exports.Nil | ||
const promise = __classPrivateFieldGet(this, _AsyncOptional_promise, "f").then(x => x === exports.Nil | ||
? optional_1.Optional.None() | ||
@@ -51,20 +49,20 @@ : optional_1.Optional.Some(x)); | ||
onSome(callback) { | ||
go_1.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
(0, go_1.go)(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result !== exports.Nil) | ||
callback(result); | ||
})); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _promise)); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _AsyncOptional_promise, "f")); | ||
} | ||
onNone(callback) { | ||
go_1.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
(0, go_1.go)(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result === exports.Nil) | ||
callback(); | ||
})); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _promise)); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _AsyncOptional_promise, "f")); | ||
} | ||
isSome() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
const result = yield __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
return result !== exports.Nil; | ||
@@ -75,3 +73,3 @@ }); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
const result = yield __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
return result === exports.Nil; | ||
@@ -81,4 +79,4 @@ }); | ||
orElse(defaultValue) { | ||
const promise = go_1.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
const promise = (0, go_1.go)(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result === exports.Nil) | ||
@@ -91,4 +89,4 @@ return defaultValue; | ||
map(mapper) { | ||
const promise = go_1.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
const promise = (0, go_1.go)(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result === exports.Nil) | ||
@@ -101,4 +99,4 @@ return exports.Nil; | ||
filter(predicate) { | ||
const promise = go_1.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
const promise = (0, go_1.go)(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result === exports.Nil) | ||
@@ -114,3 +112,3 @@ return exports.Nil; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
const result = yield __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result === exports.Nil) | ||
@@ -123,3 +121,3 @@ throw new Error('Cannot get value from None'); | ||
exports.AsyncOptional = AsyncOptional; | ||
_promise = new WeakMap(); | ||
_AsyncOptional_promise = new WeakMap(); | ||
class AsyncNone extends AsyncOptional { | ||
@@ -126,0 +124,0 @@ static of() { |
@@ -11,16 +11,14 @@ "use strict"; | ||
}; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to set private field on non-instance"); | ||
} | ||
privateMap.set(receiver, value); | ||
return value; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
if (kind === "m") throw new TypeError("Private method is not writable"); | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
}; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
}; | ||
var _promise; | ||
var _AsyncResult_promise; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -36,4 +34,4 @@ exports.AsyncResult = void 0; | ||
constructor(promise) { | ||
_promise.set(this, void 0); | ||
__classPrivateFieldSet(this, _promise, Promise.resolve(promise)); | ||
_AsyncResult_promise.set(this, void 0); | ||
__classPrivateFieldSet(this, _AsyncResult_promise, Promise.resolve(promise), "f"); | ||
} | ||
@@ -47,24 +45,24 @@ static Ok(value) { | ||
get then() { | ||
const promise = __classPrivateFieldGet(this, _promise).then(x => result_1.Result.Ok(x), x => result_1.Result.Err(x)); | ||
const promise = __classPrivateFieldGet(this, _AsyncResult_promise, "f").then(x => result_1.Result.Ok(x), x => result_1.Result.Err(x)); | ||
return promise.then.bind(promise); | ||
} | ||
onOk(callback) { | ||
go_1.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const [succ, ret] = yield get_success_promise_1.getSuccessPromise(__classPrivateFieldGet(this, _promise)); | ||
(0, go_1.go)(() => __awaiter(this, void 0, void 0, function* () { | ||
const [succ, ret] = yield (0, get_success_promise_1.getSuccessPromise)(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
if (succ) | ||
callback(ret); | ||
})); | ||
return new AsyncResult(__classPrivateFieldGet(this, _promise)); | ||
return new AsyncResult(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
} | ||
onErr(callback) { | ||
go_1.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const [fail, err] = yield get_failure_promise_1.getFailurePromise(__classPrivateFieldGet(this, _promise)); | ||
(0, go_1.go)(() => __awaiter(this, void 0, void 0, function* () { | ||
const [fail, err] = yield (0, get_failure_promise_1.getFailurePromise)(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
if (fail) | ||
callback(err); | ||
})); | ||
return new AsyncResult(__classPrivateFieldGet(this, _promise)); | ||
return new AsyncResult(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
} | ||
isOk() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield is_success_promise_1.isSuccessPromise(__classPrivateFieldGet(this, _promise)); | ||
return yield (0, is_success_promise_1.isSuccessPromise)(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
}); | ||
@@ -74,9 +72,9 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield is_failure_promise_1.isFailurePromise(__classPrivateFieldGet(this, _promise)); | ||
return yield (0, is_failure_promise_1.isFailurePromise)(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
}); | ||
} | ||
orElse(defaultValue) { | ||
const promise = go_1.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const promise = (0, go_1.go)(() => __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
return yield __classPrivateFieldGet(this, _promise); | ||
return yield __classPrivateFieldGet(this, _AsyncResult_promise, "f"); | ||
} | ||
@@ -90,4 +88,4 @@ catch (_a) { | ||
map(mapper) { | ||
const promise = go_1.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
const promise = (0, go_1.go)(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _AsyncResult_promise, "f"); | ||
return mapper(result); | ||
@@ -99,3 +97,3 @@ })); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield __classPrivateFieldGet(this, _promise); | ||
return yield __classPrivateFieldGet(this, _AsyncResult_promise, "f"); | ||
}); | ||
@@ -105,3 +103,3 @@ } | ||
exports.AsyncResult = AsyncResult; | ||
_promise = new WeakMap(); | ||
_AsyncResult_promise = new WeakMap(); | ||
class AsyncOk extends AsyncResult { | ||
@@ -108,0 +106,0 @@ static of(value) { |
"use strict"; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to set private field on non-instance"); | ||
} | ||
privateMap.set(receiver, value); | ||
return value; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
if (kind === "m") throw new TypeError("Private method is not writable"); | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
}; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
}; | ||
var _value; | ||
var _Some_value; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -30,4 +28,4 @@ exports.Optional = void 0; | ||
super(); | ||
_value.set(this, void 0); | ||
__classPrivateFieldSet(this, _value, value); | ||
_Some_value.set(this, void 0); | ||
__classPrivateFieldSet(this, _Some_value, value, "f"); | ||
} | ||
@@ -44,17 +42,17 @@ static of(value) { | ||
onSome(callback) { | ||
callback(__classPrivateFieldGet(this, _value)); | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
callback(__classPrivateFieldGet(this, _Some_value, "f")); | ||
return Some.of(__classPrivateFieldGet(this, _Some_value, "f")); | ||
} | ||
onNone() { | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
return Some.of(__classPrivateFieldGet(this, _Some_value, "f")); | ||
} | ||
orElse() { | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
return Some.of(__classPrivateFieldGet(this, _Some_value, "f")); | ||
} | ||
map(mapper) { | ||
return Some.of(mapper(__classPrivateFieldGet(this, _value))); | ||
return Some.of(mapper(__classPrivateFieldGet(this, _Some_value, "f"))); | ||
} | ||
filter(predicate) { | ||
if (predicate(__classPrivateFieldGet(this, _value))) { | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
if (predicate(__classPrivateFieldGet(this, _Some_value, "f"))) { | ||
return Some.of(__classPrivateFieldGet(this, _Some_value, "f")); | ||
} | ||
@@ -66,6 +64,6 @@ else { | ||
get() { | ||
return __classPrivateFieldGet(this, _value); | ||
return __classPrivateFieldGet(this, _Some_value, "f"); | ||
} | ||
} | ||
_value = new WeakMap(); | ||
_Some_value = new WeakMap(); | ||
class None extends Optional { | ||
@@ -72,0 +70,0 @@ static of() { |
"use strict"; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to set private field on non-instance"); | ||
} | ||
privateMap.set(receiver, value); | ||
return value; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
if (kind === "m") throw new TypeError("Private method is not writable"); | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
}; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
}; | ||
var _value, _value_1; | ||
var _Ok_value, _Err_value; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -30,4 +28,4 @@ exports.Result = void 0; | ||
super(); | ||
_value.set(this, void 0); | ||
__classPrivateFieldSet(this, _value, value); | ||
_Ok_value.set(this, void 0); | ||
__classPrivateFieldSet(this, _Ok_value, value, "f"); | ||
} | ||
@@ -44,24 +42,24 @@ static of(value) { | ||
onOk(callback) { | ||
callback(__classPrivateFieldGet(this, _value)); | ||
return Ok.of(__classPrivateFieldGet(this, _value)); | ||
callback(__classPrivateFieldGet(this, _Ok_value, "f")); | ||
return Ok.of(__classPrivateFieldGet(this, _Ok_value, "f")); | ||
} | ||
onErr() { | ||
return Ok.of(__classPrivateFieldGet(this, _value)); | ||
return Ok.of(__classPrivateFieldGet(this, _Ok_value, "f")); | ||
} | ||
orElse() { | ||
return Ok.of(__classPrivateFieldGet(this, _value)); | ||
return Ok.of(__classPrivateFieldGet(this, _Ok_value, "f")); | ||
} | ||
map(fn) { | ||
return Ok.of(fn(__classPrivateFieldGet(this, _value))); | ||
return Ok.of(fn(__classPrivateFieldGet(this, _Ok_value, "f"))); | ||
} | ||
get() { | ||
return __classPrivateFieldGet(this, _value); | ||
return __classPrivateFieldGet(this, _Ok_value, "f"); | ||
} | ||
} | ||
_value = new WeakMap(); | ||
_Ok_value = new WeakMap(); | ||
class Err extends Result { | ||
constructor(err) { | ||
super(); | ||
_value_1.set(this, void 0); | ||
__classPrivateFieldSet(this, _value_1, err); | ||
_Err_value.set(this, void 0); | ||
__classPrivateFieldSet(this, _Err_value, err, "f"); | ||
} | ||
@@ -78,7 +76,7 @@ static of(error) { | ||
onOk() { | ||
return Err.of(__classPrivateFieldGet(this, _value_1)); | ||
return Err.of(__classPrivateFieldGet(this, _Err_value, "f")); | ||
} | ||
onErr(callback) { | ||
callback(__classPrivateFieldGet(this, _value_1)); | ||
return Err.of(__classPrivateFieldGet(this, _value_1)); | ||
callback(__classPrivateFieldGet(this, _Err_value, "f")); | ||
return Err.of(__classPrivateFieldGet(this, _Err_value, "f")); | ||
} | ||
@@ -89,9 +87,9 @@ orElse(defaultValue) { | ||
map() { | ||
return Err.of(__classPrivateFieldGet(this, _value_1)); | ||
return Err.of(__classPrivateFieldGet(this, _Err_value, "f")); | ||
} | ||
get() { | ||
throw __classPrivateFieldGet(this, _value_1); | ||
throw __classPrivateFieldGet(this, _Err_value, "f"); | ||
} | ||
} | ||
_value_1 = new WeakMap(); | ||
_Err_value = new WeakMap(); | ||
//# sourceMappingURL=result.js.map |
@@ -20,3 +20,3 @@ "use strict"; | ||
function toOptionalAsync(fn, isNone) { | ||
const promise = go_1.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const promise = (0, go_1.go)(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield fn(); | ||
@@ -23,0 +23,0 @@ if (isNone(result)) |
@@ -20,3 +20,3 @@ "use strict"; | ||
function toOptionalPromise(promise, isNone) { | ||
return new async_optional_1.AsyncOptional(go_1.go(() => __awaiter(this, void 0, void 0, function* () { | ||
return new async_optional_1.AsyncOptional((0, go_1.go)(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield promise; | ||
@@ -23,0 +23,0 @@ if (isNone(result)) |
"use strict"; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to set private field on non-instance"); | ||
} | ||
privateMap.set(receiver, value); | ||
return value; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
if (kind === "m") throw new TypeError("Private method is not writable"); | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
}; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
}; | ||
var _promise; | ||
var _AsyncOptional_promise; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -23,4 +21,4 @@ exports.AsyncOptional = exports.Nil = void 0; | ||
constructor(promise) { | ||
_promise.set(this, void 0); | ||
__classPrivateFieldSet(this, _promise, Promise.resolve(promise)); | ||
_AsyncOptional_promise.set(this, void 0); | ||
__classPrivateFieldSet(this, _AsyncOptional_promise, Promise.resolve(promise), "f"); | ||
} | ||
@@ -34,3 +32,3 @@ static Some(value) { | ||
get then() { | ||
const promise = __classPrivateFieldGet(this, _promise).then(x => x === exports.Nil | ||
const promise = __classPrivateFieldGet(this, _AsyncOptional_promise, "f").then(x => x === exports.Nil | ||
? optional_1.Optional.None() | ||
@@ -41,28 +39,28 @@ : optional_1.Optional.Some(x)); | ||
onSome(callback) { | ||
go_1.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
(0, go_1.go)(async () => { | ||
const result = await __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result !== exports.Nil) | ||
callback(result); | ||
}); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _promise)); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _AsyncOptional_promise, "f")); | ||
} | ||
onNone(callback) { | ||
go_1.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
(0, go_1.go)(async () => { | ||
const result = await __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result === exports.Nil) | ||
callback(); | ||
}); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _promise)); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _AsyncOptional_promise, "f")); | ||
} | ||
async isSome() { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
const result = await __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
return result !== exports.Nil; | ||
} | ||
async isNone() { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
const result = await __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
return result === exports.Nil; | ||
} | ||
orElse(defaultValue) { | ||
const promise = go_1.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
const promise = (0, go_1.go)(async () => { | ||
const result = await __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result === exports.Nil) | ||
@@ -75,4 +73,4 @@ return defaultValue; | ||
map(mapper) { | ||
const promise = go_1.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
const promise = (0, go_1.go)(async () => { | ||
const result = await __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result === exports.Nil) | ||
@@ -85,4 +83,4 @@ return exports.Nil; | ||
filter(predicate) { | ||
const promise = go_1.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
const promise = (0, go_1.go)(async () => { | ||
const result = await __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result === exports.Nil) | ||
@@ -97,3 +95,3 @@ return exports.Nil; | ||
async get() { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
const result = await __classPrivateFieldGet(this, _AsyncOptional_promise, "f"); | ||
if (result === exports.Nil) | ||
@@ -105,3 +103,3 @@ throw new Error('Cannot get value from None'); | ||
exports.AsyncOptional = AsyncOptional; | ||
_promise = new WeakMap(); | ||
_AsyncOptional_promise = new WeakMap(); | ||
class AsyncNone extends AsyncOptional { | ||
@@ -108,0 +106,0 @@ static of() { |
"use strict"; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to set private field on non-instance"); | ||
} | ||
privateMap.set(receiver, value); | ||
return value; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
if (kind === "m") throw new TypeError("Private method is not writable"); | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
}; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
}; | ||
var _promise; | ||
var _AsyncResult_promise; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -26,4 +24,4 @@ exports.AsyncResult = void 0; | ||
constructor(promise) { | ||
_promise.set(this, void 0); | ||
__classPrivateFieldSet(this, _promise, Promise.resolve(promise)); | ||
_AsyncResult_promise.set(this, void 0); | ||
__classPrivateFieldSet(this, _AsyncResult_promise, Promise.resolve(promise), "f"); | ||
} | ||
@@ -37,31 +35,31 @@ static Ok(value) { | ||
get then() { | ||
const promise = __classPrivateFieldGet(this, _promise).then(x => result_1.Result.Ok(x), x => result_1.Result.Err(x)); | ||
const promise = __classPrivateFieldGet(this, _AsyncResult_promise, "f").then(x => result_1.Result.Ok(x), x => result_1.Result.Err(x)); | ||
return promise.then.bind(promise); | ||
} | ||
onOk(callback) { | ||
go_1.go(async () => { | ||
const [succ, ret] = await get_success_promise_1.getSuccessPromise(__classPrivateFieldGet(this, _promise)); | ||
(0, go_1.go)(async () => { | ||
const [succ, ret] = await (0, get_success_promise_1.getSuccessPromise)(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
if (succ) | ||
callback(ret); | ||
}); | ||
return new AsyncResult(__classPrivateFieldGet(this, _promise)); | ||
return new AsyncResult(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
} | ||
onErr(callback) { | ||
go_1.go(async () => { | ||
const [fail, err] = await get_failure_promise_1.getFailurePromise(__classPrivateFieldGet(this, _promise)); | ||
(0, go_1.go)(async () => { | ||
const [fail, err] = await (0, get_failure_promise_1.getFailurePromise)(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
if (fail) | ||
callback(err); | ||
}); | ||
return new AsyncResult(__classPrivateFieldGet(this, _promise)); | ||
return new AsyncResult(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
} | ||
async isOk() { | ||
return await is_success_promise_1.isSuccessPromise(__classPrivateFieldGet(this, _promise)); | ||
return await (0, is_success_promise_1.isSuccessPromise)(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
} | ||
async isErr() { | ||
return await is_failure_promise_1.isFailurePromise(__classPrivateFieldGet(this, _promise)); | ||
return await (0, is_failure_promise_1.isFailurePromise)(__classPrivateFieldGet(this, _AsyncResult_promise, "f")); | ||
} | ||
orElse(defaultValue) { | ||
const promise = go_1.go(async () => { | ||
const promise = (0, go_1.go)(async () => { | ||
try { | ||
return await __classPrivateFieldGet(this, _promise); | ||
return await __classPrivateFieldGet(this, _AsyncResult_promise, "f"); | ||
} | ||
@@ -75,4 +73,4 @@ catch (_a) { | ||
map(mapper) { | ||
const promise = go_1.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
const promise = (0, go_1.go)(async () => { | ||
const result = await __classPrivateFieldGet(this, _AsyncResult_promise, "f"); | ||
return mapper(result); | ||
@@ -83,7 +81,7 @@ }); | ||
async get() { | ||
return await __classPrivateFieldGet(this, _promise); | ||
return await __classPrivateFieldGet(this, _AsyncResult_promise, "f"); | ||
} | ||
} | ||
exports.AsyncResult = AsyncResult; | ||
_promise = new WeakMap(); | ||
_AsyncResult_promise = new WeakMap(); | ||
class AsyncOk extends AsyncResult { | ||
@@ -90,0 +88,0 @@ static of(value) { |
"use strict"; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to set private field on non-instance"); | ||
} | ||
privateMap.set(receiver, value); | ||
return value; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
if (kind === "m") throw new TypeError("Private method is not writable"); | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
}; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
}; | ||
var _value; | ||
var _Some_value; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -30,4 +28,4 @@ exports.Optional = void 0; | ||
super(); | ||
_value.set(this, void 0); | ||
__classPrivateFieldSet(this, _value, value); | ||
_Some_value.set(this, void 0); | ||
__classPrivateFieldSet(this, _Some_value, value, "f"); | ||
} | ||
@@ -44,17 +42,17 @@ static of(value) { | ||
onSome(callback) { | ||
callback(__classPrivateFieldGet(this, _value)); | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
callback(__classPrivateFieldGet(this, _Some_value, "f")); | ||
return Some.of(__classPrivateFieldGet(this, _Some_value, "f")); | ||
} | ||
onNone() { | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
return Some.of(__classPrivateFieldGet(this, _Some_value, "f")); | ||
} | ||
orElse() { | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
return Some.of(__classPrivateFieldGet(this, _Some_value, "f")); | ||
} | ||
map(mapper) { | ||
return Some.of(mapper(__classPrivateFieldGet(this, _value))); | ||
return Some.of(mapper(__classPrivateFieldGet(this, _Some_value, "f"))); | ||
} | ||
filter(predicate) { | ||
if (predicate(__classPrivateFieldGet(this, _value))) { | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
if (predicate(__classPrivateFieldGet(this, _Some_value, "f"))) { | ||
return Some.of(__classPrivateFieldGet(this, _Some_value, "f")); | ||
} | ||
@@ -66,6 +64,6 @@ else { | ||
get() { | ||
return __classPrivateFieldGet(this, _value); | ||
return __classPrivateFieldGet(this, _Some_value, "f"); | ||
} | ||
} | ||
_value = new WeakMap(); | ||
_Some_value = new WeakMap(); | ||
class None extends Optional { | ||
@@ -72,0 +70,0 @@ static of() { |
"use strict"; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to set private field on non-instance"); | ||
} | ||
privateMap.set(receiver, value); | ||
return value; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
if (kind === "m") throw new TypeError("Private method is not writable"); | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
}; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
}; | ||
var _value, _value_1; | ||
var _Ok_value, _Err_value; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -30,4 +28,4 @@ exports.Result = void 0; | ||
super(); | ||
_value.set(this, void 0); | ||
__classPrivateFieldSet(this, _value, value); | ||
_Ok_value.set(this, void 0); | ||
__classPrivateFieldSet(this, _Ok_value, value, "f"); | ||
} | ||
@@ -44,24 +42,24 @@ static of(value) { | ||
onOk(callback) { | ||
callback(__classPrivateFieldGet(this, _value)); | ||
return Ok.of(__classPrivateFieldGet(this, _value)); | ||
callback(__classPrivateFieldGet(this, _Ok_value, "f")); | ||
return Ok.of(__classPrivateFieldGet(this, _Ok_value, "f")); | ||
} | ||
onErr() { | ||
return Ok.of(__classPrivateFieldGet(this, _value)); | ||
return Ok.of(__classPrivateFieldGet(this, _Ok_value, "f")); | ||
} | ||
orElse() { | ||
return Ok.of(__classPrivateFieldGet(this, _value)); | ||
return Ok.of(__classPrivateFieldGet(this, _Ok_value, "f")); | ||
} | ||
map(fn) { | ||
return Ok.of(fn(__classPrivateFieldGet(this, _value))); | ||
return Ok.of(fn(__classPrivateFieldGet(this, _Ok_value, "f"))); | ||
} | ||
get() { | ||
return __classPrivateFieldGet(this, _value); | ||
return __classPrivateFieldGet(this, _Ok_value, "f"); | ||
} | ||
} | ||
_value = new WeakMap(); | ||
_Ok_value = new WeakMap(); | ||
class Err extends Result { | ||
constructor(err) { | ||
super(); | ||
_value_1.set(this, void 0); | ||
__classPrivateFieldSet(this, _value_1, err); | ||
_Err_value.set(this, void 0); | ||
__classPrivateFieldSet(this, _Err_value, err, "f"); | ||
} | ||
@@ -78,7 +76,7 @@ static of(error) { | ||
onOk() { | ||
return Err.of(__classPrivateFieldGet(this, _value_1)); | ||
return Err.of(__classPrivateFieldGet(this, _Err_value, "f")); | ||
} | ||
onErr(callback) { | ||
callback(__classPrivateFieldGet(this, _value_1)); | ||
return Err.of(__classPrivateFieldGet(this, _value_1)); | ||
callback(__classPrivateFieldGet(this, _Err_value, "f")); | ||
return Err.of(__classPrivateFieldGet(this, _Err_value, "f")); | ||
} | ||
@@ -89,9 +87,9 @@ orElse(defaultValue) { | ||
map() { | ||
return Err.of(__classPrivateFieldGet(this, _value_1)); | ||
return Err.of(__classPrivateFieldGet(this, _Err_value, "f")); | ||
} | ||
get() { | ||
throw __classPrivateFieldGet(this, _value_1); | ||
throw __classPrivateFieldGet(this, _Err_value, "f"); | ||
} | ||
} | ||
_value_1 = new WeakMap(); | ||
_Err_value = new WeakMap(); | ||
//# sourceMappingURL=result.js.map |
@@ -11,3 +11,3 @@ "use strict"; | ||
function toOptionalAsync(fn, isNone) { | ||
const promise = go_1.go(async () => { | ||
const promise = (0, go_1.go)(async () => { | ||
const result = await fn(); | ||
@@ -14,0 +14,0 @@ if (isNone(result)) |
@@ -11,3 +11,3 @@ "use strict"; | ||
function toOptionalPromise(promise, isNone) { | ||
return new async_optional_1.AsyncOptional(go_1.go(async () => { | ||
return new async_optional_1.AsyncOptional((0, go_1.go)(async () => { | ||
const result = await promise; | ||
@@ -14,0 +14,0 @@ if (isNone(result)) |
{ | ||
"name": "return-style", | ||
"version": "0.12.3", | ||
"version": "0.12.4", | ||
"description": "Non-intrusively convert the result of any function or promise to the user's desired style.", | ||
@@ -58,26 +58,26 @@ "keywords": [ | ||
"devDependencies": { | ||
"@blackglory/jest-matchers": "^0.1.13", | ||
"@blackglory/types": "^0.4.1", | ||
"@commitlint/cli": "^12.0.1", | ||
"@commitlint/config-conventional": "^12.0.1", | ||
"@rollup/plugin-typescript": "^8.2.0", | ||
"@types/jest": "^26.0.21", | ||
"@blackglory/jest-matchers": "^0.1.21", | ||
"@blackglory/types": "^0.5.1", | ||
"@commitlint/cli": "^13.2.1", | ||
"@commitlint/config-conventional": "^13.2.0", | ||
"@rollup/plugin-typescript": "^8.2.5", | ||
"@types/jest": "^27.0.2", | ||
"@types/node": "^14.14.35", | ||
"@typescript-eslint/eslint-plugin": "^4.18.0", | ||
"@typescript-eslint/parser": "^4.18.0", | ||
"eslint": "^7.22.0", | ||
"@typescript-eslint/eslint-plugin": "^5.0.0", | ||
"@typescript-eslint/parser": "^5.0.0", | ||
"eslint": "^8.0.1", | ||
"husky": "4", | ||
"iterable-operator": "^0.13.5", | ||
"jest": "^26.6.3", | ||
"jest-extended": "^0.11.5", | ||
"iterable-operator": "^0.14.4", | ||
"jest": "^27.2.5", | ||
"jest-extended": "^1.0.0", | ||
"npm-run-all": "^4.1.5", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.42.1", | ||
"rollup": "^2.58.0", | ||
"rollup-plugin-analyzer": "^4.0.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"standard-version": "^9.1.1", | ||
"ts-jest": "^26.5.4", | ||
"standard-version": "^9.3.1", | ||
"ts-jest": "^27.0.5", | ||
"tscpaths": "^0.0.9", | ||
"tslib": "^2.1.0", | ||
"typescript": "^4.2.3" | ||
"tslib": "^2.3.1", | ||
"typescript": "^4.4.4" | ||
}, | ||
@@ -84,0 +84,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
637268
5290