return-style
Advanced tools
Comparing version 0.12.2 to 0.12.3
@@ -5,2 +5,9 @@ # Changelog | ||
### [0.12.3](https://github.com/BlackGlory/return-style/compare/v0.12.2...v0.12.3) (2021-03-20) | ||
### Features | ||
* improve tuple results ([ff67948](https://github.com/BlackGlory/return-style/commit/ff6794850a5935aea237f01b921855c0429c5106)) | ||
### [0.12.2](https://github.com/BlackGlory/return-style/compare/v0.12.1...v0.12.2) (2021-02-25) | ||
@@ -7,0 +14,0 @@ |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReturnStyle = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@blackglory/go')) : | ||
typeof define === 'function' && define.amd ? define(['exports', '@blackglory/go'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReturnStyle = {}, global.go)); | ||
}(this, (function (exports, go) { 'use strict'; | ||
@@ -361,3 +361,3 @@ function getErrorResult(fn) { | ||
var _value, _value_1; | ||
var _value$1, _value_1; | ||
class Result { | ||
@@ -374,4 +374,4 @@ static Ok(value) { | ||
super(); | ||
_value.set(this, void 0); | ||
__classPrivateFieldSet(this, _value, value); | ||
_value$1.set(this, void 0); | ||
__classPrivateFieldSet(this, _value$1, value); | ||
} | ||
@@ -388,19 +388,19 @@ static of(value) { | ||
onOk(callback) { | ||
callback(__classPrivateFieldGet(this, _value)); | ||
return Ok.of(__classPrivateFieldGet(this, _value)); | ||
callback(__classPrivateFieldGet(this, _value$1)); | ||
return Ok.of(__classPrivateFieldGet(this, _value$1)); | ||
} | ||
onErr() { | ||
return Ok.of(__classPrivateFieldGet(this, _value)); | ||
return Ok.of(__classPrivateFieldGet(this, _value$1)); | ||
} | ||
orElse() { | ||
return Ok.of(__classPrivateFieldGet(this, _value)); | ||
return Ok.of(__classPrivateFieldGet(this, _value$1)); | ||
} | ||
map(fn) { | ||
return Ok.of(fn(__classPrivateFieldGet(this, _value))); | ||
return Ok.of(fn(__classPrivateFieldGet(this, _value$1))); | ||
} | ||
get() { | ||
return __classPrivateFieldGet(this, _value); | ||
return __classPrivateFieldGet(this, _value$1); | ||
} | ||
} | ||
_value = new WeakMap(); | ||
_value$1 = new WeakMap(); | ||
class Err extends Result { | ||
@@ -450,7 +450,7 @@ constructor(err) { | ||
var _promise; | ||
var _promise$1; | ||
class AsyncResult { | ||
constructor(promise) { | ||
_promise.set(this, void 0); | ||
__classPrivateFieldSet(this, _promise, Promise.resolve(promise)); | ||
_promise$1.set(this, void 0); | ||
__classPrivateFieldSet(this, _promise$1, Promise.resolve(promise)); | ||
} | ||
@@ -464,24 +464,24 @@ static Ok(value) { | ||
get then() { | ||
const promise = __classPrivateFieldGet(this, _promise).then(x => Result.Ok(x), x => Result.Err(x)); | ||
const promise = __classPrivateFieldGet(this, _promise$1).then(x => Result.Ok(x), x => Result.Err(x)); | ||
return promise.then.bind(promise); | ||
} | ||
onOk(callback) { | ||
(() => __awaiter(this, void 0, void 0, function* () { | ||
const [succ, ret] = yield getSuccessPromise(__classPrivateFieldGet(this, _promise)); | ||
go.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const [succ, ret] = yield getSuccessPromise(__classPrivateFieldGet(this, _promise$1)); | ||
if (succ) | ||
callback(ret); | ||
}))(); | ||
return new AsyncResult(__classPrivateFieldGet(this, _promise)); | ||
})); | ||
return new AsyncResult(__classPrivateFieldGet(this, _promise$1)); | ||
} | ||
onErr(callback) { | ||
(() => __awaiter(this, void 0, void 0, function* () { | ||
const [fail, err] = yield getFailurePromise(__classPrivateFieldGet(this, _promise)); | ||
go.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const [fail, err] = yield getFailurePromise(__classPrivateFieldGet(this, _promise$1)); | ||
if (fail) | ||
callback(err); | ||
}))(); | ||
return new AsyncResult(__classPrivateFieldGet(this, _promise)); | ||
})); | ||
return new AsyncResult(__classPrivateFieldGet(this, _promise$1)); | ||
} | ||
isOk() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield isSuccessPromise(__classPrivateFieldGet(this, _promise)); | ||
return yield isSuccessPromise(__classPrivateFieldGet(this, _promise$1)); | ||
}); | ||
@@ -491,9 +491,9 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield isFailurePromise(__classPrivateFieldGet(this, _promise)); | ||
return yield isFailurePromise(__classPrivateFieldGet(this, _promise$1)); | ||
}); | ||
} | ||
orElse(defaultValue) { | ||
return new AsyncResult((() => __awaiter(this, void 0, void 0, function* () { | ||
const promise = go.go(() => __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
return yield __classPrivateFieldGet(this, _promise); | ||
return yield __classPrivateFieldGet(this, _promise$1); | ||
} | ||
@@ -503,17 +503,19 @@ catch (_a) { | ||
} | ||
}))()); | ||
})); | ||
return new AsyncResult(promise); | ||
} | ||
map(mapper) { | ||
return new AsyncResult((() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
const promise = go.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise$1); | ||
return mapper(result); | ||
}))()); | ||
})); | ||
return new AsyncResult(promise); | ||
} | ||
get() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield __classPrivateFieldGet(this, _promise); | ||
return yield __classPrivateFieldGet(this, _promise$1); | ||
}); | ||
} | ||
} | ||
_promise = new WeakMap(); | ||
_promise$1 = new WeakMap(); | ||
class AsyncOk extends AsyncResult { | ||
@@ -550,3 +552,3 @@ static of(value) { | ||
var _value$1; | ||
var _value; | ||
class Optional { | ||
@@ -563,4 +565,4 @@ static Some(value) { | ||
super(); | ||
_value$1.set(this, void 0); | ||
__classPrivateFieldSet(this, _value$1, value); | ||
_value.set(this, void 0); | ||
__classPrivateFieldSet(this, _value, value); | ||
} | ||
@@ -577,17 +579,17 @@ static of(value) { | ||
onSome(callback) { | ||
callback(__classPrivateFieldGet(this, _value$1)); | ||
return Some.of(__classPrivateFieldGet(this, _value$1)); | ||
callback(__classPrivateFieldGet(this, _value)); | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
} | ||
onNone() { | ||
return Some.of(__classPrivateFieldGet(this, _value$1)); | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
} | ||
orElse() { | ||
return Some.of(__classPrivateFieldGet(this, _value$1)); | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
} | ||
map(mapper) { | ||
return Some.of(mapper(__classPrivateFieldGet(this, _value$1))); | ||
return Some.of(mapper(__classPrivateFieldGet(this, _value))); | ||
} | ||
filter(predicate) { | ||
if (predicate(__classPrivateFieldGet(this, _value$1))) { | ||
return Some.of(__classPrivateFieldGet(this, _value$1)); | ||
if (predicate(__classPrivateFieldGet(this, _value))) { | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
} | ||
@@ -599,6 +601,6 @@ else { | ||
get() { | ||
return __classPrivateFieldGet(this, _value$1); | ||
return __classPrivateFieldGet(this, _value); | ||
} | ||
} | ||
_value$1 = new WeakMap(); | ||
_value = new WeakMap(); | ||
class None extends Optional { | ||
@@ -651,8 +653,8 @@ static of() { | ||
var _promise$1; | ||
var _promise; | ||
const Nil = Symbol(); | ||
class AsyncOptional { | ||
constructor(promise) { | ||
_promise$1.set(this, void 0); | ||
__classPrivateFieldSet(this, _promise$1, Promise.resolve(promise)); | ||
_promise.set(this, void 0); | ||
__classPrivateFieldSet(this, _promise, Promise.resolve(promise)); | ||
} | ||
@@ -666,3 +668,3 @@ static Some(value) { | ||
get then() { | ||
const promise = __classPrivateFieldGet(this, _promise$1).then(x => x === Nil | ||
const promise = __classPrivateFieldGet(this, _promise).then(x => x === Nil | ||
? Optional.None() | ||
@@ -673,20 +675,20 @@ : Optional.Some(x)); | ||
onSome(callback) { | ||
(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise$1); | ||
go.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
if (result !== Nil) | ||
callback(result); | ||
}))(); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _promise$1)); | ||
})); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _promise)); | ||
} | ||
onNone(callback) { | ||
(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise$1); | ||
go.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
if (result === Nil) | ||
callback(); | ||
}))(); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _promise$1)); | ||
})); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _promise)); | ||
} | ||
isSome() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise$1); | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
return result !== Nil; | ||
@@ -697,3 +699,3 @@ }); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise$1); | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
return result === Nil; | ||
@@ -703,20 +705,22 @@ }); | ||
orElse(defaultValue) { | ||
return new AsyncOptional((() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise$1); | ||
const promise = go.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
if (result === Nil) | ||
return defaultValue; | ||
return result; | ||
}))()); | ||
})); | ||
return new AsyncOptional(promise); | ||
} | ||
map(mapper) { | ||
return new AsyncOptional((() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise$1); | ||
const promise = go.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
if (result === Nil) | ||
return Nil; | ||
return mapper(result); | ||
}))()); | ||
})); | ||
return new AsyncOptional(promise); | ||
} | ||
filter(predicate) { | ||
return new AsyncOptional((() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise$1); | ||
const promise = go.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
if (result === Nil) | ||
@@ -727,7 +731,8 @@ return Nil; | ||
return Nil; | ||
}))()); | ||
})); | ||
return new AsyncOptional(promise); | ||
} | ||
get() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise$1); | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
if (result === Nil) | ||
@@ -739,3 +744,3 @@ throw new Error('Cannot get value from None'); | ||
} | ||
_promise$1 = new WeakMap(); | ||
_promise = new WeakMap(); | ||
class AsyncNone extends AsyncOptional { | ||
@@ -762,3 +767,3 @@ static of() { | ||
function toOptionalAsync(fn, isNone) { | ||
return new AsyncOptional((() => __awaiter(this, void 0, void 0, function* () { | ||
const promise = go.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield fn(); | ||
@@ -768,3 +773,4 @@ if (isNone(result)) | ||
return result; | ||
}))()); | ||
})); | ||
return new AsyncOptional(promise); | ||
} | ||
@@ -776,3 +782,3 @@ | ||
function toOptionalPromise(promise, isNone) { | ||
return new AsyncOptional((() => __awaiter(this, void 0, void 0, function* () { | ||
return new AsyncOptional(go.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield promise; | ||
@@ -782,3 +788,3 @@ if (isNone(result)) | ||
return result; | ||
}))()); | ||
}))); | ||
} | ||
@@ -785,0 +791,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((t="undefined"!=typeof globalThis?globalThis:t||self).ReturnStyle={})}(this,(function(t){"use strict"; | ||
!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"; | ||
/*! ***************************************************************************** | ||
@@ -16,3 +16,3 @@ Copyright (c) Microsoft Corporation. | ||
***************************************************************************** */ | ||
function r(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 n(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 e(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,e=t[Symbol.asyncIterator];return e?e.call(t):(t=n(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 o(t,r){if(!r.has(t))throw new TypeError("attempted to get private field on non-instance");return r.get(t)}function i(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 u(t){return r(this,void 0,void 0,(function*(){try{return[!0,yield t]}catch(t){return[!1,void 0]}}))}function s(t){return r(this,void 0,void 0,(function*(){try{return yield t,[!1,void 0]}catch(t){return[!0,t]}}))}function c(t){return r(this,void 0,void 0,(function*(){try{return yield t,!0}catch(t){return!1}}))}function d(t){return r(this,void 0,void 0,(function*(){try{return yield t,!1}catch(t){return!0}}))}var f,h,a,l,v;class y{static Ok(t){return m.of(t)}static Err(t){return p.of(t)}}class m extends y{constructor(t){super(),f.set(this,void 0),i(this,f,t)}static of(t){return new m(t)}isOk(){return!0}isErr(){return!1}onOk(t){return t(o(this,f)),m.of(o(this,f))}onErr(){return m.of(o(this,f))}orElse(){return m.of(o(this,f))}map(t){return m.of(t(o(this,f)))}get(){return o(this,f)}}f=new WeakMap;class p extends y{constructor(t){super(),h.set(this,void 0),i(this,h,t)}static of(t){return new p(t)}isOk(){return!1}isErr(){return!0}onOk(){return p.of(o(this,h))}onErr(t){return t(o(this,h)),p.of(o(this,h))}orElse(t){return m.of(t)}map(){return p.of(o(this,h))}get(){throw o(this,h)}}h=new WeakMap;class w{constructor(t){a.set(this,void 0),i(this,a,Promise.resolve(t))}static Ok(t){return g.of(t)}static Err(t){return E.of(t)}get then(){const t=o(this,a).then((t=>y.Ok(t)),(t=>y.Err(t)));return t.then.bind(t)}onOk(t){return(()=>{r(this,void 0,void 0,(function*(){const[r,n]=yield u(o(this,a));r&&t(n)}))})(),new w(o(this,a))}onErr(t){return(()=>{r(this,void 0,void 0,(function*(){const[r,n]=yield s(o(this,a));r&&t(n)}))})(),new w(o(this,a))}isOk(){return r(this,void 0,void 0,(function*(){return yield c(o(this,a))}))}isErr(){return r(this,void 0,void 0,(function*(){return yield d(o(this,a))}))}orElse(t){return new w((()=>r(this,void 0,void 0,(function*(){try{return yield o(this,a)}catch(r){return t}})))())}map(t){return new w((()=>r(this,void 0,void 0,(function*(){const r=yield o(this,a);return t(r)})))())}get(){return r(this,void 0,void 0,(function*(){return yield o(this,a)}))}}a=new WeakMap;class g extends w{static of(t){return new g(t)}constructor(t){super(Promise.resolve(t))}}class E extends w{static of(t){return new E(t)}constructor(t){super(Promise.reject(t))}}class S{static Some(t){return P.of(t)}static None(){return b.of()}}class P extends S{constructor(t){super(),l.set(this,void 0),i(this,l,t)}static of(t){return new P(t)}isSome(){return!0}isNone(){return!1}onSome(t){return t(o(this,l)),P.of(o(this,l))}onNone(){return P.of(o(this,l))}orElse(){return P.of(o(this,l))}map(t){return P.of(t(o(this,l)))}filter(t){return t(o(this,l))?P.of(o(this,l)):b.of()}get(){return o(this,l)}}l=new WeakMap;class b extends S{static of(){return new b}constructor(){super()}isSome(){return!1}isNone(){return!0}onSome(){return b.of()}onNone(t){return t(),b.of()}orElse(t){return P.of(t)}map(){return b.of()}filter(){return b.of()}get(){throw new Error("Cannot get value from None")}}function O(t,r){const n=t();return r(n)?S.None():S.Some(n)}const x=Symbol();class k{constructor(t){v.set(this,void 0),i(this,v,Promise.resolve(t))}static Some(t){return A.of(t)}static None(){return R.of()}get then(){const t=o(this,v).then((t=>t===x?S.None():S.Some(t)));return t.then.bind(t)}onSome(t){return(()=>{r(this,void 0,void 0,(function*(){const r=yield o(this,v);r!==x&&t(r)}))})(),new k(o(this,v))}onNone(t){return(()=>{r(this,void 0,void 0,(function*(){(yield o(this,v))===x&&t()}))})(),new k(o(this,v))}isSome(){return r(this,void 0,void 0,(function*(){return(yield o(this,v))!==x}))}isNone(){return r(this,void 0,void 0,(function*(){return(yield o(this,v))===x}))}orElse(t){return new k((()=>r(this,void 0,void 0,(function*(){const r=yield o(this,v);return r===x?t:r})))())}map(t){return new k((()=>r(this,void 0,void 0,(function*(){const r=yield o(this,v);return r===x?x:t(r)})))())}filter(t){return new k((()=>r(this,void 0,void 0,(function*(){const r=yield o(this,v);return r===x?x:t(r)?r:x})))())}get(){return r(this,void 0,void 0,(function*(){const t=yield o(this,v);if(t===x)throw new Error("Cannot get value from None");return t}))}}v=new WeakMap;class R extends k{static of(){return new R}constructor(){super(Promise.resolve(x))}}class A extends k{static of(t){return new A(t)}constructor(t){super(Promise.resolve(t))}}function N(t,n){return new k((()=>r(this,void 0,void 0,(function*(){const r=yield t();return n(r)?x:r})))())}function F(t,n){return new k((()=>r(this,void 0,void 0,(function*(){const r=yield t;return n(r)?x:r})))())}t.getError=function(t){try{t()}catch(t){return t}},t.getErrorAsync=function(t){return r(this,void 0,void 0,(function*(){try{yield t()}catch(t){return t}}))},t.getErrorAsyncIterable=function(t){var n,o,i,u;return r(this,void 0,void 0,(function*(){try{try{for(n=e(t);!(o=yield n.next()).done;){o.value}}catch(t){i={error:t}}finally{try{o&&!o.done&&(u=n.return)&&(yield u.call(n))}finally{if(i)throw i.error}}}catch(t){return t}}))},t.getErrorPromise=function(t){return r(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 r(this,void 0,void 0,(function*(){try{return[void 0,yield t()]}catch(t){return[t,void 0]}}))},t.getErrorResultPromise=function(t){return r(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 r(this,void 0,void 0,(function*(){try{return yield t(),[!1,void 0]}catch(t){return[!0,t]}}))},t.getFailurePromise=s,t.getResult=function(t){try{return t()}catch(t){return}},t.getResultAsync=function(t){return r(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 r(this,void 0,void 0,(function*(){try{return[yield t(),void 0]}catch(t){return[void 0,t]}}))},t.getResultErrorPromise=function(t){return r(this,void 0,void 0,(function*(){try{return[yield t,void 0]}catch(t){return[void 0,t]}}))},t.getResultPromise=function(t){return r(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 r(this,void 0,void 0,(function*(){try{return[!0,yield t()]}catch(t){return[!1,void 0]}}))},t.getSuccessPromise=u,t.isFailure=function(t){try{return t(),!1}catch(t){return!0}},t.isFailureAsync=function(t){return r(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 r(this,void 0,void 0,(function*(){try{return yield t(),!0}catch(t){return!1}}))},t.isSuccessPromise=c,t.toOptional=O,t.toOptionalAsync=N,t.toOptionalAsyncPartial=function(t){return r=>N(r,t)},t.toOptionalPartial=function(t){return r=>O(r,t)},t.toOptionalPromise=F,t.toOptionalPromisePartial=function(t){return r=>F(r,t)},t.toResult=function(t){try{const r=t();return y.Ok(r)}catch(t){return y.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){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})})); | ||
//# sourceMappingURL=index.umd.min.js.map |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReturnStyle = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@blackglory/go')) : | ||
typeof define === 'function' && define.amd ? define(['exports', '@blackglory/go'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReturnStyle = {}, global.go)); | ||
}(this, (function (exports, go) { 'use strict'; | ||
@@ -284,3 +284,3 @@ function getErrorResult(fn) { | ||
var _value, _value_1; | ||
var _value$1, _value_1; | ||
class Result { | ||
@@ -297,4 +297,4 @@ static Ok(value) { | ||
super(); | ||
_value.set(this, void 0); | ||
__classPrivateFieldSet(this, _value, value); | ||
_value$1.set(this, void 0); | ||
__classPrivateFieldSet(this, _value$1, value); | ||
} | ||
@@ -311,19 +311,19 @@ static of(value) { | ||
onOk(callback) { | ||
callback(__classPrivateFieldGet(this, _value)); | ||
return Ok.of(__classPrivateFieldGet(this, _value)); | ||
callback(__classPrivateFieldGet(this, _value$1)); | ||
return Ok.of(__classPrivateFieldGet(this, _value$1)); | ||
} | ||
onErr() { | ||
return Ok.of(__classPrivateFieldGet(this, _value)); | ||
return Ok.of(__classPrivateFieldGet(this, _value$1)); | ||
} | ||
orElse() { | ||
return Ok.of(__classPrivateFieldGet(this, _value)); | ||
return Ok.of(__classPrivateFieldGet(this, _value$1)); | ||
} | ||
map(fn) { | ||
return Ok.of(fn(__classPrivateFieldGet(this, _value))); | ||
return Ok.of(fn(__classPrivateFieldGet(this, _value$1))); | ||
} | ||
get() { | ||
return __classPrivateFieldGet(this, _value); | ||
return __classPrivateFieldGet(this, _value$1); | ||
} | ||
} | ||
_value = new WeakMap(); | ||
_value$1 = new WeakMap(); | ||
class Err extends Result { | ||
@@ -373,7 +373,7 @@ constructor(err) { | ||
var _promise; | ||
var _promise$1; | ||
class AsyncResult { | ||
constructor(promise) { | ||
_promise.set(this, void 0); | ||
__classPrivateFieldSet(this, _promise, Promise.resolve(promise)); | ||
_promise$1.set(this, void 0); | ||
__classPrivateFieldSet(this, _promise$1, Promise.resolve(promise)); | ||
} | ||
@@ -387,31 +387,31 @@ static Ok(value) { | ||
get then() { | ||
const promise = __classPrivateFieldGet(this, _promise).then(x => Result.Ok(x), x => Result.Err(x)); | ||
const promise = __classPrivateFieldGet(this, _promise$1).then(x => Result.Ok(x), x => Result.Err(x)); | ||
return promise.then.bind(promise); | ||
} | ||
onOk(callback) { | ||
(async () => { | ||
const [succ, ret] = await getSuccessPromise(__classPrivateFieldGet(this, _promise)); | ||
go.go(async () => { | ||
const [succ, ret] = await getSuccessPromise(__classPrivateFieldGet(this, _promise$1)); | ||
if (succ) | ||
callback(ret); | ||
})(); | ||
return new AsyncResult(__classPrivateFieldGet(this, _promise)); | ||
}); | ||
return new AsyncResult(__classPrivateFieldGet(this, _promise$1)); | ||
} | ||
onErr(callback) { | ||
(async () => { | ||
const [fail, err] = await getFailurePromise(__classPrivateFieldGet(this, _promise)); | ||
go.go(async () => { | ||
const [fail, err] = await getFailurePromise(__classPrivateFieldGet(this, _promise$1)); | ||
if (fail) | ||
callback(err); | ||
})(); | ||
return new AsyncResult(__classPrivateFieldGet(this, _promise)); | ||
}); | ||
return new AsyncResult(__classPrivateFieldGet(this, _promise$1)); | ||
} | ||
async isOk() { | ||
return await isSuccessPromise(__classPrivateFieldGet(this, _promise)); | ||
return await isSuccessPromise(__classPrivateFieldGet(this, _promise$1)); | ||
} | ||
async isErr() { | ||
return await isFailurePromise(__classPrivateFieldGet(this, _promise)); | ||
return await isFailurePromise(__classPrivateFieldGet(this, _promise$1)); | ||
} | ||
orElse(defaultValue) { | ||
return new AsyncResult((async () => { | ||
const promise = go.go(async () => { | ||
try { | ||
return await __classPrivateFieldGet(this, _promise); | ||
return await __classPrivateFieldGet(this, _promise$1); | ||
} | ||
@@ -421,15 +421,17 @@ catch (_a) { | ||
} | ||
})()); | ||
}); | ||
return new AsyncResult(promise); | ||
} | ||
map(mapper) { | ||
return new AsyncResult((async () => { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
const promise = go.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise$1); | ||
return mapper(result); | ||
})()); | ||
}); | ||
return new AsyncResult(promise); | ||
} | ||
async get() { | ||
return await __classPrivateFieldGet(this, _promise); | ||
return await __classPrivateFieldGet(this, _promise$1); | ||
} | ||
} | ||
_promise = new WeakMap(); | ||
_promise$1 = new WeakMap(); | ||
class AsyncOk extends AsyncResult { | ||
@@ -466,3 +468,3 @@ static of(value) { | ||
var _value$1; | ||
var _value; | ||
class Optional { | ||
@@ -479,4 +481,4 @@ static Some(value) { | ||
super(); | ||
_value$1.set(this, void 0); | ||
__classPrivateFieldSet(this, _value$1, value); | ||
_value.set(this, void 0); | ||
__classPrivateFieldSet(this, _value, value); | ||
} | ||
@@ -493,17 +495,17 @@ static of(value) { | ||
onSome(callback) { | ||
callback(__classPrivateFieldGet(this, _value$1)); | ||
return Some.of(__classPrivateFieldGet(this, _value$1)); | ||
callback(__classPrivateFieldGet(this, _value)); | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
} | ||
onNone() { | ||
return Some.of(__classPrivateFieldGet(this, _value$1)); | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
} | ||
orElse() { | ||
return Some.of(__classPrivateFieldGet(this, _value$1)); | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
} | ||
map(mapper) { | ||
return Some.of(mapper(__classPrivateFieldGet(this, _value$1))); | ||
return Some.of(mapper(__classPrivateFieldGet(this, _value))); | ||
} | ||
filter(predicate) { | ||
if (predicate(__classPrivateFieldGet(this, _value$1))) { | ||
return Some.of(__classPrivateFieldGet(this, _value$1)); | ||
if (predicate(__classPrivateFieldGet(this, _value))) { | ||
return Some.of(__classPrivateFieldGet(this, _value)); | ||
} | ||
@@ -515,6 +517,6 @@ else { | ||
get() { | ||
return __classPrivateFieldGet(this, _value$1); | ||
return __classPrivateFieldGet(this, _value); | ||
} | ||
} | ||
_value$1 = new WeakMap(); | ||
_value = new WeakMap(); | ||
class None extends Optional { | ||
@@ -567,8 +569,8 @@ static of() { | ||
var _promise$1; | ||
var _promise; | ||
const Nil = Symbol(); | ||
class AsyncOptional { | ||
constructor(promise) { | ||
_promise$1.set(this, void 0); | ||
__classPrivateFieldSet(this, _promise$1, Promise.resolve(promise)); | ||
_promise.set(this, void 0); | ||
__classPrivateFieldSet(this, _promise, Promise.resolve(promise)); | ||
} | ||
@@ -582,3 +584,3 @@ static Some(value) { | ||
get then() { | ||
const promise = __classPrivateFieldGet(this, _promise$1).then(x => x === Nil | ||
const promise = __classPrivateFieldGet(this, _promise).then(x => x === Nil | ||
? Optional.None() | ||
@@ -589,44 +591,46 @@ : Optional.Some(x)); | ||
onSome(callback) { | ||
(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise$1); | ||
go.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
if (result !== Nil) | ||
callback(result); | ||
})(); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _promise$1)); | ||
}); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _promise)); | ||
} | ||
onNone(callback) { | ||
(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise$1); | ||
go.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
if (result === Nil) | ||
callback(); | ||
})(); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _promise$1)); | ||
}); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _promise)); | ||
} | ||
async isSome() { | ||
const result = await __classPrivateFieldGet(this, _promise$1); | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
return result !== Nil; | ||
} | ||
async isNone() { | ||
const result = await __classPrivateFieldGet(this, _promise$1); | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
return result === Nil; | ||
} | ||
orElse(defaultValue) { | ||
return new AsyncOptional((async () => { | ||
const result = await __classPrivateFieldGet(this, _promise$1); | ||
const promise = go.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
if (result === Nil) | ||
return defaultValue; | ||
return result; | ||
})()); | ||
}); | ||
return new AsyncOptional(promise); | ||
} | ||
map(mapper) { | ||
return new AsyncOptional((async () => { | ||
const result = await __classPrivateFieldGet(this, _promise$1); | ||
const promise = go.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
if (result === Nil) | ||
return Nil; | ||
return mapper(result); | ||
})()); | ||
}); | ||
return new AsyncOptional(promise); | ||
} | ||
filter(predicate) { | ||
return new AsyncOptional((async () => { | ||
const result = await __classPrivateFieldGet(this, _promise$1); | ||
const promise = go.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
if (result === Nil) | ||
@@ -637,6 +641,7 @@ return Nil; | ||
return Nil; | ||
})()); | ||
}); | ||
return new AsyncOptional(promise); | ||
} | ||
async get() { | ||
const result = await __classPrivateFieldGet(this, _promise$1); | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
if (result === Nil) | ||
@@ -647,3 +652,3 @@ throw new Error('Cannot get value from None'); | ||
} | ||
_promise$1 = new WeakMap(); | ||
_promise = new WeakMap(); | ||
class AsyncNone extends AsyncOptional { | ||
@@ -670,3 +675,3 @@ static of() { | ||
function toOptionalAsync(fn, isNone) { | ||
return new AsyncOptional((async () => { | ||
const promise = go.go(async () => { | ||
const result = await fn(); | ||
@@ -676,3 +681,4 @@ if (isNone(result)) | ||
return result; | ||
})()); | ||
}); | ||
return new AsyncOptional(promise); | ||
} | ||
@@ -684,3 +690,3 @@ | ||
function toOptionalPromise(promise, isNone) { | ||
return new AsyncOptional((async () => { | ||
return new AsyncOptional(go.go(async () => { | ||
const result = await promise; | ||
@@ -690,3 +696,3 @@ if (isNone(result)) | ||
return result; | ||
})()); | ||
})); | ||
} | ||
@@ -693,0 +699,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((t="undefined"!=typeof globalThis?globalThis:t||self).ReturnStyle={})}(this,(function(t){"use strict";async function r(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 e(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 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}} | ||
/*! ***************************************************************************** | ||
@@ -16,3 +16,3 @@ Copyright (c) Microsoft Corporation. | ||
***************************************************************************** */ | ||
function o(t,r){if(!r.has(t))throw new TypeError("attempted to get private field on non-instance");return r.get(t)}function i(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 c,u,a,f,h;class y{static Ok(t){return w.of(t)}static Err(t){return l.of(t)}}class w extends y{constructor(t){super(),c.set(this,void 0),i(this,c,t)}static of(t){return new w(t)}isOk(){return!0}isErr(){return!1}onOk(t){return t(o(this,c)),w.of(o(this,c))}onErr(){return w.of(o(this,c))}orElse(){return w.of(o(this,c))}map(t){return w.of(t(o(this,c)))}get(){return o(this,c)}}c=new WeakMap;class l extends y{constructor(t){super(),u.set(this,void 0),i(this,u,t)}static of(t){return new l(t)}isOk(){return!1}isErr(){return!0}onOk(){return l.of(o(this,u))}onErr(t){return t(o(this,u)),l.of(o(this,u))}orElse(t){return w.of(t)}map(){return l.of(o(this,u))}get(){throw o(this,u)}}u=new WeakMap;class d{constructor(t){a.set(this,void 0),i(this,a,Promise.resolve(t))}static Ok(t){return m.of(t)}static Err(t){return p.of(t)}get then(){const t=o(this,a).then((t=>y.Ok(t)),(t=>y.Err(t)));return t.then.bind(t)}onOk(t){return(async()=>{const[n,e]=await r(o(this,a));n&&t(e)})(),new d(o(this,a))}onErr(t){return(async()=>{const[r,e]=await n(o(this,a));r&&t(e)})(),new d(o(this,a))}async isOk(){return await e(o(this,a))}async isErr(){return await s(o(this,a))}orElse(t){return new d((async()=>{try{return await o(this,a)}catch(r){return t}})())}map(t){return new d((async()=>{const r=await o(this,a);return t(r)})())}async get(){return await o(this,a)}}a=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 g.of(t)}static None(){return E.of()}}class g extends v{constructor(t){super(),f.set(this,void 0),i(this,f,t)}static of(t){return new g(t)}isSome(){return!0}isNone(){return!1}onSome(t){return t(o(this,f)),g.of(o(this,f))}onNone(){return g.of(o(this,f))}orElse(){return g.of(o(this,f))}map(t){return g.of(t(o(this,f)))}filter(t){return t(o(this,f))?g.of(o(this,f)):E.of()}get(){return o(this,f)}}f=new WeakMap;class E extends v{static of(){return new E}constructor(){super()}isSome(){return!1}isNone(){return!0}onSome(){return E.of()}onNone(t){return t(),E.of()}orElse(t){return g.of(t)}map(){return E.of()}filter(){return E.of()}get(){throw new Error("Cannot get value from None")}}function P(t,r){const n=t();return r(n)?v.None():v.Some(n)}const S=Symbol();class O{constructor(t){h.set(this,void 0),i(this,h,Promise.resolve(t))}static Some(t){return R.of(t)}static None(){return k.of()}get then(){const t=o(this,h).then((t=>t===S?v.None():v.Some(t)));return t.then.bind(t)}onSome(t){return(async()=>{const r=await o(this,h);r!==S&&t(r)})(),new O(o(this,h))}onNone(t){return(async()=>{await o(this,h)===S&&t()})(),new O(o(this,h))}async isSome(){return await o(this,h)!==S}async isNone(){return await o(this,h)===S}orElse(t){return new O((async()=>{const r=await o(this,h);return r===S?t:r})())}map(t){return new O((async()=>{const r=await o(this,h);return r===S?S:t(r)})())}filter(t){return new O((async()=>{const r=await o(this,h);return r===S?S:t(r)?r:S})())}async get(){const t=await o(this,h);if(t===S)throw new Error("Cannot get value from None");return t}}h=new WeakMap;class k extends O{static of(){return new k}constructor(){super(Promise.resolve(S))}}class R extends O{static of(t){return new R(t)}constructor(t){super(Promise.resolve(t))}}function A(t,r){return new O((async()=>{const n=await t();return r(n)?S:n})())}function N(t,r){return new O((async()=>{const n=await t;return r(n)?S:n})())}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=r,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=e,t.toOptional=P,t.toOptionalAsync=A,t.toOptionalAsyncPartial=function(t){return r=>A(r,t)},t.toOptionalPartial=function(t){return r=>P(r,t)},t.toOptionalPromise=N,t.toOptionalPromisePartial=function(t){return r=>N(r,t)},t.toResult=function(t){try{const r=t();return y.Ok(r)}catch(t){return y.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){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})})); | ||
//# sourceMappingURL=index.umd.min.js.map |
@@ -27,2 +27,3 @@ "use strict"; | ||
exports.AsyncOptional = exports.Nil = void 0; | ||
const go_1 = require("@blackglory/go"); | ||
const optional_1 = require("./optional"); | ||
@@ -48,17 +49,15 @@ exports.Nil = Symbol(); | ||
onSome(callback) { | ||
; | ||
(() => __awaiter(this, void 0, void 0, function* () { | ||
go_1.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
if (result !== exports.Nil) | ||
callback(result); | ||
}))(); | ||
})); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _promise)); | ||
} | ||
onNone(callback) { | ||
; | ||
(() => __awaiter(this, void 0, void 0, function* () { | ||
go_1.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
if (result === exports.Nil) | ||
callback(); | ||
}))(); | ||
})); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _promise)); | ||
@@ -79,3 +78,3 @@ } | ||
orElse(defaultValue) { | ||
return new AsyncOptional((() => __awaiter(this, void 0, void 0, function* () { | ||
const promise = go_1.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
@@ -85,6 +84,7 @@ if (result === exports.Nil) | ||
return result; | ||
}))()); | ||
})); | ||
return new AsyncOptional(promise); | ||
} | ||
map(mapper) { | ||
return new AsyncOptional((() => __awaiter(this, void 0, void 0, function* () { | ||
const promise = go_1.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
@@ -94,6 +94,7 @@ if (result === exports.Nil) | ||
return mapper(result); | ||
}))()); | ||
})); | ||
return new AsyncOptional(promise); | ||
} | ||
filter(predicate) { | ||
return new AsyncOptional((() => __awaiter(this, void 0, void 0, function* () { | ||
const promise = go_1.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
@@ -105,3 +106,4 @@ if (result === exports.Nil) | ||
return exports.Nil; | ||
}))()); | ||
})); | ||
return new AsyncOptional(promise); | ||
} | ||
@@ -108,0 +110,0 @@ get() { |
@@ -27,2 +27,3 @@ "use strict"; | ||
exports.AsyncResult = void 0; | ||
const go_1 = require("@blackglory/go"); | ||
const result_1 = require("./result"); | ||
@@ -49,17 +50,15 @@ const get_success_promise_1 = require("../functions/get-success-promise"); | ||
onOk(callback) { | ||
; | ||
(() => __awaiter(this, void 0, void 0, function* () { | ||
go_1.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const [succ, ret] = yield get_success_promise_1.getSuccessPromise(__classPrivateFieldGet(this, _promise)); | ||
if (succ) | ||
callback(ret); | ||
}))(); | ||
})); | ||
return new AsyncResult(__classPrivateFieldGet(this, _promise)); | ||
} | ||
onErr(callback) { | ||
; | ||
(() => __awaiter(this, void 0, void 0, function* () { | ||
go_1.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const [fail, err] = yield get_failure_promise_1.getFailurePromise(__classPrivateFieldGet(this, _promise)); | ||
if (fail) | ||
callback(err); | ||
}))(); | ||
})); | ||
return new AsyncResult(__classPrivateFieldGet(this, _promise)); | ||
@@ -78,3 +77,3 @@ } | ||
orElse(defaultValue) { | ||
return new AsyncResult((() => __awaiter(this, void 0, void 0, function* () { | ||
const promise = go_1.go(() => __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
@@ -86,9 +85,11 @@ return yield __classPrivateFieldGet(this, _promise); | ||
} | ||
}))()); | ||
})); | ||
return new AsyncResult(promise); | ||
} | ||
map(mapper) { | ||
return new AsyncResult((() => __awaiter(this, void 0, void 0, function* () { | ||
const promise = go_1.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield __classPrivateFieldGet(this, _promise); | ||
return mapper(result); | ||
}))()); | ||
})); | ||
return new AsyncResult(promise); | ||
} | ||
@@ -95,0 +96,0 @@ get() { |
@@ -1,1 +0,1 @@ | ||
export declare function getErrorResultAsync<X = Error, T = unknown>(fn: () => PromiseLike<T> | T): Promise<[undefined, T] | [X, undefined]>; | ||
export declare function getErrorResultAsync<X = Error, T = unknown>(fn: () => PromiseLike<T> | T): Promise<[error: undefined, result: T] | [error: X, result: undefined]>; |
@@ -1,1 +0,1 @@ | ||
export declare function getErrorResultPromise<X = Error, T = unknown>(promise: PromiseLike<T>): Promise<[undefined, T] | [X, undefined]>; | ||
export declare function getErrorResultPromise<X = Error, T = unknown>(promise: PromiseLike<T>): Promise<[error: undefined, result: T] | [error: X, result: undefined]>; |
@@ -1,1 +0,1 @@ | ||
export declare function getErrorResult<X = Error, T = unknown>(fn: () => T): [undefined, T] | [X, undefined]; | ||
export declare function getErrorResult<X = Error, T = unknown>(fn: () => T): [error: undefined, result: T] | [error: X, result: undefined]; |
@@ -1,1 +0,1 @@ | ||
export declare function getFailureAsync<X = Error>(fn: () => PromiseLike<unknown> | unknown): Promise<[true, X] | [false, undefined]>; | ||
export declare function getFailureAsync<X = Error>(fn: () => PromiseLike<unknown> | unknown): Promise<[failed: true, error: X] | [failed: false, error: undefined]>; |
@@ -1,1 +0,1 @@ | ||
export declare function getFailurePromise<X = Error>(promise: PromiseLike<unknown>): Promise<[true, X] | [false, undefined]>; | ||
export declare function getFailurePromise<X = Error>(promise: PromiseLike<unknown>): Promise<[failed: true, error: X] | [failed: false, error: undefined]>; |
@@ -1,1 +0,1 @@ | ||
export declare function getFailure<X = Error>(fn: () => unknown): [true, X] | [false, undefined]; | ||
export declare function getFailure<X = Error>(fn: () => unknown): [failed: true, error: X] | [faled: false, error: undefined]; |
@@ -1,1 +0,1 @@ | ||
export declare function getResultErrorAsync<X = Error, T = unknown>(fn: () => PromiseLike<T> | T): Promise<[T, undefined] | [undefined, X]>; | ||
export declare function getResultErrorAsync<X = Error, T = unknown>(fn: () => PromiseLike<T> | T): Promise<[result: T, error: undefined] | [result: undefined, error: X]>; |
@@ -1,1 +0,1 @@ | ||
export declare function getResultErrorPromise<X = Error, T = unknown>(promise: PromiseLike<T>): Promise<[T, undefined] | [undefined, X]>; | ||
export declare function getResultErrorPromise<X = Error, T = unknown>(promise: PromiseLike<T>): Promise<[result: T, error: undefined] | [result: undefined, error: X]>; |
@@ -1,1 +0,1 @@ | ||
export declare function getResultError<X = Error, T = unknown>(fn: () => T): [T, undefined] | [undefined, X]; | ||
export declare function getResultError<X = Error, T = unknown>(fn: () => T): [result: T, error: undefined] | [result: undefined, error: X]; |
@@ -1,1 +0,1 @@ | ||
export declare function getSuccessAsync<T>(fn: () => PromiseLike<T> | T): Promise<[true, T] | [false, undefined]>; | ||
export declare function getSuccessAsync<T>(fn: () => PromiseLike<T> | T): Promise<[succeeded: true, result: T] | [succeeded: false, result: undefined]>; |
@@ -1,1 +0,1 @@ | ||
export declare function getSuccessPromise<T>(promise: PromiseLike<T>): Promise<[true, T] | [false, undefined]>; | ||
export declare function getSuccessPromise<T>(promise: PromiseLike<T>): Promise<[succeeded: true, result: T] | [succeeded: false, result: undefined]>; |
@@ -1,1 +0,1 @@ | ||
export declare function getSuccess<T>(fn: () => T): [true, T] | [false, undefined]; | ||
export declare function getSuccess<T>(fn: () => T): [succeeded: true, result: T] | [succeeded: false, result: undefined]; |
@@ -13,2 +13,3 @@ "use strict"; | ||
exports.toOptionalAsync = exports.toOptionalAsyncPartial = void 0; | ||
const go_1 = require("@blackglory/go"); | ||
const async_optional_1 = require("../classes/async-optional"); | ||
@@ -20,3 +21,3 @@ function toOptionalAsyncPartial(isNone) { | ||
function toOptionalAsync(fn, isNone) { | ||
return new async_optional_1.AsyncOptional((() => __awaiter(this, void 0, void 0, function* () { | ||
const promise = go_1.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield fn(); | ||
@@ -26,5 +27,6 @@ if (isNone(result)) | ||
return result; | ||
}))()); | ||
})); | ||
return new async_optional_1.AsyncOptional(promise); | ||
} | ||
exports.toOptionalAsync = toOptionalAsync; | ||
//# sourceMappingURL=to-optional-async.js.map |
@@ -13,2 +13,3 @@ "use strict"; | ||
exports.toOptionalPromise = exports.toOptionalPromisePartial = void 0; | ||
const go_1 = require("@blackglory/go"); | ||
const async_optional_1 = require("../classes/async-optional"); | ||
@@ -20,3 +21,3 @@ function toOptionalPromisePartial(isNone) { | ||
function toOptionalPromise(promise, isNone) { | ||
return new async_optional_1.AsyncOptional((() => __awaiter(this, void 0, void 0, function* () { | ||
return new async_optional_1.AsyncOptional(go_1.go(() => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield promise; | ||
@@ -26,5 +27,5 @@ if (isNone(result)) | ||
return result; | ||
}))()); | ||
}))); | ||
} | ||
exports.toOptionalPromise = toOptionalPromise; | ||
//# sourceMappingURL=to-optional-promise.js.map |
@@ -18,2 +18,3 @@ "use strict"; | ||
exports.AsyncOptional = exports.Nil = void 0; | ||
const go_1 = require("@blackglory/go"); | ||
const optional_1 = require("./optional"); | ||
@@ -39,17 +40,15 @@ exports.Nil = Symbol(); | ||
onSome(callback) { | ||
; | ||
(async () => { | ||
go_1.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
if (result !== exports.Nil) | ||
callback(result); | ||
})(); | ||
}); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _promise)); | ||
} | ||
onNone(callback) { | ||
; | ||
(async () => { | ||
go_1.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
if (result === exports.Nil) | ||
callback(); | ||
})(); | ||
}); | ||
return new AsyncOptional(__classPrivateFieldGet(this, _promise)); | ||
@@ -66,3 +65,3 @@ } | ||
orElse(defaultValue) { | ||
return new AsyncOptional((async () => { | ||
const promise = go_1.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
@@ -72,6 +71,7 @@ if (result === exports.Nil) | ||
return result; | ||
})()); | ||
}); | ||
return new AsyncOptional(promise); | ||
} | ||
map(mapper) { | ||
return new AsyncOptional((async () => { | ||
const promise = go_1.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
@@ -81,6 +81,7 @@ if (result === exports.Nil) | ||
return mapper(result); | ||
})()); | ||
}); | ||
return new AsyncOptional(promise); | ||
} | ||
filter(predicate) { | ||
return new AsyncOptional((async () => { | ||
const promise = go_1.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
@@ -92,3 +93,4 @@ if (result === exports.Nil) | ||
return exports.Nil; | ||
})()); | ||
}); | ||
return new AsyncOptional(promise); | ||
} | ||
@@ -95,0 +97,0 @@ async get() { |
@@ -18,2 +18,3 @@ "use strict"; | ||
exports.AsyncResult = void 0; | ||
const go_1 = require("@blackglory/go"); | ||
const result_1 = require("./result"); | ||
@@ -40,17 +41,15 @@ const get_success_promise_1 = require("../functions/get-success-promise"); | ||
onOk(callback) { | ||
; | ||
(async () => { | ||
go_1.go(async () => { | ||
const [succ, ret] = await get_success_promise_1.getSuccessPromise(__classPrivateFieldGet(this, _promise)); | ||
if (succ) | ||
callback(ret); | ||
})(); | ||
}); | ||
return new AsyncResult(__classPrivateFieldGet(this, _promise)); | ||
} | ||
onErr(callback) { | ||
; | ||
(async () => { | ||
go_1.go(async () => { | ||
const [fail, err] = await get_failure_promise_1.getFailurePromise(__classPrivateFieldGet(this, _promise)); | ||
if (fail) | ||
callback(err); | ||
})(); | ||
}); | ||
return new AsyncResult(__classPrivateFieldGet(this, _promise)); | ||
@@ -65,3 +64,3 @@ } | ||
orElse(defaultValue) { | ||
return new AsyncResult((async () => { | ||
const promise = go_1.go(async () => { | ||
try { | ||
@@ -73,9 +72,11 @@ return await __classPrivateFieldGet(this, _promise); | ||
} | ||
})()); | ||
}); | ||
return new AsyncResult(promise); | ||
} | ||
map(mapper) { | ||
return new AsyncResult((async () => { | ||
const promise = go_1.go(async () => { | ||
const result = await __classPrivateFieldGet(this, _promise); | ||
return mapper(result); | ||
})()); | ||
}); | ||
return new AsyncResult(promise); | ||
} | ||
@@ -82,0 +83,0 @@ async get() { |
@@ -1,1 +0,1 @@ | ||
export declare function getErrorResultAsync<X = Error, T = unknown>(fn: () => PromiseLike<T> | T): Promise<[undefined, T] | [X, undefined]>; | ||
export declare function getErrorResultAsync<X = Error, T = unknown>(fn: () => PromiseLike<T> | T): Promise<[error: undefined, result: T] | [error: X, result: undefined]>; |
@@ -1,1 +0,1 @@ | ||
export declare function getErrorResultPromise<X = Error, T = unknown>(promise: PromiseLike<T>): Promise<[undefined, T] | [X, undefined]>; | ||
export declare function getErrorResultPromise<X = Error, T = unknown>(promise: PromiseLike<T>): Promise<[error: undefined, result: T] | [error: X, result: undefined]>; |
@@ -1,1 +0,1 @@ | ||
export declare function getErrorResult<X = Error, T = unknown>(fn: () => T): [undefined, T] | [X, undefined]; | ||
export declare function getErrorResult<X = Error, T = unknown>(fn: () => T): [error: undefined, result: T] | [error: X, result: undefined]; |
@@ -1,1 +0,1 @@ | ||
export declare function getFailureAsync<X = Error>(fn: () => PromiseLike<unknown> | unknown): Promise<[true, X] | [false, undefined]>; | ||
export declare function getFailureAsync<X = Error>(fn: () => PromiseLike<unknown> | unknown): Promise<[failed: true, error: X] | [failed: false, error: undefined]>; |
@@ -1,1 +0,1 @@ | ||
export declare function getFailurePromise<X = Error>(promise: PromiseLike<unknown>): Promise<[true, X] | [false, undefined]>; | ||
export declare function getFailurePromise<X = Error>(promise: PromiseLike<unknown>): Promise<[failed: true, error: X] | [failed: false, error: undefined]>; |
@@ -1,1 +0,1 @@ | ||
export declare function getFailure<X = Error>(fn: () => unknown): [true, X] | [false, undefined]; | ||
export declare function getFailure<X = Error>(fn: () => unknown): [failed: true, error: X] | [faled: false, error: undefined]; |
@@ -1,1 +0,1 @@ | ||
export declare function getResultErrorAsync<X = Error, T = unknown>(fn: () => PromiseLike<T> | T): Promise<[T, undefined] | [undefined, X]>; | ||
export declare function getResultErrorAsync<X = Error, T = unknown>(fn: () => PromiseLike<T> | T): Promise<[result: T, error: undefined] | [result: undefined, error: X]>; |
@@ -1,1 +0,1 @@ | ||
export declare function getResultErrorPromise<X = Error, T = unknown>(promise: PromiseLike<T>): Promise<[T, undefined] | [undefined, X]>; | ||
export declare function getResultErrorPromise<X = Error, T = unknown>(promise: PromiseLike<T>): Promise<[result: T, error: undefined] | [result: undefined, error: X]>; |
@@ -1,1 +0,1 @@ | ||
export declare function getResultError<X = Error, T = unknown>(fn: () => T): [T, undefined] | [undefined, X]; | ||
export declare function getResultError<X = Error, T = unknown>(fn: () => T): [result: T, error: undefined] | [result: undefined, error: X]; |
@@ -1,1 +0,1 @@ | ||
export declare function getSuccessAsync<T>(fn: () => PromiseLike<T> | T): Promise<[true, T] | [false, undefined]>; | ||
export declare function getSuccessAsync<T>(fn: () => PromiseLike<T> | T): Promise<[succeeded: true, result: T] | [succeeded: false, result: undefined]>; |
@@ -1,1 +0,1 @@ | ||
export declare function getSuccessPromise<T>(promise: PromiseLike<T>): Promise<[true, T] | [false, undefined]>; | ||
export declare function getSuccessPromise<T>(promise: PromiseLike<T>): Promise<[succeeded: true, result: T] | [succeeded: false, result: undefined]>; |
@@ -1,1 +0,1 @@ | ||
export declare function getSuccess<T>(fn: () => T): [true, T] | [false, undefined]; | ||
export declare function getSuccess<T>(fn: () => T): [succeeded: true, result: T] | [succeeded: false, result: undefined]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toOptionalAsync = exports.toOptionalAsyncPartial = void 0; | ||
const go_1 = require("@blackglory/go"); | ||
const async_optional_1 = require("../classes/async-optional"); | ||
@@ -10,3 +11,3 @@ function toOptionalAsyncPartial(isNone) { | ||
function toOptionalAsync(fn, isNone) { | ||
return new async_optional_1.AsyncOptional((async () => { | ||
const promise = go_1.go(async () => { | ||
const result = await fn(); | ||
@@ -16,5 +17,6 @@ if (isNone(result)) | ||
return result; | ||
})()); | ||
}); | ||
return new async_optional_1.AsyncOptional(promise); | ||
} | ||
exports.toOptionalAsync = toOptionalAsync; | ||
//# sourceMappingURL=to-optional-async.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toOptionalPromise = exports.toOptionalPromisePartial = void 0; | ||
const go_1 = require("@blackglory/go"); | ||
const async_optional_1 = require("../classes/async-optional"); | ||
@@ -10,3 +11,3 @@ function toOptionalPromisePartial(isNone) { | ||
function toOptionalPromise(promise, isNone) { | ||
return new async_optional_1.AsyncOptional((async () => { | ||
return new async_optional_1.AsyncOptional(go_1.go(async () => { | ||
const result = await promise; | ||
@@ -16,5 +17,5 @@ if (isNone(result)) | ||
return result; | ||
})()); | ||
})); | ||
} | ||
exports.toOptionalPromise = toOptionalPromise; | ||
//# sourceMappingURL=to-optional-promise.js.map |
{ | ||
"name": "return-style", | ||
"version": "0.12.2", | ||
"version": "0.12.3", | ||
"description": "Non-intrusively convert the result of any function or promise to the user's desired style.", | ||
@@ -58,14 +58,14 @@ "keywords": [ | ||
"devDependencies": { | ||
"@blackglory/jest-matchers": "^0.1.10", | ||
"@blackglory/types": "^0.2.18", | ||
"@commitlint/cli": "^12.0.0", | ||
"@commitlint/config-conventional": "^12.0.0", | ||
"@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.20", | ||
"@types/node": "^14.14.31", | ||
"@typescript-eslint/eslint-plugin": "^4.15.2", | ||
"@typescript-eslint/parser": "^4.15.2", | ||
"eslint": "^7.20.0", | ||
"@types/jest": "^26.0.21", | ||
"@types/node": "^14.14.35", | ||
"@typescript-eslint/eslint-plugin": "^4.18.0", | ||
"@typescript-eslint/parser": "^4.18.0", | ||
"eslint": "^7.22.0", | ||
"husky": "4", | ||
"iterable-operator": "^0.13.3", | ||
"iterable-operator": "^0.13.5", | ||
"jest": "^26.6.3", | ||
@@ -75,11 +75,14 @@ "jest-extended": "^0.11.5", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.39.1", | ||
"rollup": "^2.42.1", | ||
"rollup-plugin-analyzer": "^4.0.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"standard-version": "^9.1.1", | ||
"ts-jest": "^26.5.2", | ||
"ts-jest": "^26.5.4", | ||
"tscpaths": "^0.0.9", | ||
"tslib": "^2.1.0", | ||
"typescript": "^4.2.2" | ||
"typescript": "^4.2.3" | ||
}, | ||
"dependencies": { | ||
"@blackglory/go": "^0.1.0" | ||
} | ||
} |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
606343
5306
1
4
+ Added@blackglory/go@^0.1.0
+ Added@blackglory/go@0.1.1(transitive)