function e(e,t){return e===2?((...e)=>e.length>=2?t(e[0],e[1]):n=>t(n,e[0])):e===3?((...e)=>e.length>=3?t(e[0],e[1],e[2]):n=>t(n,e[0],e[1])):e===4?((...e)=>e.length>=4?t(e[0],e[1],e[2],e[3]):n=>t(n,e[0],e[1],e[2])):((...n)=>n.length>=e?t(...n):e=>t(e,...n))}var t=e=>e instanceof Error?{name:e.name,message:e.message,stack:e.stack}:e,n=class e extends Error{_tag=`Panic`;static is(t){return t instanceof e}constructor(e){if(super(e.message,e.cause===void 0?void 0:{cause:e.cause}),Object.assign(this,e),Object.setPrototypeOf(this,new.target.prototype),this.name=`Panic`,e.cause instanceof Error&&e.cause.stack){let t=e.cause.stack.replace(/\n/g,`
  `);this.stack=`${this.stack}\nCaused by: ${t}`}}toJSON(){return{...this,_tag:this._tag,name:this.name,message:this.message,cause:t(this.cause),stack:this.stack}}*[Symbol.iterator](){return yield*u(this),r(`Unreachable: Err yielded in Panic but generator continued`,this)}},r=(e,t)=>{throw new n({message:e,cause:t})},i=(e,t)=>{try{return e()}catch(e){throw r(t,e)}},a=async(e,t)=>{try{return await e()}catch(e){throw r(t,e)}},o=class e{status=`ok`;constructor(e){this.value=e}isOk(){return!0}isErr(){return!1}map(t){return i(()=>new e(t(this.value)),`map callback threw`)}mapError(e){return this}tryRecover(e){return this}tryRecoverAsync(e){return Promise.resolve(this)}andThen(e){return i(()=>e(this.value),`andThen callback threw`)}andThenAsync(e){return a(()=>e(this.value),`andThenAsync callback threw`)}match(e){return i(()=>e.ok(this.value),`match ok handler threw`)}unwrap(e){return this.value}unwrapOr(e){return this.value}tap(e){return i(()=>(e(this.value),this),`tap callback threw`)}tapAsync(e){return a(async()=>(await e(this.value),this),`tapAsync callback threw`)}tapError(e){return this}tapErrorAsync(e){return Promise.resolve(this)}tapBoth(e){return i(()=>(e.ok(this.value),this),`tapBoth ok callback threw`)}tapBothAsync(e){return a(async()=>(await e.ok(this.value),this),`tapBothAsync ok callback threw`)}*[Symbol.iterator](){return this.value}},s=class e{status=`error`;constructor(e){this.error=e}isOk(){return!1}isErr(){return!0}map(e){return this}mapError(t){return i(()=>new e(t(this.error)),`mapError callback threw`)}tryRecover(e){return i(()=>e(this.error),`tryRecover callback threw`)}tryRecoverAsync(e){return a(()=>e(this.error),`tryRecoverAsync callback threw`)}andThen(e){return this}andThenAsync(e){return Promise.resolve(this)}match(e){return i(()=>e.err(this.error),`match err handler threw`)}unwrap(e){return r(e??`Unwrap called on Err: ${String(this.error)}`,this.error)}unwrapOr(e){return e}tap(e){return this}tapError(e){return i(()=>(e(this.error),this),`tapError callback threw`)}tapAsync(e){return Promise.resolve(this)}tapErrorAsync(e){return a(async()=>(await e(this.error),this),`tapErrorAsync callback threw`)}tapBoth(e){return i(()=>(e.err(this.error),this),`tapBoth err callback threw`)}tapBothAsync(e){return a(async()=>(await e.err(this.error),this),`tapBothAsync err callback threw`)}*[Symbol.iterator](){return yield this,r(`Unreachable: Err yielded in Result.gen but generator continued`,this.error)}};function c(e){return new o(e)}var l=e=>e.status===`ok`,u=e=>new s(e),d=e=>e.status===`error`,f=e=>e instanceof Error?{name:e.name,message:e.message,stack:e.stack}:e,p=Object.assign(e=>()=>{class t extends Error{_tag=e;static is(e){return e instanceof t}constructor(t){let n=t&&`message`in t&&typeof t.message==`string`?t.message:void 0,r=t&&`cause`in t?t.cause:void 0;if(super(n,r===void 0?void 0:{cause:r}),t&&Object.assign(this,t),Object.setPrototypeOf(this,new.target.prototype),this.name=e,r instanceof Error&&r.stack){let e=r.stack.replace(/\n/g,`
  `);this.stack=`${this.stack}\nCaused by: ${e}`}}toJSON(){return{...this,_tag:this._tag,name:this.name,message:this.message,cause:f(this.cause),stack:this.stack}}*[Symbol.iterator](){return yield*u(this),r(`Unreachable: Err yielded in TaggedError but generator continued`,this)}}return t},{is:e=>e instanceof Error&&`_tag`in e&&typeof e._tag==`string`}),m=class extends p(`UnhandledException`)(){constructor(e){let t=e.cause instanceof Error?`Unhandled exception: ${e.cause.message}`:`Unhandled exception: ${String(e.cause)}`;super({message:t,cause:e.cause})}},h=class extends p(`ResultDeserializationError`)(){constructor(e){super({message:`Failed to deserialize value as Result: expected { status: "ok", value } or { status: "error", error }`,value:e.value})}},g=(e,t)=>{try{return e()}catch(e){throw r(t,e)}},_=(e,t)=>{let n=()=>{if(typeof e==`function`)try{return c(e())}catch(e){return u(new m({cause:e}))}try{return c(e.try())}catch(t){try{return u(e.catch(t))}catch(e){throw r(`Result.try catch handler threw`,e)}}},i=t?.retry?.times??0,a=n();for(let e=0;e<i&&a.status===`error`;e++)a=n();return a},v=async(e,t)=>{let n=async()=>{if(typeof e==`function`)try{return c(await e())}catch(e){return u(new m({cause:e}))}try{return c(await e.try())}catch(t){try{return u(await e.catch(t))}catch(e){throw r(`Result.tryPromise catch handler threw`,e)}}},i=t?.retry;if(!i)return n();let a=e=>{switch(i.backoff){case`constant`:return i.delayMs;case`linear`:return i.delayMs*(e+1);case`exponential`:return i.delayMs*2**e}},o=e=>new Promise(t=>setTimeout(t,e)),s=await n(),l=i.shouldRetry??(()=>!0);for(let e=0;e<i.times&&s.status===`error`;e++){let t=s.error;if(!g(()=>l(t),`shouldRetry predicate threw`))break;await o(a(e)),s=await n()}return s},y=e(2,(e,t)=>e.map(t)),b=e(2,(e,t)=>e.mapError(t)),x=e(2,(e,t)=>e.tryRecover(t)),S=e(2,(e,t)=>e.andThen(t)),C=e(2,(e,t)=>e.tryRecoverAsync(t)),w=e(2,(e,t)=>e.andThenAsync(t)),T=e(2,(e,t)=>e.match(t)),E=e(2,(e,t)=>e.tap(t)),D=e(2,(e,t)=>e.tapAsync(t)),O=e(2,(e,t)=>e.tapError(t)),k=e(2,(e,t)=>e.tapErrorAsync(t)),A=e(2,(e,t)=>e.tapBoth(t)),j=e(2,(e,t)=>e.tapBothAsync(t)),M=(e,t)=>e.unwrap(t);function N(e){if(!(typeof e==`object`&&e&&`status`in e&&(e.status===`ok`||e.status===`error`)))return r(`Result.gen body must return Result.ok() or Result.err(), got: `+(e===null?`null`:typeof e==`object`?JSON.stringify(e):String(e)))}var P=e(2,(e,t)=>e.unwrapOr(t)),F=((e,t)=>{let n=e.call(t);if(Symbol.asyncIterator in n)return(async()=>{let e=n,t;try{t=await e.next()}catch(e){throw r(`generator body threw`,e)}if(N(t.value),!t.done)try{await e.return?.(void 0)}catch(e){throw r(`generator cleanup threw`,e)}return t.value})();let i=n,a;try{a=i.next()}catch(e){throw r(`generator body threw`,e)}if(N(a.value),!a.done)try{i.return?.(void 0)}catch(e){throw r(`generator cleanup threw`,e)}return a.value});async function*I(e){return yield*await e}function L(e){return typeof e==`object`&&!!e&&`status`in e&&(e.status===`ok`&&`value`in e||e.status===`error`&&`error`in e)}var R=e=>e.status===`ok`?{status:`ok`,value:e.value}:{status:`error`,error:e.error},z=e=>L(e)?e.status===`ok`?new o(e.value):new s(e.error):u(new h({value:e})),B={ok:c,isOk:l,err:u,isError:d,try:_,tryPromise:v,map:y,mapError:b,tryRecover:x,andThen:S,tryRecoverAsync:C,andThenAsync:w,match:T,tap:E,tapAsync:D,tapError:O,tapErrorAsync:k,tapBoth:A,tapBothAsync:j,unwrap:M,unwrapOr:P,gen:F,await:I,serialize:R,deserialize:z,hydrate:e=>z(e),partition:e=>{let t=[],n=[];for(let r of e)r.status===`ok`?t.push(r.value):n.push(r.error);return[t,n]},flatten:e=>e.status===`ok`?e.value:e};export{p as n,B as t};