functype 0.46.0 → 0.46.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import{Brand as e}from"./branded/index.js";import{n as t,t as n}from"./Companion-VlxcFhzb.js";import{None as r,Option as i,Some as a}from"./option/index.js";import{Try as o}from"./try/index.js";import{List as s}from"./list/index.js";import{Left as c,Right as l}from"./either/index.js";import u from"safe-stable-stringify";const d=e=>{let t=Error(e);return t.name=`ParseError`,t},ee=(e,t)=>({toJSON:()=>JSON.stringify({_tag:e,value:t}),toYAML:()=>`_tag: ${e}\nvalue: ${u(t)}`,toBinary:()=>Buffer.from(JSON.stringify({_tag:e,value:t})).toString(`base64`)}),te=e=>({toJSON:()=>JSON.stringify(e),toYAML:()=>Object.entries(e).map(([e,t])=>`${e}: ${u(t)}`).join(`
2
2
  `),toBinary:()=>Buffer.from(JSON.stringify(e)).toString(`base64`)}),ne=(e,t)=>t(JSON.parse(e)),re=(e,t)=>{let n=e.split(`
3
- `),r={};for(let e of n){let t=e.indexOf(`: `);if(t===-1)continue;let n=e.substring(0,t),i=e.substring(t+2);if(!i){r[n]=null;continue}try{r[n]=i===`null`?null:JSON.parse(i)}catch{r[n]=i}}return t(r)},ie=(e,t)=>ne(Buffer.from(e,`base64`).toString(),t),ae=e=>({fromJSON:t=>ne(t,e),fromYAML:t=>re(t,e),fromBinary:t=>ie(t,e)}),oe=Set,se=e=>{let t=e;return{get(){return t},set(e){t=e},update(e){t=e(t)},getAndSet(e){let n=t;return t=e,n},updateAndGet(e){return t=e(t),t},getAndUpdate(e){let n=t;return t=e(t),n},compareAndSet(e,n){return t===e?(t=n,!0):!1},modify(e){let[n,r]=e(t);return t=n,r}}},f=n(se,{of:e=>se(e)}),p=(e=0)=>{let t=f(e),n=e;return{get:()=>t.get(),set:e=>t.set(e),increment:()=>t.updateAndGet(e=>e+1),decrement:()=>t.updateAndGet(e=>e-1),reset:()=>t.set(n),compareAndSet:(e,n)=>t.compareAndSet(e,n)}},ce=()=>{let e=f([]);return{add:t=>e.update(e=>[...e,t]),addAll:t=>e.update(e=>[...e,...t]),build:()=>e.get(),clear:()=>e.set([]),size:()=>e.get().length}},m=e=>{let t={_tag:`LazyList`,[Symbol.iterator]:()=>e[Symbol.iterator](),map:t=>m((function*(){for(let n of e)yield t(n)})()),flatMap:t=>m((function*(){for(let n of e)yield*t(n)})()),filter:t=>m((function*(){for(let n of e)t(n)&&(yield n)})()),take:t=>m((function*(){let n=p(0);for(let r of e){if(n.get()>=t)break;yield r,n.increment()}})()),drop:t=>m((function*(){let n=p(0);for(let r of e)n.get()>=t&&(yield r),n.increment()})()),takeWhile:t=>m((function*(){for(let n of e){if(!t(n))break;yield n}})()),dropWhile:t=>m((function*(){let n=f(!0);for(let r of e)n.get()&&t(r)||(n.set(!1),yield r)})()),concat:t=>m((function*(){yield*e,yield*t})()),zip:t=>m((function*(){let n=e[Symbol.iterator](),r=t[Symbol.iterator]();for(;;){let e=n.next(),t=r.next();if(e.done||t.done)break;yield[e.value,t.value]}})()),toList:()=>s(Array.from(e)),toArray:()=>Array.from(e),forEach:t=>{for(let n of e)t(n)},reduce:(t,n)=>{let r=f(n);for(let n of e)r.set(t(r.get(),n));return r.get()},find:t=>{for(let n of e)if(t(n))return i(n);return i.none()},some:t=>{for(let n of e)if(t(n))return!0;return!1},every:t=>{for(let n of e)if(!t(n))return!1;return!0},count:()=>{let t=p(0);for(let n of e)t.increment();return t.get()},get head(){let t=e[Symbol.iterator]().next();return t.done?void 0:t.value},get headOption(){let t=e[Symbol.iterator]().next();return t.done?i.none():i(t.value)},get last(){let t;for(let n of e)t=n;return t},get lastOption(){let t=f(void 0),n=f(!1);for(let r of e)t.set(r),n.set(!0);return n.get()?i(t.get()):i.none()},get tail(){return m((function*(){let t=e[Symbol.iterator]();t.next();let n=t.next();for(;!n.done;)yield n.value,n=t.next()})())},get init(){let t=Array.from(e);return m(t.length===0?[]:t.slice(0,-1))},takeRight:t=>{let n=Array.from(e);return m(t<=0?[]:n.slice(-t))},reverse:()=>m(Array.from(e).reverse()),distinct:()=>m((function*(){let t=new globalThis.Set;for(let n of e)t.has(n)||(t.add(n),yield n)})()),zipWithIndex:()=>m((function*(){let t=p(0);for(let n of e)yield[n,t.get()],t.increment()})()),fold:(t,n)=>{let r=e[Symbol.iterator]().next();return r.done?t():n(r.value)},foldLeft:t=>n=>{let r=f(t);for(let t of e)r.set(n(r.get(),t));return r.get()},foldRight:t=>n=>Array.from(e).reduceRight((e,t)=>n(t,e),t),pipe:e=>e(t),serialize:()=>{let t=Array.from(e);return{toJSON:()=>JSON.stringify({_tag:`LazyList`,value:t}),toYAML:()=>`_tag: LazyList\nvalue: ${u(t)}`,toBinary:()=>Buffer.from(JSON.stringify({_tag:`LazyList`,value:t})).toString(`base64`)}},toString:()=>{let t=[],n=p(0),r=f(!1);for(let i of e)if(n.get()<10)t.push(i),n.increment();else{r.set(!0);break}let i=t.map(e=>String(e)).join(`, `);return r.get()?`LazyList(${i}, ...)`:`LazyList(${i})`}};return t},le=n(e=>m(e),{empty:()=>m([]),of:e=>m([e]),from:(...e)=>m(e),iterate:(e,t)=>m((function*(){let n=f(e);for(;;)yield n.get(),n.set(t(n.get()))})()),generate:e=>m((function*(){for(;;)yield e()})()),range:(e,t,n=1)=>m((function*(){if(n===0)throw Error(`Step cannot be zero`);let r=f(e);if(n>0)for(;r.get()<t;)yield r.get(),r.set(r.get()+n);else for(;r.get()>t;)yield r.get(),r.set(r.get()+n)})()),repeat:(e,t)=>m((function*(){if(t===void 0)for(;;)yield e;else{let n=p(0);for(;n.get()<t;)yield e,n.increment()}})()),cycle:e=>m((function*(){let t=Array.from(e);if(t.length!==0)for(;;)yield*t})())});function ue({_tag:e,impl:t}){return{...t,_tag:e}}function de(e,t){return!e||typeof e!=`object`||!(`_tag`in e)?!1:t?e._tag===t:!0}function h(t,n){return{brand:t,validate:n,of:r=>n(r)?i(e(t,r)):i.none(),from:r=>n(r)?l(e(t,r)):c(`Invalid ${t}: validation failed`),unsafeOf:r=>{if(!n(r))throw Error(`Invalid ${t}: validation failed`);return e(t,r)},is:e=>{try{return n(e)}catch{return!1}},unwrap:e=>e,refine:(e,t)=>h(e,e=>n(e)&&t(e))}}const fe=h(`PositiveNumber`,e=>e>0),pe=h(`NonNegativeNumber`,e=>e>=0),me=h(`IntegerNumber`,e=>Number.isInteger(e)),he=fe.refine(`PositiveInteger`,e=>Number.isInteger(e)),ge=h(`NonEmptyString`,e=>e.length>0),_e=h(`EmailAddress`,e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)),ve=h(`UrlString`,e=>{try{return new URL(e),!0}catch{return!1}}),ye=h(`UUID`,e=>/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e)),be=h(`ISO8601Date`,e=>!isNaN(Date.parse(e))&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(e));function xe(e,t,n){return h(e,e=>e>=t&&e<=n)}function Se(e,t,n){return h(e,e=>e.length>=t&&e.length<=n)}function Ce(e,t){return h(e,e=>t.test(e))}const we=e=>typeof e==`function`&&Object.keys(e).length>0,Te=e=>{let t=e=>typeof e==`function`?e():e,n={when:(r,i)=>e.resolved?n:r?Te({resolved:!0,value:t(i)}):n,elseWhen:(r,i)=>e.resolved?n:r?Te({resolved:!0,value:t(i)}):n,else:n=>e.resolved?e.value:t(n),orThrow:()=>{if(!e.resolved)throw Error(`Conditional expression has no matching condition`);return e.value}};return n},Ee=()=>Te({resolved:!1}),De=n(Ee,{of:()=>Ee(),match:e=>t=>{let n=t[e];if(n===void 0)throw Error(`No case defined for value: ${String(e)}`);return typeof n==`function`?n():n},lazy:()=>{let e={resolved:!1},t={when:(n,r)=>(e.resolved||n()&&(e.resolved=!0,e.value=r()),t),elseWhen:(n,r)=>(e.resolved||n()&&(e.resolved=!0,e.value=r()),t),else:t=>e.resolved?e.value:t()};return t}}),g=(e,t)=>t===e?!0:typeof t==`function`?t(e):t&&typeof t==`object`&&`_`in t?t._(e):typeof t==`object`&&t&&typeof e==`object`&&e?Object.entries(t).every(([t,n])=>{let r=e[t];return g(r,n)}):!1,_=e=>{let t=(e,t)=>typeof e==`function`?e(t):e,n=()=>{for(let{pattern:n,result:r}of e.patterns)if(g(e.value,n))return{matched:!0,result:t(r,e.value)};return{matched:!1}},r={case:(n,i)=>e.resolved?r:g(e.value,n)?_({value:e.value,resolved:!0,result:t(i,e.value),patterns:[]}):_({...e,patterns:[...e.patterns,{pattern:n,result:i}]}),caseValue:(t,n)=>{if(e.resolved)return r;if(e.value===t){let t=typeof n==`function`?n():n;return _({value:e.value,resolved:!0,result:t,patterns:[]})}return r},caseValues:(t,n)=>{if(e.resolved)return r;if(t.includes(e.value)){let t=typeof n==`function`?n():n;return _({value:e.value,resolved:!0,result:t,patterns:[]})}return r},when:(e,t)=>r.case(e,t),caseAny:(n,i)=>{if(e.resolved)return r;for(let r of n)if(g(e.value,r))return _({value:e.value,resolved:!0,result:t(i,e.value),patterns:[]});return _({...e,patterns:[...e.patterns,...n.map(e=>({pattern:e,result:i}))]})},default:n=>e.resolved?e.result:t(n,e.value),exhaustive:()=>{if(e.resolved)return e.result;let t=n();if(!t.matched)throw Error(`Non-exhaustive match. No pattern matched value: ${JSON.stringify(e.value)}`);return t.result},orThrow:t=>{if(e.resolved)return e.result;let r=n();if(!r.matched)throw Error(t??`No matching pattern for value: ${JSON.stringify(e.value)}`);return r.result},toOption:()=>{if(e.resolved)return i(e.result);let t=n();return t.matched?i(t.result):i.none()}};return r},Oe=e=>{let t=(e,t)=>typeof e==`function`?e(t):e;return{case:(n,r)=>{let i={value:e,resolved:!1,patterns:[{pattern:n,result:r}]};return g(e,n)?_({...i,resolved:!0,result:t(r,e)}):_(i)},caseValue:(t,n)=>_(e===t?{value:e,resolved:!0,result:typeof n==`function`?n():n,patterns:[]}:{value:e,resolved:!1,patterns:[]}),caseValues:(t,n)=>t.includes(e)?_({value:e,resolved:!0,result:typeof n==`function`?n():n,patterns:[]}):_({value:e,resolved:!1,patterns:[]}),when:(n,r)=>{let i={value:e,resolved:!1,patterns:[{pattern:n,result:r}]};return n(e)?_({...i,resolved:!0,result:t(r,e)}):_(i)},caseAny:(n,r)=>{for(let i of n)if(g(e,i))return _({value:e,resolved:!0,result:t(r,e),patterns:n.map(e=>({pattern:e,result:r}))});return _({value:e,resolved:!1,patterns:n.map(e=>({pattern:e,result:r}))})}}},ke=n(e=>Oe(e),{exhaustive:e=>t=>{let n=e[t];if(n===void 0)throw Error(`No case defined for value: ${String(t)}`);return n},partial:e=>({withDefault:t=>n=>{let r=e[n];return r===void 0?typeof t==`function`?t(n):t:typeof r==`function`?r(n):r}}),withGuards:e=>({withDefault:t=>n=>{for(let[t,r]of e)if(t(n))return typeof r==`function`?r(n):r;return typeof t==`function`?t(n):t}}),struct:()=>{let e=[],t={case:(n,r)=>(e.push({pattern:n,handler:r}),t),build:()=>t=>{for(let{pattern:n,handler:r}of e)if(g(t,n))return r(t);throw Error(`No matching pattern for value: ${JSON.stringify(t)}`)}};return t},builder:()=>{let e=[],t,n={case:(t,r)=>(e.push({pattern:t,result:r}),n),when:(t,r)=>(e.push({pattern:t,result:r}),n),default:n=>(t=n,{build:()=>n=>{for(let{pattern:t,result:r}of e)if(g(n,t))return typeof r==`function`?r(n):r;if(t!==void 0)return typeof t==`function`?t(n):t;throw Error(`No matching pattern for value: ${JSON.stringify(n)}`)}})};return n}});function v(e,t){return{...ue({_tag:e,impl:t}),toString(){return`${e}()`},doUnwrap(){if(`isSome`in t&&`isNone`in t){if(typeof t.isSome==`function`&&t.isSome()&&`get`in t&&typeof t.get==`function`)return{ok:!0,value:t.get()};if(typeof t.isNone==`function`&&t.isNone())return{ok:!1,empty:!0}}if(`isLeft`in t&&`isRight`in t){if(typeof t.isRight==`function`&&t.isRight()&&`value`in t)return{ok:!0,value:t.value};if(typeof t.isLeft==`function`&&t.isLeft()&&`value`in t)return{ok:!1,empty:!1,error:t.value}}if(`isSuccess`in t&&`isFailure`in t){if(typeof t.isSuccess==`function`&&t.isSuccess()&&`get`in t&&typeof t.get==`function`)return{ok:!0,value:t.get()};if(typeof t.isFailure==`function`&&t.isFailure()&&`getError`in t&&typeof t.getError==`function`)return{ok:!1,empty:!1,error:t.getError()}}if(`isEmpty`in t&&`head`in t){if(typeof t.isEmpty==`function`&&t.isEmpty())return{ok:!1,empty:!0};if(typeof t.head==`function`)return{ok:!0,value:t.head()};if(`head`in t)return{ok:!0,value:t.head}}return{ok:!0,value:t}}}}const y=`Throwable`;var b=class e extends Error{constructor(e,t){super(e,{cause:t?.cause}),this._tag=y,this.name=t?.taskInfo?.name??y,Object.defineProperties(this,{_tag:{value:y,writable:!1,configurable:!1},data:{value:t?.data,writable:!1,configurable:!1},taskInfo:{value:t?.taskInfo,writable:!1,configurable:!1},name:{value:t?.taskInfo?.name??y,writable:!1,configurable:!1}}),t?.cause&&Object.defineProperty(this,`cause`,{value:t.cause,writable:!1,configurable:!1}),t?.stack?this.stack=t.stack:Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}static apply(t,n,r){if(t instanceof Error){let i=new e(t.message,{data:n,cause:t.cause??void 0,stack:t.stack??void 0,taskInfo:r});for(let e of Object.keys(t))if(!(e in i)){let n=i;n[e]=t[e]}return i}if(t&&typeof t==`object`){let i=t,a=new e(typeof i.message==`string`?i.message:typeof i.error==`string`?i.error:`Object error: ${JSON.stringify(i,Object.getOwnPropertyNames(i).filter(e=>i[e]!==void 0))}`,{data:n??i,taskInfo:r});for(let e of Object.keys(i))if(!(e in a)){let t=a;t[e]=i[e]}return a}if(typeof t==`function`){let i=t.name??`anonymous function`,a=t.toString().substring(0,100)+(t.toString().length>100?`...`:``);return new e(`Function error: ${i}`,{data:n??{functionType:typeof t,functionName:i,functionString:a},taskInfo:r})}let i=typeof t,a=t===null?`null`:t===void 0?`undefined`:String(t);if(i===`number`){let a=t;return new e(Number.isNaN(a)?`Number error: NaN`:Number.isFinite(a)?`Number error: ${a}`:`Number error: ${a>0?`Infinity`:`-Infinity`}`,{data:n??{errorType:i,errorValue:a,originalError:t},taskInfo:r})}if(i===`bigint`)return new e(`BigInt error: ${t}n`,{data:n??{errorType:i,errorValue:String(t),originalError:t},taskInfo:r});if(i===`boolean`)return new e(`Boolean error: ${t}`,{data:n??{errorType:i,errorValue:t,originalError:t},taskInfo:r});if(i===`symbol`){let a=t.description??`unnamed symbol`;return new e(`Symbol error: Symbol(${a})`,{data:n??{errorType:i,symbolDescription:a,originalError:t},taskInfo:r})}return new e(typeof t==`string`?t:`${i.charAt(0).toUpperCase()+i.slice(1)} error: ${a}`,{data:n??{errorType:i,errorValue:a,originalError:t},taskInfo:r})}};function Ae(e){return e instanceof Error&&typeof e==`object`&&e._tag===`Throwable`}const je=(e,t)=>{if(e.isRight())return S(e.orThrow(),t);if(e.isLeft())return x(e.fold(e=>e,()=>Error(`Unexpected right value`)),void 0,t);throw Error(`Unrecognized task outcome`)},x=(e,t,n)=>{let i={name:n?.name??`Task`,description:n?.description??``},a=b.apply(e,t,i),l={...v(`Err`,{error:a,meta:i}),_tag:`Err`,_meta:i,value:void 0,error:a,isSuccess(){return!1},isFailure(){return!0},isOk(){return!1},isErr(){return!0},map:e=>x(a,t,n),flatMap:e=>x(a,t,n),ap:e=>x(a,t,n),mapAsync:e=>Promise.resolve(x(a,t,n)),flatMapAsync:e=>Promise.resolve(x(a,t,n)),mapError:e=>x(e(a),t,n),recover:e=>S(e,n),recoverWith:e=>S(e(a),n),orThrow:e=>{throw e??a},orElse:e=>e,or:e=>e,orNull:()=>null,orUndefined:()=>void 0,toEither:()=>c(a),toTry:()=>o(()=>{throw a}),toOption:()=>r(),toList:()=>s([]),fold:(e,t)=>e(a),match:e=>e.Err(a),foldLeft:e=>t=>e,foldRight:e=>t=>e,size:0,isEmpty:!0,contains:e=>!1,reduce:e=>{throw Error(`Cannot reduce empty Err`)},reduceRight:e=>{throw Error(`Cannot reduceRight empty Err`)},count:e=>0,find:e=>r(),exists:e=>!1,forEach:e=>{},toPromise:()=>Promise.reject(a),doUnwrap(){return{ok:!1,empty:!1,error:a}},serialize:()=>({toJSON:()=>u({_tag:`Err`,error:a.message??a.toString()})??`{}`,toYAML:()=>`_tag: Err\nerror: ${a.message??a.toString()}`,toBinary:()=>Buffer.from(JSON.stringify({_tag:`Err`,error:a.message??a.toString()})).toString(`base64`)}),pipe:e=>e(l)};return l},S=(e,t)=>{let n={name:t?.name??`Task`,description:t?.description??``},i={...v(`Ok`,{value:e,meta:n}),_tag:`Ok`,_meta:n,value:e,error:void 0,isSuccess(){return!0},isFailure(){return!1},isOk(){return!0},isErr(){return!1},map:n=>S(n(e),t),flatMap:n=>{let r=n(e);return r&&typeof r==`object`&&`isLeft`in r&&`isRight`in r?je(r,t):r},ap:n=>n.isOk()?S(n.value(e),t):x(n.error,void 0,t),mapAsync:async n=>S(await n(e),t),flatMapAsync:async t=>await t(e),mapError:n=>S(e,t),recover:n=>S(e,t),recoverWith:n=>S(e,t),orThrow:t=>e,orElse:t=>e,or:n=>S(e,t),orNull:()=>e,orUndefined:()=>e,toEither:()=>l(e),toTry:()=>o(()=>e),toOption:()=>a(e),toList:()=>s([e]),fold:(t,n)=>n(e),match:t=>t.Ok(e),foldLeft:t=>n=>n(t,e),foldRight:t=>n=>n(e,t),size:1,isEmpty:!1,contains:t=>e===t,reduce:t=>e,reduceRight:t=>e,count:t=>t(e)?1:0,find:t=>t(e)?a(e):r(),exists:t=>t(e),forEach:t=>t(e),toPromise:()=>Promise.resolve(e),doUnwrap(){return{ok:!0,value:e}},serialize:()=>({toJSON:()=>u({_tag:`Ok`,value:e})??`{}`,toYAML:()=>`_tag: Ok\nvalue: ${u(e)??`undefined`}`,toBinary:()=>Buffer.from(JSON.stringify({_tag:`Ok`,value:e})).toString(`base64`)}),pipe:e=>e(i)};return i},C=()=>{let e=new AbortController,t=ce();return{token:{get isCancelled(){return e.signal.aborted},get signal(){return e.signal},onCancel(n){e.signal.aborted?n():t.add(n)}},cancel(){e.signal.aborted||(e.abort(),t.build().forEach(e=>{try{e()}catch(e){console.error(`Error in cancellation callback:`,e)}}))}}},Me=e=>{let t=e?.name??`Task`,n=e?.description??``,r={Async:(e,r=e=>e,i=()=>{},a)=>new Promise(o=>{(async()=>{let s=f(!1),c=f(null),l=f(()=>{});if(a){if(a.isCancelled){try{await i()}catch(e){o(x(e,void 0,{name:t,description:n}));return}o(x(Error(`Task was cancelled before execution started`),void 0,{name:t,description:n}));return}a.onCancel(()=>{s.set(!0),c.set(Error(`Task was cancelled during execution`))}),l.set(()=>{})}try{let r=await e();try{await i()}catch(e){o(x(e,void 0,{name:t,description:n}));return}if(s.get()){c.get()?o(x(c.get(),void 0,{name:t,description:n})):o(x(Error(`Task was cancelled during execution`),void 0,{name:t,description:n}));return}if(r&&typeof r==`object`&&`_tag`in r){let e=r;e._tag===`Ok`||e._tag===`Err`?o(e):o(S(r,{name:t,description:n}))}else o(S(r,{name:t,description:n}))}catch(e){try{await i()}catch(e){o(x(e,void 0,{name:t,description:n}));return}if(s.get()){c.get()?o(x(c.get(),void 0,{name:t,description:n})):o(x(Error(`Task was cancelled during execution`),void 0,{name:t,description:n}));return}try{if(e instanceof Error&&Ae(e)){let i=Error(`${t}: ${e.message}`),a=b.apply(i,void 0,{name:t,description:n});Object.defineProperty(a,`cause`,{value:e,writable:!1,configurable:!1}),Promise.resolve().then(()=>{try{r(e)}catch(e){console.error(`Error in error handler:`,e)}}),o(x(a,void 0,{name:t,description:n}))}else{let i=await r(e);if(i&&typeof i==`object`&&`_tag`in i){let e=i;e._tag===`Ok`||e._tag===`Err`?o(e):o(x(i,void 0,{name:t,description:n}))}else o(x(i,void 0,{name:t,description:n}))}}catch(e){o(x(e,void 0,{name:t,description:n}))}}finally{l.get()()}})().catch(e=>o(x(e,void 0,{name:t,description:n})))}),Sync:(e,r=e=>e,i=()=>{})=>{try{return S(e(),{name:t,description:n})}catch(e){return x(r(e),void 0,{name:t,description:n})}finally{i()}},AsyncWithProgress:(e,t,n=e=>e,i=()=>{},a)=>{let o=e=>{let n=Math.max(0,Math.min(100,e));n<=100&&t(n)};return r.Async(()=>e(o),n,i,a)}};return{...v(`Task`,r),_type:`Task`}},Ne={success:(e,t)=>S(e,t),fail:(e,t,n)=>x(e,t,n),ok:(e,t)=>S(e,t),err:(e,t,n)=>x(e,t,n),fromEither:(e,t)=>je(e,t),fromTry:(e,t)=>e.isSuccess()?S(e.orThrow(),t):x(e.fold(e=>e,()=>Error(`Unexpected success`)),void 0,t),getErrorChain:e=>{if(!e)return[];let t=ce();t.add(e);let n=f(e);for(;n.get()&&n.get().cause;){let{cause:e}=n.get();if(e)t.add(e),n.set(e);else break;if(t.size()>100)break}return t.build()},formatErrorChain:(e,t)=>{let n=Ne.getErrorChain(e),r=t?.separator??`
3
+ `),r={};for(let e of n){let t=e.indexOf(`: `);if(t===-1)continue;let n=e.substring(0,t),i=e.substring(t+2);if(!i){r[n]=null;continue}try{r[n]=i===`null`?null:JSON.parse(i)}catch{r[n]=i}}return t(r)},ie=(e,t)=>ne(Buffer.from(e,`base64`).toString(),t),ae=e=>({fromJSON:t=>ne(t,e),fromYAML:t=>re(t,e),fromBinary:t=>ie(t,e)}),oe=globalThis.Set,se=e=>{let t=e;return{get(){return t},set(e){t=e},update(e){t=e(t)},getAndSet(e){let n=t;return t=e,n},updateAndGet(e){return t=e(t),t},getAndUpdate(e){let n=t;return t=e(t),n},compareAndSet(e,n){return t===e?(t=n,!0):!1},modify(e){let[n,r]=e(t);return t=n,r}}},f=n(se,{of:e=>se(e)}),p=(e=0)=>{let t=f(e),n=e;return{get:()=>t.get(),set:e=>t.set(e),increment:()=>t.updateAndGet(e=>e+1),decrement:()=>t.updateAndGet(e=>e-1),reset:()=>t.set(n),compareAndSet:(e,n)=>t.compareAndSet(e,n)}},ce=()=>{let e=f([]);return{add:t=>e.update(e=>[...e,t]),addAll:t=>e.update(e=>[...e,...t]),build:()=>e.get(),clear:()=>e.set([]),size:()=>e.get().length}},m=e=>{let t={_tag:`LazyList`,[Symbol.iterator]:()=>e[Symbol.iterator](),map:t=>m((function*(){for(let n of e)yield t(n)})()),flatMap:t=>m((function*(){for(let n of e)yield*t(n)})()),filter:t=>m((function*(){for(let n of e)t(n)&&(yield n)})()),take:t=>m((function*(){let n=p(0);for(let r of e){if(n.get()>=t)break;yield r,n.increment()}})()),drop:t=>m((function*(){let n=p(0);for(let r of e)n.get()>=t&&(yield r),n.increment()})()),takeWhile:t=>m((function*(){for(let n of e){if(!t(n))break;yield n}})()),dropWhile:t=>m((function*(){let n=f(!0);for(let r of e)n.get()&&t(r)||(n.set(!1),yield r)})()),concat:t=>m((function*(){yield*e,yield*t})()),zip:t=>m((function*(){let n=e[Symbol.iterator](),r=t[Symbol.iterator]();for(;;){let e=n.next(),t=r.next();if(e.done||t.done)break;yield[e.value,t.value]}})()),toList:()=>s(Array.from(e)),toArray:()=>Array.from(e),forEach:t=>{for(let n of e)t(n)},reduce:(t,n)=>{let r=f(n);for(let n of e)r.set(t(r.get(),n));return r.get()},find:t=>{for(let n of e)if(t(n))return i(n);return i.none()},some:t=>{for(let n of e)if(t(n))return!0;return!1},every:t=>{for(let n of e)if(!t(n))return!1;return!0},count:()=>{let t=p(0);for(let n of e)t.increment();return t.get()},get head(){let t=e[Symbol.iterator]().next();return t.done?void 0:t.value},get headOption(){let t=e[Symbol.iterator]().next();return t.done?i.none():i(t.value)},get last(){let t;for(let n of e)t=n;return t},get lastOption(){let t=f(void 0),n=f(!1);for(let r of e)t.set(r),n.set(!0);return n.get()?i(t.get()):i.none()},get tail(){return m((function*(){let t=e[Symbol.iterator]();t.next();let n=t.next();for(;!n.done;)yield n.value,n=t.next()})())},get init(){let t=Array.from(e);return m(t.length===0?[]:t.slice(0,-1))},takeRight:t=>{let n=Array.from(e);return m(t<=0?[]:n.slice(-t))},reverse:()=>m(Array.from(e).reverse()),distinct:()=>m((function*(){let t=new globalThis.Set;for(let n of e)t.has(n)||(t.add(n),yield n)})()),zipWithIndex:()=>m((function*(){let t=p(0);for(let n of e)yield[n,t.get()],t.increment()})()),fold:(t,n)=>{let r=e[Symbol.iterator]().next();return r.done?t():n(r.value)},foldLeft:t=>n=>{let r=f(t);for(let t of e)r.set(n(r.get(),t));return r.get()},foldRight:t=>n=>Array.from(e).reduceRight((e,t)=>n(t,e),t),pipe:e=>e(t),serialize:()=>{let t=Array.from(e);return{toJSON:()=>JSON.stringify({_tag:`LazyList`,value:t}),toYAML:()=>`_tag: LazyList\nvalue: ${u(t)}`,toBinary:()=>Buffer.from(JSON.stringify({_tag:`LazyList`,value:t})).toString(`base64`)}},toString:()=>{let t=[],n=p(0),r=f(!1);for(let i of e)if(n.get()<10)t.push(i),n.increment();else{r.set(!0);break}let i=t.map(e=>String(e)).join(`, `);return r.get()?`LazyList(${i}, ...)`:`LazyList(${i})`}};return t},le=n(e=>m(e),{empty:()=>m([]),of:e=>m([e]),from:(...e)=>m(e),iterate:(e,t)=>m((function*(){let n=f(e);for(;;)yield n.get(),n.set(t(n.get()))})()),generate:e=>m((function*(){for(;;)yield e()})()),range:(e,t,n=1)=>m((function*(){if(n===0)throw Error(`Step cannot be zero`);let r=f(e);if(n>0)for(;r.get()<t;)yield r.get(),r.set(r.get()+n);else for(;r.get()>t;)yield r.get(),r.set(r.get()+n)})()),repeat:(e,t)=>m((function*(){if(t===void 0)for(;;)yield e;else{let n=p(0);for(;n.get()<t;)yield e,n.increment()}})()),cycle:e=>m((function*(){let t=Array.from(e);if(t.length!==0)for(;;)yield*t})())});function ue({_tag:e,impl:t}){return{...t,_tag:e}}function de(e,t){return!e||typeof e!=`object`||!(`_tag`in e)?!1:t?e._tag===t:!0}function h(t,n){return{brand:t,validate:n,of:r=>n(r)?i(e(t,r)):i.none(),from:r=>n(r)?l(e(t,r)):c(`Invalid ${t}: validation failed`),unsafeOf:r=>{if(!n(r))throw Error(`Invalid ${t}: validation failed`);return e(t,r)},is:e=>{try{return n(e)}catch{return!1}},unwrap:e=>e,refine:(e,t)=>h(e,e=>n(e)&&t(e))}}const fe=h(`PositiveNumber`,e=>e>0),pe=h(`NonNegativeNumber`,e=>e>=0),me=h(`IntegerNumber`,e=>Number.isInteger(e)),he=fe.refine(`PositiveInteger`,e=>Number.isInteger(e)),ge=h(`NonEmptyString`,e=>e.length>0),_e=h(`EmailAddress`,e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)),ve=h(`UrlString`,e=>{try{return new URL(e),!0}catch{return!1}}),ye=h(`UUID`,e=>/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e)),be=h(`ISO8601Date`,e=>!isNaN(Date.parse(e))&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(e));function xe(e,t,n){return h(e,e=>e>=t&&e<=n)}function Se(e,t,n){return h(e,e=>e.length>=t&&e.length<=n)}function Ce(e,t){return h(e,e=>t.test(e))}const we=e=>typeof e==`function`&&Object.keys(e).length>0,Te=e=>{let t=e=>typeof e==`function`?e():e,n={when:(r,i)=>e.resolved?n:r?Te({resolved:!0,value:t(i)}):n,elseWhen:(r,i)=>e.resolved?n:r?Te({resolved:!0,value:t(i)}):n,else:n=>e.resolved?e.value:t(n),orThrow:()=>{if(!e.resolved)throw Error(`Conditional expression has no matching condition`);return e.value}};return n},Ee=()=>Te({resolved:!1}),De=n(Ee,{of:()=>Ee(),match:e=>t=>{let n=t[e];if(n===void 0)throw Error(`No case defined for value: ${String(e)}`);return typeof n==`function`?n():n},lazy:()=>{let e={resolved:!1},t={when:(n,r)=>(e.resolved||n()&&(e.resolved=!0,e.value=r()),t),elseWhen:(n,r)=>(e.resolved||n()&&(e.resolved=!0,e.value=r()),t),else:t=>e.resolved?e.value:t()};return t}}),g=(e,t)=>t===e?!0:typeof t==`function`?t(e):t&&typeof t==`object`&&`_`in t?t._(e):typeof t==`object`&&t&&typeof e==`object`&&e?Object.entries(t).every(([t,n])=>{let r=e[t];return g(r,n)}):!1,_=e=>{let t=(e,t)=>typeof e==`function`?e(t):e,n=()=>{for(let{pattern:n,result:r}of e.patterns)if(g(e.value,n))return{matched:!0,result:t(r,e.value)};return{matched:!1}},r={case:(n,i)=>e.resolved?r:g(e.value,n)?_({value:e.value,resolved:!0,result:t(i,e.value),patterns:[]}):_({...e,patterns:[...e.patterns,{pattern:n,result:i}]}),caseValue:(t,n)=>{if(e.resolved)return r;if(e.value===t){let t=typeof n==`function`?n():n;return _({value:e.value,resolved:!0,result:t,patterns:[]})}return r},caseValues:(t,n)=>{if(e.resolved)return r;if(t.includes(e.value)){let t=typeof n==`function`?n():n;return _({value:e.value,resolved:!0,result:t,patterns:[]})}return r},when:(e,t)=>r.case(e,t),caseAny:(n,i)=>{if(e.resolved)return r;for(let r of n)if(g(e.value,r))return _({value:e.value,resolved:!0,result:t(i,e.value),patterns:[]});return _({...e,patterns:[...e.patterns,...n.map(e=>({pattern:e,result:i}))]})},default:n=>e.resolved?e.result:t(n,e.value),exhaustive:()=>{if(e.resolved)return e.result;let t=n();if(!t.matched)throw Error(`Non-exhaustive match. No pattern matched value: ${JSON.stringify(e.value)}`);return t.result},orThrow:t=>{if(e.resolved)return e.result;let r=n();if(!r.matched)throw Error(t??`No matching pattern for value: ${JSON.stringify(e.value)}`);return r.result},toOption:()=>{if(e.resolved)return i(e.result);let t=n();return t.matched?i(t.result):i.none()}};return r},Oe=e=>{let t=(e,t)=>typeof e==`function`?e(t):e;return{case:(n,r)=>{let i={value:e,resolved:!1,patterns:[{pattern:n,result:r}]};return g(e,n)?_({...i,resolved:!0,result:t(r,e)}):_(i)},caseValue:(t,n)=>_(e===t?{value:e,resolved:!0,result:typeof n==`function`?n():n,patterns:[]}:{value:e,resolved:!1,patterns:[]}),caseValues:(t,n)=>t.includes(e)?_({value:e,resolved:!0,result:typeof n==`function`?n():n,patterns:[]}):_({value:e,resolved:!1,patterns:[]}),when:(n,r)=>{let i={value:e,resolved:!1,patterns:[{pattern:n,result:r}]};return n(e)?_({...i,resolved:!0,result:t(r,e)}):_(i)},caseAny:(n,r)=>{for(let i of n)if(g(e,i))return _({value:e,resolved:!0,result:t(r,e),patterns:n.map(e=>({pattern:e,result:r}))});return _({value:e,resolved:!1,patterns:n.map(e=>({pattern:e,result:r}))})}}},ke=n(e=>Oe(e),{exhaustive:e=>t=>{let n=e[t];if(n===void 0)throw Error(`No case defined for value: ${String(t)}`);return n},partial:e=>({withDefault:t=>n=>{let r=e[n];return r===void 0?typeof t==`function`?t(n):t:typeof r==`function`?r(n):r}}),withGuards:e=>({withDefault:t=>n=>{for(let[t,r]of e)if(t(n))return typeof r==`function`?r(n):r;return typeof t==`function`?t(n):t}}),struct:()=>{let e=[],t={case:(n,r)=>(e.push({pattern:n,handler:r}),t),build:()=>t=>{for(let{pattern:n,handler:r}of e)if(g(t,n))return r(t);throw Error(`No matching pattern for value: ${JSON.stringify(t)}`)}};return t},builder:()=>{let e=[],t,n={case:(t,r)=>(e.push({pattern:t,result:r}),n),when:(t,r)=>(e.push({pattern:t,result:r}),n),default:n=>(t=n,{build:()=>n=>{for(let{pattern:t,result:r}of e)if(g(n,t))return typeof r==`function`?r(n):r;if(t!==void 0)return typeof t==`function`?t(n):t;throw Error(`No matching pattern for value: ${JSON.stringify(n)}`)}})};return n}});function v(e,t){return{...ue({_tag:e,impl:t}),toString(){return`${e}()`},doUnwrap(){if(`isSome`in t&&`isNone`in t){if(typeof t.isSome==`function`&&t.isSome()&&`get`in t&&typeof t.get==`function`)return{ok:!0,value:t.get()};if(typeof t.isNone==`function`&&t.isNone())return{ok:!1,empty:!0}}if(`isLeft`in t&&`isRight`in t){if(typeof t.isRight==`function`&&t.isRight()&&`value`in t)return{ok:!0,value:t.value};if(typeof t.isLeft==`function`&&t.isLeft()&&`value`in t)return{ok:!1,empty:!1,error:t.value}}if(`isSuccess`in t&&`isFailure`in t){if(typeof t.isSuccess==`function`&&t.isSuccess()&&`get`in t&&typeof t.get==`function`)return{ok:!0,value:t.get()};if(typeof t.isFailure==`function`&&t.isFailure()&&`getError`in t&&typeof t.getError==`function`)return{ok:!1,empty:!1,error:t.getError()}}if(`isEmpty`in t&&`head`in t){if(typeof t.isEmpty==`function`&&t.isEmpty())return{ok:!1,empty:!0};if(typeof t.head==`function`)return{ok:!0,value:t.head()};if(`head`in t)return{ok:!0,value:t.head}}return{ok:!0,value:t}}}}const y=`Throwable`;var b=class e extends Error{constructor(e,t){super(e,{cause:t?.cause}),this._tag=y,this.name=t?.taskInfo?.name??y,Object.defineProperties(this,{_tag:{value:y,writable:!1,configurable:!1},data:{value:t?.data,writable:!1,configurable:!1},taskInfo:{value:t?.taskInfo,writable:!1,configurable:!1},name:{value:t?.taskInfo?.name??y,writable:!1,configurable:!1}}),t?.cause&&Object.defineProperty(this,`cause`,{value:t.cause,writable:!1,configurable:!1}),t?.stack?this.stack=t.stack:Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}static apply(t,n,r){if(t instanceof Error){let i=new e(t.message,{data:n,cause:t.cause??void 0,stack:t.stack??void 0,taskInfo:r});for(let e of Object.keys(t))if(!(e in i)){let n=i;n[e]=t[e]}return i}if(t&&typeof t==`object`){let i=t,a=new e(typeof i.message==`string`?i.message:typeof i.error==`string`?i.error:`Object error: ${JSON.stringify(i,Object.getOwnPropertyNames(i).filter(e=>i[e]!==void 0))}`,{data:n??i,taskInfo:r});for(let e of Object.keys(i))if(!(e in a)){let t=a;t[e]=i[e]}return a}if(typeof t==`function`){let i=t.name??`anonymous function`,a=t.toString().substring(0,100)+(t.toString().length>100?`...`:``);return new e(`Function error: ${i}`,{data:n??{functionType:typeof t,functionName:i,functionString:a},taskInfo:r})}let i=typeof t,a=t===null?`null`:t===void 0?`undefined`:String(t);if(i===`number`){let a=t;return new e(Number.isNaN(a)?`Number error: NaN`:Number.isFinite(a)?`Number error: ${a}`:`Number error: ${a>0?`Infinity`:`-Infinity`}`,{data:n??{errorType:i,errorValue:a,originalError:t},taskInfo:r})}if(i===`bigint`)return new e(`BigInt error: ${t}n`,{data:n??{errorType:i,errorValue:String(t),originalError:t},taskInfo:r});if(i===`boolean`)return new e(`Boolean error: ${t}`,{data:n??{errorType:i,errorValue:t,originalError:t},taskInfo:r});if(i===`symbol`){let a=t.description??`unnamed symbol`;return new e(`Symbol error: Symbol(${a})`,{data:n??{errorType:i,symbolDescription:a,originalError:t},taskInfo:r})}return new e(typeof t==`string`?t:`${i.charAt(0).toUpperCase()+i.slice(1)} error: ${a}`,{data:n??{errorType:i,errorValue:a,originalError:t},taskInfo:r})}};function Ae(e){return e instanceof Error&&typeof e==`object`&&e._tag===`Throwable`}const je=(e,t)=>{if(e.isRight())return S(e.orThrow(),t);if(e.isLeft())return x(e.fold(e=>e,()=>Error(`Unexpected right value`)),void 0,t);throw Error(`Unrecognized task outcome`)},x=(e,t,n)=>{let i={name:n?.name??`Task`,description:n?.description??``},a=b.apply(e,t,i),l={...v(`Err`,{error:a,meta:i}),_tag:`Err`,_meta:i,value:void 0,error:a,isSuccess(){return!1},isFailure(){return!0},isOk(){return!1},isErr(){return!0},map:e=>x(a,t,n),flatMap:e=>x(a,t,n),ap:e=>x(a,t,n),mapAsync:e=>Promise.resolve(x(a,t,n)),flatMapAsync:e=>Promise.resolve(x(a,t,n)),mapError:e=>x(e(a),t,n),recover:e=>S(e,n),recoverWith:e=>S(e(a),n),orThrow:e=>{throw e??a},orElse:e=>e,or:e=>e,orNull:()=>null,orUndefined:()=>void 0,toEither:()=>c(a),toTry:()=>o(()=>{throw a}),toOption:()=>r(),toList:()=>s([]),fold:(e,t)=>e(a),match:e=>e.Err(a),foldLeft:e=>t=>e,foldRight:e=>t=>e,size:0,isEmpty:!0,contains:e=>!1,reduce:e=>{throw Error(`Cannot reduce empty Err`)},reduceRight:e=>{throw Error(`Cannot reduceRight empty Err`)},count:e=>0,find:e=>r(),exists:e=>!1,forEach:e=>{},toPromise:()=>Promise.reject(a),doUnwrap(){return{ok:!1,empty:!1,error:a}},serialize:()=>({toJSON:()=>u({_tag:`Err`,error:a.message??a.toString()})??`{}`,toYAML:()=>`_tag: Err\nerror: ${a.message??a.toString()}`,toBinary:()=>Buffer.from(JSON.stringify({_tag:`Err`,error:a.message??a.toString()})).toString(`base64`)}),pipe:e=>e(l)};return l},S=(e,t)=>{let n={name:t?.name??`Task`,description:t?.description??``},i={...v(`Ok`,{value:e,meta:n}),_tag:`Ok`,_meta:n,value:e,error:void 0,isSuccess(){return!0},isFailure(){return!1},isOk(){return!0},isErr(){return!1},map:n=>S(n(e),t),flatMap:n=>{let r=n(e);return r&&typeof r==`object`&&`isLeft`in r&&`isRight`in r?je(r,t):r},ap:n=>n.isOk()?S(n.value(e),t):x(n.error,void 0,t),mapAsync:async n=>S(await n(e),t),flatMapAsync:async t=>await t(e),mapError:n=>S(e,t),recover:n=>S(e,t),recoverWith:n=>S(e,t),orThrow:t=>e,orElse:t=>e,or:n=>S(e,t),orNull:()=>e,orUndefined:()=>e,toEither:()=>l(e),toTry:()=>o(()=>e),toOption:()=>a(e),toList:()=>s([e]),fold:(t,n)=>n(e),match:t=>t.Ok(e),foldLeft:t=>n=>n(t,e),foldRight:t=>n=>n(e,t),size:1,isEmpty:!1,contains:t=>e===t,reduce:t=>e,reduceRight:t=>e,count:t=>t(e)?1:0,find:t=>t(e)?a(e):r(),exists:t=>t(e),forEach:t=>t(e),toPromise:()=>Promise.resolve(e),doUnwrap(){return{ok:!0,value:e}},serialize:()=>({toJSON:()=>u({_tag:`Ok`,value:e})??`{}`,toYAML:()=>`_tag: Ok\nvalue: ${u(e)??`undefined`}`,toBinary:()=>Buffer.from(JSON.stringify({_tag:`Ok`,value:e})).toString(`base64`)}),pipe:e=>e(i)};return i},C=()=>{let e=new AbortController,t=ce();return{token:{get isCancelled(){return e.signal.aborted},get signal(){return e.signal},onCancel(n){e.signal.aborted?n():t.add(n)}},cancel(){e.signal.aborted||(e.abort(),t.build().forEach(e=>{try{e()}catch(e){console.error(`Error in cancellation callback:`,e)}}))}}},Me=e=>{let t=e?.name??`Task`,n=e?.description??``,r={Async:(e,r=e=>e,i=()=>{},a)=>new Promise(o=>{(async()=>{let s=f(!1),c=f(null),l=f(()=>{});if(a){if(a.isCancelled){try{await i()}catch(e){o(x(e,void 0,{name:t,description:n}));return}o(x(Error(`Task was cancelled before execution started`),void 0,{name:t,description:n}));return}a.onCancel(()=>{s.set(!0),c.set(Error(`Task was cancelled during execution`))}),l.set(()=>{})}try{let r=await e();try{await i()}catch(e){o(x(e,void 0,{name:t,description:n}));return}if(s.get()){c.get()?o(x(c.get(),void 0,{name:t,description:n})):o(x(Error(`Task was cancelled during execution`),void 0,{name:t,description:n}));return}if(r&&typeof r==`object`&&`_tag`in r){let e=r;e._tag===`Ok`||e._tag===`Err`?o(e):o(S(r,{name:t,description:n}))}else o(S(r,{name:t,description:n}))}catch(e){try{await i()}catch(e){o(x(e,void 0,{name:t,description:n}));return}if(s.get()){c.get()?o(x(c.get(),void 0,{name:t,description:n})):o(x(Error(`Task was cancelled during execution`),void 0,{name:t,description:n}));return}try{if(e instanceof Error&&Ae(e)){let i=Error(`${t}: ${e.message}`),a=b.apply(i,void 0,{name:t,description:n});Object.defineProperty(a,`cause`,{value:e,writable:!1,configurable:!1}),Promise.resolve().then(()=>{try{r(e)}catch(e){console.error(`Error in error handler:`,e)}}),o(x(a,void 0,{name:t,description:n}))}else{let i=await r(e);if(i&&typeof i==`object`&&`_tag`in i){let e=i;e._tag===`Ok`||e._tag===`Err`?o(e):o(x(i,void 0,{name:t,description:n}))}else o(x(i,void 0,{name:t,description:n}))}}catch(e){o(x(e,void 0,{name:t,description:n}))}}finally{l.get()()}})().catch(e=>o(x(e,void 0,{name:t,description:n})))}),Sync:(e,r=e=>e,i=()=>{})=>{try{return S(e(),{name:t,description:n})}catch(e){return x(r(e),void 0,{name:t,description:n})}finally{i()}},AsyncWithProgress:(e,t,n=e=>e,i=()=>{},a)=>{let o=e=>{let n=Math.max(0,Math.min(100,e));n<=100&&t(n)};return r.Async(()=>e(o),n,i,a)}};return{...v(`Task`,r),_type:`Task`}},Ne={success:(e,t)=>S(e,t),fail:(e,t,n)=>x(e,t,n),ok:(e,t)=>S(e,t),err:(e,t,n)=>x(e,t,n),fromEither:(e,t)=>je(e,t),fromTry:(e,t)=>e.isSuccess()?S(e.orThrow(),t):x(e.fold(e=>e,()=>Error(`Unexpected success`)),void 0,t),getErrorChain:e=>{if(!e)return[];let t=ce();t.add(e);let n=f(e);for(;n.get()&&n.get().cause;){let{cause:e}=n.get();if(e)t.add(e),n.set(e);else break;if(t.size()>100)break}return t.build()},formatErrorChain:(e,t)=>{let n=Ne.getErrorChain(e),r=t?.separator??`
4
4
  `;return n.map((e,n)=>{if(!e)return`${n>0?`↳ `:``}Unknown error`;let{taskInfo:r}=e,i=t?.includeTasks&&r?.name?`[${r.name}] `:``,a=e.message??`No message`,o=f(`${n>0?`↳ `:``}${i}${a}`);return t?.includeStackTrace&&e.stack&&o.set(`${o.get()}\n${e.stack.split(`
5
5
  `).slice(1).join(`
6
6
  `)}`),o.get()}).join(r)},fromPromise:(e,t)=>(...n)=>w(t??{name:`PromiseTask`,description:`Task from Promise`}).Async(()=>e(...n),e=>e),toPromise:e=>new Promise((t,n)=>{e.isSuccess()?t(e.orThrow()):n(e.error)}),race:(e,t,n)=>w({name:n?.name??`TaskRace`,description:n?.description??`Race between multiple tasks`}).Async(async()=>{let n=ce();e.forEach(e=>n.add(e));let r=f(void 0);if(typeof t==`number`&&t>0){let e=new Promise((e,n)=>{r.set(setTimeout(()=>{n(Error(`Task race timed out after ${t}ms`))},t))});n.add(e)}try{return await new Promise((e,t)=>{n.build().forEach(n=>{n.then(n=>{if(n&&typeof n==`object`&&`_tag`in n){let r=n;r._tag===`Ok`?e(r.orThrow()):r._tag===`Err`?t(r.error):e(n)}else e(n)},e=>t(e))})})}finally{r.get()&&clearTimeout(r.get())}},e=>e),fromNodeCallback:(e,t)=>{let n={name:t?.name??`NodeCallbackTask`,description:t?.description??`Task from Node.js callback function`};return(...t)=>w(n).Async(()=>new Promise((n,r)=>{try{e(...t,(e,t)=>{e?r(e):n(t)})}catch(e){r(e)}}),e=>e)},createCancellationTokenSource:C,cancellable:(e,t)=>{let n=C();return{task:w(t).Async(()=>e(n.token),e=>e,()=>{},n.token),cancel:()=>n.cancel()}},withProgress:(e,t=()=>{},n)=>{let r=C(),i=f(0),a=e=>{i.set(Math.max(0,Math.min(100,e))),t(i.get())};return{task:w(n).Async(()=>e(a,r.token),e=>e,()=>{},r.token),cancel:()=>r.cancel(),currentProgress:()=>i.get()}}},w=n(Me,Ne),Pe={includeTasks:!0,includeStackTrace:!1,separator:`
package/dist/cli/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{P as e}from"../Valuable-B8h0iKI_.js";import{Option as t}from"../option/index.js";import{List as n}from"../list/index.js";const r=`0.46.0`,i={Option:{description:`Safe nullable handling - Some<T> or None`,interfaces:[`Functor`,`Monad`,`Foldable`,`Extractable`,`Matchable`,`Serializable`,`Traversable`],methods:{create:[`Option(v)`,`Option.none()`,`Some(v)`,`None()`],transform:[`.map(f)`,`.flatMap(f)`,`.filter(p)`,`.ap(ff)`],extract:[`.fold(n, s)`,`.orElse(d)`,`.orThrow()`,`.orNull()`,`.match({Some, None})`],check:[`.isSome`,`.isNone`,`.isDefined`,`.isEmpty`]}},Either:{description:`Error handling with Left (error) or Right (success)`,interfaces:[`Functor`,`Monad`,`Foldable`,`Traversable`,`PromiseLike`],methods:{create:[`Right(v)`,`Left(e)`,`Either.right(v)`,`Either.left(e)`],transform:[`.map(f)`,`.flatMap(f)`,`.mapLeft(f)`,`.swap()`],extract:[`.fold(l, r)`,`.orElse(d)`,`.orThrow()`,`.match({Left, Right})`],check:[`.isRight`,`.isLeft`]}},Try:{description:`Wrap operations that may throw - Success<T> or Failure`,interfaces:[`Functor`,`Monad`,`Foldable`,`Extractable`,`Matchable`,`Serializable`,`Traversable`],methods:{create:[`Try(() => expr)`,`Success(v)`,`Failure(e)`],transform:[`.map(f)`,`.flatMap(f)`,`.recover(f)`,`.recoverWith(f)`],extract:[`.fold(f, s)`,`.orElse(d)`,`.orThrow()`,`.toOption()`,`.toEither()`],check:[`.isSuccess`,`.isFailure`]}},List:{description:`Immutable array with functional operations`,interfaces:[`Functor`,`Monad`,`Foldable`,`Collection`,`Serializable`,`Traversable`],methods:{create:[`List([...])`,`List.of(...)`,`List.empty()`],transform:[`.map(f)`,`.flatMap(f)`,`.filter(p)`,`.take(n)`,`.takeWhile(p)`,`.takeRight(n)`,`.drop(n)`,`.dropWhile(p)`,`.concat(list)`,`.reverse()`,`.distinct()`,`.sorted()`,`.sortBy(f)`,`.zip(list)`,`.zipWithIndex()`,`.prepend(v)`,`.slice(s, e)`],extract:[`.fold(z, f)`,`.reduce(f)`,`.head`,`.headOption`,`.tail`,`.last`,`.lastOption`,`.init`,`.indexOf(v)`,`.toArray()`],check:[`.isEmpty`,`.nonEmpty`,`.size`,`.contains(v)`],other:[`.groupBy(f)`,`.partition(p)`,`.span(p)`]}},Set:{description:`Immutable set of unique values`,interfaces:[`Functor`,`Foldable`,`Collection`,`Serializable`,`Traversable`],methods:{create:[`Set([...])`,`Set.of(...)`,`Set.empty()`],transform:[`.map(f)`,`.filter(p)`,`.union(s)`,`.intersection(s)`,`.difference(s)`,`.add(v)`],extract:[`.fold(z, f)`,`.toArray()`],check:[`.has(v)`,`.isEmpty`,`.size`]}},Map:{description:`Immutable key-value store`,interfaces:[`SafeTraversable`,`Collection`,`Serializable`],methods:{create:[`Map([[k, v], ...])`,`Map.of([k, v], ...)`,`Map.empty()`],transform:[`.set(k, v)`,`.delete(k)`,`.map(f)`,`.filter(p)`,`.add(k, v)`],extract:[`.get(k)`,`.keys()`,`.values()`,`.entries()`,`.fold(z, f)`],check:[`.has(k)`,`.isEmpty`,`.size`]}},Lazy:{description:`Deferred computation with memoization`,interfaces:[`Functor`,`Monad`,`Foldable`,`Extractable`,`Serializable`,`Traversable`],methods:{create:[`Lazy(() => expr)`],transform:[`.map(f)`,`.flatMap(f)`],extract:[`.fold(n, s)`,`.orElse(d)`,`.orThrow()`,`.get()`],check:[`.isEvaluated`]}},LazyList:{description:`Lazy sequences for large/infinite data`,interfaces:[`Functor`,`Monad`,`Iterable`],methods:{create:[`LazyList.from(iter)`,`LazyList.range(start, end)`,`LazyList.infinite(f)`],transform:[`.map(f)`,`.filter(p)`,`.take(n)`,`.takeRight(n)`,`.drop(n)`,`.takeWhile(p)`,`.dropWhile(p)`,`.concat(ll)`,`.reverse()`,`.distinct()`,`.zip(ll)`,`.zipWithIndex()`],extract:[`.head`,`.headOption`,`.tail`,`.last`,`.lastOption`,`.init`,`.toArray()`],check:[`.isEmpty`]}},Task:{description:`Async operations with cancellation and progress`,interfaces:[],methods:{create:[`Task.of(v)`,`Task.from(promise)`,`Task.sync(f)`,`Task.async(f)`],transform:[`.map(f)`,`.flatMap(f)`,`.mapError(f)`],extract:[`.run()`,`.cancel()`],other:[`.onProgress(cb)`,`.onCancel(cb)`]}},IO:{description:`Lazy effect type with typed errors and dependency injection`,interfaces:[`Functor`,`Monad`,`Foldable`,`Matchable`],methods:{create:[`IO(() => v)`,`IO.succeed(v)`,`IO.fail(e)`,`IO.sync(f)`,`IO.async(f)`,`IO.tryPromise({try, catch})`,`IO.fromEither(e)`,`IO.fromOption(o)`,`IO.fromTry(t)`],transform:[`.map(f)`,`.flatMap(f)`,`.tap(f)`,`.mapError(f)`,`.recover(v)`,`.recoverWith(f)`],extract:[`.run()`,`.runOrThrow()`,`.runSync()`,`.runSyncOrThrow()`,`.runExit()`,`.runOption()`,`.runTry()`,`.fold(onErr, onOk)`,`.match({failure, success})`],check:[],other:[`.catchTag(tag, f)`,`.catchAll(f)`,`.retry(n)`,`.retryWithDelay(n, ms)`,`.timeout(ms)`,`.delay(ms)`,`.zip(io)`,`.pipe(f)`,`IO.all([...])`,`IO.race([...])`,`IO.bracket(acquire, use, release)`,`IO.gen(function*() {...})`,`IO.Do.bind().map()`,`IO.service(Tag)`,`.provideService(Tag, impl)`,`.provideLayer(layer)`]}},Cond:{description:`Conditional expression builder - replace if-else chains`,interfaces:[],methods:{create:[`Cond<T>()`],other:[`.case(pred, result)`,`.otherwise(result)`,`.eval()`]}},Match:{description:`Pattern matching - replace switch statements`,interfaces:[],methods:{create:[`Match(value)`],other:[`.case(pattern, result)`,`.when(pred, result)`,`.default(result)`,`.done()`]}},Brand:{description:`Nominal typing without runtime overhead`,interfaces:[],methods:{create:[`Brand<K, T>(value)`],extract:[`.unwrap()`,`.toString()`]}},ValidatedBrand:{description:`Branded types with runtime validation`,interfaces:[],methods:{create:[`ValidatedBrand(validator)`,`.of(v)`,`.from(v)`,`.unsafeOf(v)`],check:[`.is(v)`],other:[`.refine(validator)`]}},Tuple:{description:`Fixed-size typed array`,interfaces:[`Typeable`,`Valuable`,`Iterable`],methods:{create:[`Tuple([a, b, ...])`,`Tuple.of(a, b, ...)`],extract:[`.first`,`.second`,`.toArray()`],transform:[`.map(f)`]}},Stack:{description:`Immutable LIFO stack`,interfaces:[`Foldable`,`Collection`,`Serializable`,`Traversable`],methods:{create:[`Stack()`,`Stack.of(...)`],transform:[`.push(v)`,`.pop()`],extract:[`.peek()`,`.toArray()`],check:[`.isEmpty`,`.size`]}}},a={Functor:{description:`Transform contained values`,methods:[`.map<B>(f: A => B): Functor<B>`]},Applicative:{extends:`Functor`,description:`Apply wrapped functions`,methods:[`.ap<B>(ff: Applicative<A => B>): Applicative<B>`]},Monad:{extends:`Applicative`,description:`Chain operations returning wrapped values`,methods:[`.flatMap<B>(f: A => Monad<B>): Monad<B>`]},Foldable:{description:`Extract via pattern matching`,methods:[`.fold<B>(empty: () => B, f: A => B): B`,`.foldLeft<B>(z: B, op: (B, A) => B): B`,`.foldRight<B>(z: B, op: (A, B) => B): B`]},Extractable:{description:`Get contained value with fallback`,methods:[`.orElse(d: T): T`,`.orThrow(e?: Error): T`,`.orNull(): T | null`,`.orUndefined(): T | undefined`]},Matchable:{description:`Pattern match on type variants`,methods:[`.match<R>(patterns: Record<Tag, Handler>): R`]},Traversable:{description:`Iterate and check contents`,methods:[`.size: number`,`.isEmpty: boolean`,`.contains(v: A): boolean`,`.reduce<B>(f, init): B`]},Collection:{description:`Collection operations`,methods:[`.toArray(): A[]`,`.forEach(f: A => void): void`]},Serializable:{description:`Convert to string formats`,methods:[`.serialize().toJSON(): string`,`.serialize().toYAML(): string`]}},o={Core:[`Option`,`Either`,`Try`],Collection:[`List`,`Set`,`Map`,`LazyList`,`Tuple`,`Stack`],Effect:[`IO`,`Task`],Utility:[`Lazy`,`Cond`,`Match`,`Brand`,`ValidatedBrand`]},s=()=>{let e=n([`functype ${r} - Scala-inspired FP for TypeScript`,``]);return n(Object.entries(o)).foldLeft(e)((e,[r,a])=>{let o=e.add(r.toUpperCase());return n(a).foldLeft(o)((e,n)=>t(i[n]).fold(()=>e,t=>{let r=t.interfaces.length>0?` [${t.interfaces.join(`, `)}]`:``;return e.add(` ${n}${r}`).add(` ${t.description}`)})).add(``)}).concat(n([`Use: npx functype <Type> for details`,`Use: npx functype interfaces for interface reference`])).toArray().join(`
2
+ import{P as e}from"../Valuable-BlffnwkD.js";import{Option as t}from"../option/index.js";import{List as n}from"../list/index.js";const r=`0.46.1`,i={Option:{description:`Safe nullable handling - Some<T> or None`,interfaces:[`Functor`,`Monad`,`Foldable`,`Extractable`,`Matchable`,`Serializable`,`Traversable`],methods:{create:[`Option(v)`,`Option.none()`,`Some(v)`,`None()`],transform:[`.map(f)`,`.flatMap(f)`,`.filter(p)`,`.ap(ff)`],extract:[`.fold(n, s)`,`.orElse(d)`,`.orThrow()`,`.orNull()`,`.match({Some, None})`],check:[`.isSome`,`.isNone`,`.isDefined`,`.isEmpty`]}},Either:{description:`Error handling with Left (error) or Right (success)`,interfaces:[`Functor`,`Monad`,`Foldable`,`Traversable`,`PromiseLike`],methods:{create:[`Right(v)`,`Left(e)`,`Either.right(v)`,`Either.left(e)`],transform:[`.map(f)`,`.flatMap(f)`,`.mapLeft(f)`,`.swap()`],extract:[`.fold(l, r)`,`.orElse(d)`,`.orThrow()`,`.match({Left, Right})`],check:[`.isRight`,`.isLeft`]}},Try:{description:`Wrap operations that may throw - Success<T> or Failure`,interfaces:[`Functor`,`Monad`,`Foldable`,`Extractable`,`Matchable`,`Serializable`,`Traversable`],methods:{create:[`Try(() => expr)`,`Success(v)`,`Failure(e)`],transform:[`.map(f)`,`.flatMap(f)`,`.recover(f)`,`.recoverWith(f)`],extract:[`.fold(f, s)`,`.orElse(d)`,`.orThrow()`,`.toOption()`,`.toEither()`],check:[`.isSuccess`,`.isFailure`]}},List:{description:`Immutable array with functional operations`,interfaces:[`Functor`,`Monad`,`Foldable`,`Collection`,`Serializable`,`Traversable`],methods:{create:[`List([...])`,`List.of(...)`,`List.empty()`],transform:[`.map(f)`,`.flatMap(f)`,`.filter(p)`,`.take(n)`,`.takeWhile(p)`,`.takeRight(n)`,`.drop(n)`,`.dropWhile(p)`,`.concat(list)`,`.reverse()`,`.distinct()`,`.sorted()`,`.sortBy(f)`,`.zip(list)`,`.zipWithIndex()`,`.prepend(v)`,`.slice(s, e)`],extract:[`.fold(z, f)`,`.reduce(f)`,`.head`,`.headOption`,`.tail`,`.last`,`.lastOption`,`.init`,`.indexOf(v)`,`.toArray()`],check:[`.isEmpty`,`.nonEmpty`,`.size`,`.contains(v)`],other:[`.groupBy(f)`,`.partition(p)`,`.span(p)`]}},Set:{description:`Immutable set of unique values`,interfaces:[`Functor`,`Foldable`,`Collection`,`Serializable`,`Traversable`],methods:{create:[`Set([...])`,`Set.of(...)`,`Set.empty()`],transform:[`.map(f)`,`.filter(p)`,`.union(s)`,`.intersection(s)`,`.difference(s)`,`.add(v)`],extract:[`.fold(z, f)`,`.toArray()`],check:[`.has(v)`,`.isEmpty`,`.size`]}},Map:{description:`Immutable key-value store`,interfaces:[`SafeTraversable`,`Collection`,`Serializable`],methods:{create:[`Map([[k, v], ...])`,`Map.of([k, v], ...)`,`Map.empty()`],transform:[`.set(k, v)`,`.delete(k)`,`.map(f)`,`.filter(p)`,`.add(k, v)`],extract:[`.get(k)`,`.keys()`,`.values()`,`.entries()`,`.fold(z, f)`],check:[`.has(k)`,`.isEmpty`,`.size`]}},Lazy:{description:`Deferred computation with memoization`,interfaces:[`Functor`,`Monad`,`Foldable`,`Extractable`,`Serializable`,`Traversable`],methods:{create:[`Lazy(() => expr)`],transform:[`.map(f)`,`.flatMap(f)`],extract:[`.fold(n, s)`,`.orElse(d)`,`.orThrow()`,`.get()`],check:[`.isEvaluated`]}},LazyList:{description:`Lazy sequences for large/infinite data`,interfaces:[`Functor`,`Monad`,`Iterable`],methods:{create:[`LazyList.from(iter)`,`LazyList.range(start, end)`,`LazyList.infinite(f)`],transform:[`.map(f)`,`.filter(p)`,`.take(n)`,`.takeRight(n)`,`.drop(n)`,`.takeWhile(p)`,`.dropWhile(p)`,`.concat(ll)`,`.reverse()`,`.distinct()`,`.zip(ll)`,`.zipWithIndex()`],extract:[`.head`,`.headOption`,`.tail`,`.last`,`.lastOption`,`.init`,`.toArray()`],check:[`.isEmpty`]}},Task:{description:`Async operations with cancellation and progress`,interfaces:[],methods:{create:[`Task.of(v)`,`Task.from(promise)`,`Task.sync(f)`,`Task.async(f)`],transform:[`.map(f)`,`.flatMap(f)`,`.mapError(f)`],extract:[`.run()`,`.cancel()`],other:[`.onProgress(cb)`,`.onCancel(cb)`]}},IO:{description:`Lazy effect type with typed errors and dependency injection`,interfaces:[`Functor`,`Monad`,`Foldable`,`Matchable`],methods:{create:[`IO(() => v)`,`IO.succeed(v)`,`IO.fail(e)`,`IO.sync(f)`,`IO.async(f)`,`IO.tryPromise({try, catch})`,`IO.fromEither(e)`,`IO.fromOption(o)`,`IO.fromTry(t)`],transform:[`.map(f)`,`.flatMap(f)`,`.tap(f)`,`.mapError(f)`,`.recover(v)`,`.recoverWith(f)`],extract:[`.run()`,`.runOrThrow()`,`.runSync()`,`.runSyncOrThrow()`,`.runExit()`,`.runOption()`,`.runTry()`,`.fold(onErr, onOk)`,`.match({failure, success})`],check:[],other:[`.catchTag(tag, f)`,`.catchAll(f)`,`.retry(n)`,`.retryWithDelay(n, ms)`,`.timeout(ms)`,`.delay(ms)`,`.zip(io)`,`.pipe(f)`,`IO.all([...])`,`IO.race([...])`,`IO.bracket(acquire, use, release)`,`IO.gen(function*() {...})`,`IO.Do.bind().map()`,`IO.service(Tag)`,`.provideService(Tag, impl)`,`.provideLayer(layer)`]}},Cond:{description:`Conditional expression builder - replace if-else chains`,interfaces:[],methods:{create:[`Cond<T>()`],other:[`.case(pred, result)`,`.otherwise(result)`,`.eval()`]}},Match:{description:`Pattern matching - replace switch statements`,interfaces:[],methods:{create:[`Match(value)`],other:[`.case(pattern, result)`,`.when(pred, result)`,`.default(result)`,`.done()`]}},Brand:{description:`Nominal typing without runtime overhead`,interfaces:[],methods:{create:[`Brand<K, T>(value)`],extract:[`.unwrap()`,`.toString()`]}},ValidatedBrand:{description:`Branded types with runtime validation`,interfaces:[],methods:{create:[`ValidatedBrand(validator)`,`.of(v)`,`.from(v)`,`.unsafeOf(v)`],check:[`.is(v)`],other:[`.refine(validator)`]}},Tuple:{description:`Fixed-size typed array`,interfaces:[`Typeable`,`Valuable`,`Iterable`],methods:{create:[`Tuple([a, b, ...])`,`Tuple.of(a, b, ...)`],extract:[`.first`,`.second`,`.toArray()`],transform:[`.map(f)`]}},Stack:{description:`Immutable LIFO stack`,interfaces:[`Foldable`,`Collection`,`Serializable`,`Traversable`],methods:{create:[`Stack()`,`Stack.of(...)`],transform:[`.push(v)`,`.pop()`],extract:[`.peek()`,`.toArray()`],check:[`.isEmpty`,`.size`]}}},a={Functor:{description:`Transform contained values`,methods:[`.map<B>(f: A => B): Functor<B>`]},Applicative:{extends:`Functor`,description:`Apply wrapped functions`,methods:[`.ap<B>(ff: Applicative<A => B>): Applicative<B>`]},Monad:{extends:`Applicative`,description:`Chain operations returning wrapped values`,methods:[`.flatMap<B>(f: A => Monad<B>): Monad<B>`]},Foldable:{description:`Extract via pattern matching`,methods:[`.fold<B>(empty: () => B, f: A => B): B`,`.foldLeft<B>(z: B, op: (B, A) => B): B`,`.foldRight<B>(z: B, op: (A, B) => B): B`]},Extractable:{description:`Get contained value with fallback`,methods:[`.orElse(d: T): T`,`.orThrow(e?: Error): T`,`.orNull(): T | null`,`.orUndefined(): T | undefined`]},Matchable:{description:`Pattern match on type variants`,methods:[`.match<R>(patterns: Record<Tag, Handler>): R`]},Traversable:{description:`Iterate and check contents`,methods:[`.size: number`,`.isEmpty: boolean`,`.contains(v: A): boolean`,`.reduce<B>(f, init): B`]},Collection:{description:`Collection operations`,methods:[`.toArray(): A[]`,`.forEach(f: A => void): void`]},Serializable:{description:`Convert to string formats`,methods:[`.serialize().toJSON(): string`,`.serialize().toYAML(): string`]}},o={Core:[`Option`,`Either`,`Try`],Collection:[`List`,`Set`,`Map`,`LazyList`,`Tuple`,`Stack`],Effect:[`IO`,`Task`],Utility:[`Lazy`,`Cond`,`Match`,`Brand`,`ValidatedBrand`]},s=()=>{let e=n([`functype ${r} - Scala-inspired FP for TypeScript`,``]);return n(Object.entries(o)).foldLeft(e)((e,[r,a])=>{let o=e.add(r.toUpperCase());return n(a).foldLeft(o)((e,n)=>t(i[n]).fold(()=>e,t=>{let r=t.interfaces.length>0?` [${t.interfaces.join(`, `)}]`:``;return e.add(` ${n}${r}`).add(` ${t.description}`)})).add(``)}).concat(n([`Use: npx functype <Type> for details`,`Use: npx functype interfaces for interface reference`])).toArray().join(`
3
3
  `)},c=(e,r)=>{let i=r.interfaces.length>0?` [${r.interfaces.join(`, `)}]`:``,a=n([`create`,`transform`,`extract`,`check`,`other`]),o=n([`${e}<T>${i}`,``,r.description,``]);return a.foldLeft(o)((e,i)=>t(r.methods[i]).filter(e=>e.length>0).fold(()=>e,t=>{let r=e.add(i.toUpperCase());return n(t).foldLeft(r)((e,t)=>e.add(` ${t}`)).add(``)})).toArray().join(`
4
4
  `).trimEnd()},l=()=>{let e=n([`INTERFACES`,``]);return n(Object.entries(a)).foldLeft(e)((e,[t,r])=>{let i=r.extends?` extends ${r.extends}`:``,a=e.add(`${t}<A>${i}`).add(` ${r.description}`);return n(r.methods).foldLeft(a)((e,t)=>e.add(` ${t}`)).add(``)}).toArray().join(`
5
5
  `).trimEnd()},u=e=>JSON.stringify(e,null,2),d=()=>({version:r,categories:o,types:i}),f=e=>t(i[e]).map(t=>({name:e,data:t})).or(n(Object.entries(i)).find(([t])=>t.toLowerCase()===e.toLowerCase()).map(([e,t])=>({name:e,data:t}))).orUndefined(),p=()=>Object.keys(i),m=()=>a,h={Option:`export interface Option<T extends Type> extends Functype<T, "Some" | "None">, Promisable<T>, Doable<T>, Reshapeable<T> {
@@ -1,2 +1,2 @@
1
- import{rt as e}from"../Valuable-B8h0iKI_.js";import{t}from"../Companion-VlxcFhzb.js";import{None as n,Some as r}from"../option/index.js";import{Try as i}from"../try/index.js";import{List as a}from"../list/index.js";import o from"safe-stable-stringify";const s=t=>({_tag:`Right`,value:t,isLeft(){return!1},isRight(){return!0},orElse:e=>t,orThrow:()=>t,or:e=>l(t),orNull:()=>t,orUndefined:()=>t,map:e=>l(e(t)),ap:e=>e._tag===`Right`?l(e.value(t)):u(e.value),mapAsync:e=>e(t).then(e=>l(e)).catch(e=>Promise.resolve(u(e))),merge:e=>e.isLeft()?u(e.value):l([t,e.value]),flatMap:e=>e(t),flatMapAsync:e=>e(t).catch(e=>u(e)),toOption:()=>r(t),toList:()=>a([t]),toEither:e=>l(t),toTry:()=>i(()=>t),toJSON(){return{_tag:`Right`,value:t}},toString:()=>`Right(${o(t)})`,*[Symbol.iterator](){yield t},*yield(){yield t},traverse:e=>{let n=e(t);return n.isLeft()?u(n.value):l([n.value])},*lazyMap(e){yield l(e(t))},tap:e=>(e(t),l(t)),tapLeft:e=>l(t),mapLeft:e=>l(t),bimap:(e,n)=>l(n(t)),fold:(e,n)=>n(t),foldLeft:e=>n=>n(e,t),foldRight:e=>n=>n(t,e),match:e=>e.Right(t),swap:()=>u(t),toPromise:()=>Promise.resolve(t),toValue:()=>({_tag:`Right`,value:t}),pipeEither:(e,n)=>n(t),pipe:e=>e(t),serialize:()=>e(`Right`,t),get size(){return 1},get isEmpty(){return!1},contains:e=>t===e,reduce:e=>t,reduceRight:e=>t,count:e=>e(t)?1:0,find:e=>e(t)?r(t):n(),exists:e=>e(t),forEach:e=>e(t),doUnwrap(){return{ok:!0,value:t}}}),c=t=>({_tag:`Left`,value:t,isLeft(){return!0},isRight(){return!1},orElse:e=>e,orThrow:e=>{throw e??t},or:e=>e,orNull:()=>null,orUndefined:()=>void 0,map:e=>u(t),ap:e=>u(t),mapAsync:e=>Promise.resolve(u(t)),merge:e=>u(t),flatMap:e=>u(t),flatMapAsync:e=>Promise.resolve(u(t)),toOption:()=>n(),toList:()=>a(),toEither:e=>u(e),toTry:()=>i(()=>{throw Error(String(t))}),toJSON(){return{_tag:`Left`,value:t}},toString:()=>`Left(${o(t)})`,*[Symbol.iterator](){},*yield(){},traverse:e=>u(t),*lazyMap(e){yield u(t)},tap:e=>u(t),tapLeft:e=>(e(t),u(t)),mapLeft:e=>u(e(t)),bimap:(e,n)=>u(e(t)),fold:(e,n)=>e(t),foldLeft:e=>t=>e,foldRight:e=>t=>e,match:e=>e.Left(t),swap:()=>l(t),toPromise:()=>Promise.reject(t),toValue:()=>({_tag:`Left`,value:t}),pipeEither:(e,n)=>e(t),pipe:e=>e(t),serialize:()=>e(`Left`,t),get size(){return 0},get isEmpty(){return!0},contains:e=>!1,reduce:e=>{throw Error(`Cannot reduce a Left`)},reduceRight:e=>{throw Error(`Cannot reduceRight a Left`)},count:e=>0,find:e=>n(),exists:e=>!1,forEach:e=>{},doUnwrap(){return{ok:!1,empty:!1,error:t}}}),l=e=>s(e),u=e=>c(e),d=e=>e.isRight(),f=e=>e.isLeft(),p=(e,t)=>{try{return l(e())}catch(e){return u(t(e))}},m=e=>s(e);console.assert(m);const h=e=>c(e);console.assert(h);const g=async(e,t)=>{try{return l(await e())}catch(e){return u(t(e))}},_=(e,t)=>t?l(e):u(e),v={left:e=>u(e),right:e=>l(e),isRight:e=>e.isRight(),isLeft:e=>e.isLeft(),sequence:e=>e.reduce((e,t)=>e.isLeft()?e:t.isLeft()?u(t.value):e.map(e=>[...e,t.value]),l([])),traverse:(e,t)=>v.sequence(e.map(t)),fromNullable:(e,t)=>e==null?u(t):l(e),fromPredicate:(e,t,n)=>t(e)?l(e):u(n),ap:(e,t)=>e.flatMap(e=>t.map(e)),fromPromise:async(e,t)=>{try{return l(await e)}catch(e){return u(t(e))}},fromJSON:e=>{let t=JSON.parse(e);return t._tag===`Right`?l(t.value):u(t.value)},fromYAML:e=>{let t=e.split(`
1
+ import{rt as e}from"../Valuable-BlffnwkD.js";import{t}from"../Companion-VlxcFhzb.js";import{None as n,Some as r}from"../option/index.js";import{Try as i}from"../try/index.js";import{List as a}from"../list/index.js";import o from"safe-stable-stringify";const s=t=>({_tag:`Right`,value:t,isLeft(){return!1},isRight(){return!0},orElse:e=>t,orThrow:()=>t,or:e=>l(t),orNull:()=>t,orUndefined:()=>t,map:e=>l(e(t)),ap:e=>e._tag===`Right`?l(e.value(t)):u(e.value),mapAsync:e=>e(t).then(e=>l(e)).catch(e=>Promise.resolve(u(e))),merge:e=>e.isLeft()?u(e.value):l([t,e.value]),flatMap:e=>e(t),flatMapAsync:e=>e(t).catch(e=>u(e)),toOption:()=>r(t),toList:()=>a([t]),toEither:e=>l(t),toTry:()=>i(()=>t),toJSON(){return{_tag:`Right`,value:t}},toString:()=>`Right(${o(t)})`,*[Symbol.iterator](){yield t},*yield(){yield t},traverse:e=>{let n=e(t);return n.isLeft()?u(n.value):l([n.value])},*lazyMap(e){yield l(e(t))},tap:e=>(e(t),l(t)),tapLeft:e=>l(t),mapLeft:e=>l(t),bimap:(e,n)=>l(n(t)),fold:(e,n)=>n(t),foldLeft:e=>n=>n(e,t),foldRight:e=>n=>n(t,e),match:e=>e.Right(t),swap:()=>u(t),toPromise:()=>Promise.resolve(t),toValue:()=>({_tag:`Right`,value:t}),pipeEither:(e,n)=>n(t),pipe:e=>e(t),serialize:()=>e(`Right`,t),get size(){return 1},get isEmpty(){return!1},contains:e=>t===e,reduce:e=>t,reduceRight:e=>t,count:e=>e(t)?1:0,find:e=>e(t)?r(t):n(),exists:e=>e(t),forEach:e=>e(t),doUnwrap(){return{ok:!0,value:t}}}),c=t=>({_tag:`Left`,value:t,isLeft(){return!0},isRight(){return!1},orElse:e=>e,orThrow:e=>{throw e??t},or:e=>e,orNull:()=>null,orUndefined:()=>void 0,map:e=>u(t),ap:e=>u(t),mapAsync:e=>Promise.resolve(u(t)),merge:e=>u(t),flatMap:e=>u(t),flatMapAsync:e=>Promise.resolve(u(t)),toOption:()=>n(),toList:()=>a(),toEither:e=>u(e),toTry:()=>i(()=>{throw Error(String(t))}),toJSON(){return{_tag:`Left`,value:t}},toString:()=>`Left(${o(t)})`,*[Symbol.iterator](){},*yield(){},traverse:e=>u(t),*lazyMap(e){yield u(t)},tap:e=>u(t),tapLeft:e=>(e(t),u(t)),mapLeft:e=>u(e(t)),bimap:(e,n)=>u(e(t)),fold:(e,n)=>e(t),foldLeft:e=>t=>e,foldRight:e=>t=>e,match:e=>e.Left(t),swap:()=>l(t),toPromise:()=>Promise.reject(t),toValue:()=>({_tag:`Left`,value:t}),pipeEither:(e,n)=>e(t),pipe:e=>e(t),serialize:()=>e(`Left`,t),get size(){return 0},get isEmpty(){return!0},contains:e=>!1,reduce:e=>{throw Error(`Cannot reduce a Left`)},reduceRight:e=>{throw Error(`Cannot reduceRight a Left`)},count:e=>0,find:e=>n(),exists:e=>!1,forEach:e=>{},doUnwrap(){return{ok:!1,empty:!1,error:t}}}),l=e=>s(e),u=e=>c(e),d=e=>e.isRight(),f=e=>e.isLeft(),p=(e,t)=>{try{return l(e())}catch(e){return u(t(e))}},m=e=>s(e);console.assert(m);const h=e=>c(e);console.assert(h);const g=async(e,t)=>{try{return l(await e())}catch(e){return u(t(e))}},_=(e,t)=>t?l(e):u(e),v={left:e=>u(e),right:e=>l(e),isRight:e=>e.isRight(),isLeft:e=>e.isLeft(),sequence:e=>e.reduce((e,t)=>e.isLeft()?e:t.isLeft()?u(t.value):e.map(e=>[...e,t.value]),l([])),traverse:(e,t)=>v.sequence(e.map(t)),fromNullable:(e,t)=>e==null?u(t):l(e),fromPredicate:(e,t,n)=>t(e)?l(e):u(n),ap:(e,t)=>e.flatMap(e=>t.map(e)),fromPromise:async(e,t)=>{try{return l(await e)}catch(e){return u(t(e))}},fromJSON:e=>{let t=JSON.parse(e);return t._tag===`Right`?l(t.value):u(t.value)},fromYAML:e=>{let t=e.split(`
2
2
  `),n=t[0]?.split(`: `)[1],r=t[1]?.split(`: `)[1];if(!n||!r)throw Error(`Invalid YAML format for Either`);let i=JSON.parse(r);return n===`Right`?l(i):u(i)},fromBinary:e=>{let t=Buffer.from(e,`base64`).toString();return v.fromJSON(t)}},y=t(_,v);export{y as Either,u as Left,l as Right,h as TypeCheckLeft,m as TypeCheckRight,f as isLeft,d as isRight,p as tryCatch,g as tryCatchAsync};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{Brand as e,BrandedBoolean as t,BrandedNumber as n,BrandedString as r,createBrander as i,hasBrand as a,unwrap as o}from"./branded/index.js";import{$ as s,A as c,B as l,C as u,D as d,E as f,F as p,G as m,H as h,I as g,J as _,K as v,L as y,M as b,N as x,O as S,P as C,Q as w,R as T,S as E,T as D,U as O,V as k,W as A,X as j,Y as M,Z as N,_ as P,a as F,at as I,b as L,c as R,d as z,f as B,g as V,h as H,i as U,it as W,j as G,k as K,l as q,m as J,n as Y,nt as X,o as Z,ot as Q,p as $,q as ee,r as te,rt as ne,s as re,st as ie,t as ae,tt as oe,u as se,v as ce,w as le,x as ue,y as de,z as fe}from"./Valuable-B8h0iKI_.js";import{t as pe}from"./Companion-VlxcFhzb.js";import{None as me,Option as he,OptionConstructor as ge,Some as _e}from"./option/index.js";import{Set as ve}from"./set/index.js";import{Try as ye}from"./try/index.js";import{List as be}from"./list/index.js";import{Either as xe,Left as Se,Right as Ce,TypeCheckLeft as we,TypeCheckRight as Te,isLeft as Ee,isRight as De,tryCatch as Oe,tryCatchAsync as ke}from"./either/index.js";import{$ as Ae,Do as je,DoAsync as Me,EmptyListError as Ne,FailureError as Pe,LeftError as Fe,NoneError as Ie,isDoCapable as Le,unwrap as Re}from"./do/index.js";import{Tuple as ze}from"./tuple/index.js";import{Map as Be}from"./map/index.js";export{Ae as $,x as Base,y as BoundedNumber,T as BoundedString,e as Brand,t as BrandedBoolean,n as BrandedNumber,r as BrandedString,pe as Companion,p as Cond,H as Context,je as Do,Me as DoAsync,U as ESMap,xe as Either,fe as EmailAddress,Ne as EmptyListError,f as Err,J as Exit,Pe as FailureError,ce as FoldableUtils,P as HKT,z as IO,l as ISO8601Date,V as Identity,k as IntegerNumber,B as InterruptedError,se as Layer,F as Lazy,w as LazyList,Se as Left,Fe as LeftError,be as List,Be as Map,C as Match,te as MatchableUtils,G as NAME,h as NonEmptyString,O as NonNegativeNumber,me as None,Ie as NoneError,d as Ok,he as Option,ge as OptionConstructor,ie as ParseError,A as PatternString,m as PositiveInteger,v as PositiveNumber,s as Ref,Ce as Right,ve as Set,_e as Some,Y as Stack,q as Tag,S as Task,Z as TestClock,re as TestClockTag,R as TestContext,b as Throwable,$ as TimeoutError,ye as Try,ze as Tuple,we as TypeCheckLeft,Te as TypeCheckRight,j as Typeable,ue as TypedError,ee as UUID,_ as UrlString,M as ValidatedBrand,L as Validation,ae as Valuable,i as createBrander,K as createCancellationTokenSource,oe as createCustomSerializer,E as createErrorSerializer,X as createSerializationCompanion,ne as createSerializer,u as formatError,le as formatStackTrace,W as fromBinary,I as fromJSON,Q as fromYAML,a as hasBrand,g as isCompanion,Le as isDoCapable,de as isExtractable,Ee as isLeft,De as isRight,c as isTaggedThrowable,N as isTypeable,D as safeStringify,Oe as tryCatch,ke as tryCatchAsync,Re as unwrap,o as unwrapBrand};
1
+ import{Brand as e,BrandedBoolean as t,BrandedNumber as n,BrandedString as r,createBrander as i,hasBrand as a,unwrap as o}from"./branded/index.js";import{$ as s,A as c,B as l,C as u,D as d,E as f,F as p,G as m,H as h,I as g,J as _,K as v,L as y,M as b,N as x,O as S,P as C,Q as w,R as T,S as E,T as D,U as O,V as k,W as A,X as j,Y as M,Z as N,_ as P,a as F,at as I,b as L,c as R,d as z,f as B,g as V,h as H,i as U,it as W,j as G,k as K,l as q,m as J,n as Y,nt as X,o as Z,ot as Q,p as $,q as ee,r as te,rt as ne,s as re,st as ie,t as ae,tt as oe,u as se,v as ce,w as le,x as ue,y as de,z as fe}from"./Valuable-BlffnwkD.js";import{t as pe}from"./Companion-VlxcFhzb.js";import{None as me,Option as he,OptionConstructor as ge,Some as _e}from"./option/index.js";import{Set as ve}from"./set/index.js";import{Try as ye}from"./try/index.js";import{List as be}from"./list/index.js";import{Either as xe,Left as Se,Right as Ce,TypeCheckLeft as we,TypeCheckRight as Te,isLeft as Ee,isRight as De,tryCatch as Oe,tryCatchAsync as ke}from"./either/index.js";import{$ as Ae,Do as je,DoAsync as Me,EmptyListError as Ne,FailureError as Pe,LeftError as Fe,NoneError as Ie,isDoCapable as Le,unwrap as Re}from"./do/index.js";import{Tuple as ze}from"./tuple/index.js";import{Map as Be}from"./map/index.js";export{Ae as $,x as Base,y as BoundedNumber,T as BoundedString,e as Brand,t as BrandedBoolean,n as BrandedNumber,r as BrandedString,pe as Companion,p as Cond,H as Context,je as Do,Me as DoAsync,U as ESMap,xe as Either,fe as EmailAddress,Ne as EmptyListError,f as Err,J as Exit,Pe as FailureError,ce as FoldableUtils,P as HKT,z as IO,l as ISO8601Date,V as Identity,k as IntegerNumber,B as InterruptedError,se as Layer,F as Lazy,w as LazyList,Se as Left,Fe as LeftError,be as List,Be as Map,C as Match,te as MatchableUtils,G as NAME,h as NonEmptyString,O as NonNegativeNumber,me as None,Ie as NoneError,d as Ok,he as Option,ge as OptionConstructor,ie as ParseError,A as PatternString,m as PositiveInteger,v as PositiveNumber,s as Ref,Ce as Right,ve as Set,_e as Some,Y as Stack,q as Tag,S as Task,Z as TestClock,re as TestClockTag,R as TestContext,b as Throwable,$ as TimeoutError,ye as Try,ze as Tuple,we as TypeCheckLeft,Te as TypeCheckRight,j as Typeable,ue as TypedError,ee as UUID,_ as UrlString,M as ValidatedBrand,L as Validation,ae as Valuable,i as createBrander,K as createCancellationTokenSource,oe as createCustomSerializer,E as createErrorSerializer,X as createSerializationCompanion,ne as createSerializer,u as formatError,le as formatStackTrace,W as fromBinary,I as fromJSON,Q as fromYAML,a as hasBrand,g as isCompanion,Le as isDoCapable,de as isExtractable,Ee as isLeft,De as isRight,c as isTaggedThrowable,N as isTypeable,D as safeStringify,Oe as tryCatch,ke as tryCatchAsync,Re as unwrap,o as unwrapBrand};
@@ -1,2 +1,2 @@
1
- import{Z as e,rt as t}from"../Valuable-B8h0iKI_.js";import{t as n}from"../Companion-VlxcFhzb.js";import{None as r,Option as i}from"../option/index.js";import{Set as a}from"../set/index.js";import{Try as o}from"../try/index.js";import{Left as s,Right as c}from"../either/index.js";import l from"safe-stable-stringify";const u=n=>{let d=Array.from(n??[]),f={_tag:`List`,[Symbol.iterator]:()=>d[Symbol.iterator](),get size(){return d.length},get length(){return d.length},map:e=>u(d.map(e)),ap:e=>u(d.flatMap(t=>Array.from(e).map(e=>e(t)))),flatMap:e=>u(d.flatMap(t=>Array.from(e(t)))),flatMapAsync:async e=>u((await Promise.all(d.map(async t=>await e(t)))).flatMap(e=>Array.from(e))),forEach:e=>d.forEach(e),contains:e=>d.includes(e),count:e=>d.filter(e).length,exists:e=>d.some(e),filter:e=>u(d.filter(e)),filterNot:e=>u(d.filter(t=>!e(t))),filterType:t=>u(d.filter(n=>e(n,t))),find:(t,n)=>i(d.find(r=>t(r)&&(n?e(r,n):!0))),get head(){return d[0]},get headOption(){return d.length>0?i(d[0]):r()},get isEmpty(){return d.length===0},toArray:()=>[...d],reduce:e=>d.reduce(e),reduceRight:e=>d.reduceRight(e),fold:(e,t)=>{if(d.length===0)return e();let n=d[0];return t(n)},foldLeft:e=>t=>d.reduce(t,e),foldRight:e=>t=>d.reduceRight((e,n)=>t(n,e),e),match:e=>d.length===0?e.Empty():e.NonEmpty([...d]),remove:e=>u(d.filter(t=>t!==e)),removeAt:e=>e<0||e>=d.length?f:u([...d.slice(0,e),...d.slice(e+1)]),add:e=>u([...d,e]),get:e=>i(d[e]),concat:e=>u([...d,...e.toArray()]),take:e=>u(d.slice(0,Math.max(0,e))),takeWhile:e=>{let t=[];for(let n of d){if(!e(n))break;t.push(n)}return u(t)},takeRight:e=>u(e<=0?[]:d.slice(-e)),get last(){return d[d.length-1]},get lastOption(){return d.length>0?i(d[d.length-1]):r()},get tail(){return u(d.slice(1))},get init(){return u(d.length===0?[]:d.slice(0,-1))},reverse:()=>u([...d].reverse()),indexOf:e=>d.indexOf(e),prepend:e=>u([e,...d]),distinct:()=>{let e=new globalThis.Set,t=[];for(let n of d)e.has(n)||(e.add(n),t.push(n));return u(t)},sorted:e=>u([...d].sort(e)),sortBy:(e,t)=>u([...d].sort((n,r)=>{let i=e(n),a=e(r);return t?t(i,a):i<a?-1:i>a?1:0})),zip:e=>{let t=e.toArray(),n=Math.min(d.length,t.length),r=[];for(let e=0;e<n;e++)r.push([d[e],t[e]]);return u(r)},zipWithIndex:()=>u(d.map((e,t)=>[e,t])),groupBy:e=>{let t=new globalThis.Map;for(let n of d){let r=e(n),i=t.get(r)??[];i.push(n),t.set(r,i)}let n=new globalThis.Map;for(let[e,r]of t)n.set(e,u(r));return n},partition:e=>{let t=[],n=[];for(let r of d)e(r)?t.push(r):n.push(r);return[u(t),u(n)]},span:e=>{let t=d.findIndex(t=>!e(t));return t===-1?[u([...d]),u([])]:[u(d.slice(0,t)),u(d.slice(t))]},slice:(e,t)=>u(d.slice(e,t)),drop:e=>u(d.slice(e)),dropRight:e=>u(d.slice(0,-e)),dropWhile:e=>u(d.slice(d.findIndex(t=>!e(t)))),flatten:()=>u(d.flatMap(e=>Array.isArray(e)?e:[e])),toList:()=>f,toSet:()=>a(d),toOption:()=>d.length>0?i(d[0]):r(),toEither:e=>d.length>0?c(d[0]):s(e),toTry:()=>d.length>0?o(()=>d[0]):o(()=>{throw Error(`Empty list`)}),toString:()=>`List(${l(d)})`,toValue:()=>({_tag:`List`,value:d}),pipe:e=>e([...d]),serialize:()=>t(`List`,d),doUnwrap(){return d.length===0?{ok:!1,empty:!0}:{ok:!0,value:d[0]}}};return f},d=e=>u(e),f=u([]),p={empty:()=>f,of:(...e)=>u(e),fromJSON:e=>m(JSON.parse(e).value),fromYAML:e=>{let t=e.split(`
1
+ import{Z as e,rt as t}from"../Valuable-BlffnwkD.js";import{t as n}from"../Companion-VlxcFhzb.js";import{None as r,Option as i}from"../option/index.js";import{Set as a}from"../set/index.js";import{Try as o}from"../try/index.js";import{Left as s,Right as c}from"../either/index.js";import l from"safe-stable-stringify";const u=n=>{let d=Array.from(n??[]),f={_tag:`List`,[Symbol.iterator]:()=>d[Symbol.iterator](),get size(){return d.length},get length(){return d.length},map:e=>u(d.map(e)),ap:e=>u(d.flatMap(t=>Array.from(e).map(e=>e(t)))),flatMap:e=>u(d.flatMap(t=>Array.from(e(t)))),flatMapAsync:async e=>u((await Promise.all(d.map(async t=>await e(t)))).flatMap(e=>Array.from(e))),forEach:e=>d.forEach(e),contains:e=>d.includes(e),count:e=>d.filter(e).length,exists:e=>d.some(e),filter:e=>u(d.filter(e)),filterNot:e=>u(d.filter(t=>!e(t))),filterType:t=>u(d.filter(n=>e(n,t))),find:(t,n)=>i(d.find(r=>t(r)&&(n?e(r,n):!0))),get head(){return d[0]},get headOption(){return d.length>0?i(d[0]):r()},get isEmpty(){return d.length===0},toArray:()=>[...d],reduce:e=>d.reduce(e),reduceRight:e=>d.reduceRight(e),fold:(e,t)=>{if(d.length===0)return e();let n=d[0];return t(n)},foldLeft:e=>t=>d.reduce(t,e),foldRight:e=>t=>d.reduceRight((e,n)=>t(n,e),e),match:e=>d.length===0?e.Empty():e.NonEmpty([...d]),remove:e=>u(d.filter(t=>t!==e)),removeAt:e=>e<0||e>=d.length?f:u([...d.slice(0,e),...d.slice(e+1)]),add:e=>u([...d,e]),get:e=>i(d[e]),concat:e=>u([...d,...e.toArray()]),take:e=>u(d.slice(0,Math.max(0,e))),takeWhile:e=>{let t=[];for(let n of d){if(!e(n))break;t.push(n)}return u(t)},takeRight:e=>u(e<=0?[]:d.slice(-e)),get last(){return d[d.length-1]},get lastOption(){return d.length>0?i(d[d.length-1]):r()},get tail(){return u(d.slice(1))},get init(){return u(d.length===0?[]:d.slice(0,-1))},reverse:()=>u([...d].reverse()),indexOf:e=>d.indexOf(e),prepend:e=>u([e,...d]),distinct:()=>{let e=new globalThis.Set,t=[];for(let n of d)e.has(n)||(e.add(n),t.push(n));return u(t)},sorted:e=>u([...d].sort(e)),sortBy:(e,t)=>u([...d].sort((n,r)=>{let i=e(n),a=e(r);return t?t(i,a):i<a?-1:i>a?1:0})),zip:e=>{let t=e.toArray(),n=Math.min(d.length,t.length),r=[];for(let e=0;e<n;e++)r.push([d[e],t[e]]);return u(r)},zipWithIndex:()=>u(d.map((e,t)=>[e,t])),groupBy:e=>{let t=new globalThis.Map;for(let n of d){let r=e(n),i=t.get(r)??[];i.push(n),t.set(r,i)}let n=new globalThis.Map;for(let[e,r]of t)n.set(e,u(r));return n},partition:e=>{let t=[],n=[];for(let r of d)e(r)?t.push(r):n.push(r);return[u(t),u(n)]},span:e=>{let t=d.findIndex(t=>!e(t));return t===-1?[u([...d]),u([])]:[u(d.slice(0,t)),u(d.slice(t))]},slice:(e,t)=>u(d.slice(e,t)),drop:e=>u(d.slice(e)),dropRight:e=>u(d.slice(0,-e)),dropWhile:e=>u(d.slice(d.findIndex(t=>!e(t)))),flatten:()=>u(d.flatMap(e=>Array.isArray(e)?e:[e])),toList:()=>f,toSet:()=>a(d),toOption:()=>d.length>0?i(d[0]):r(),toEither:e=>d.length>0?c(d[0]):s(e),toTry:()=>d.length>0?o(()=>d[0]):o(()=>{throw Error(`Empty list`)}),toString:()=>`List(${l(d)})`,toValue:()=>({_tag:`List`,value:d}),pipe:e=>e([...d]),serialize:()=>t(`List`,d),doUnwrap(){return d.length===0?{ok:!1,empty:!0}:{ok:!0,value:d[0]}}};return f},d=e=>u(e),f=u([]),p={empty:()=>f,of:(...e)=>u(e),fromJSON:e=>m(JSON.parse(e).value),fromYAML:e=>{let t=e.split(`
2
2
  `)[1]?.split(`: `)[1];return m(t?JSON.parse(t):[])},fromBinary:e=>{let t=Buffer.from(e,`base64`).toString();return p.fromJSON(t)}},m=n(d,p);export{m as List};
package/dist/map/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{i as e,rt as t}from"../Valuable-B8h0iKI_.js";import{t as n}from"../Companion-VlxcFhzb.js";import{Option as r}from"../option/index.js";import{Set as i}from"../set/index.js";import{List as a}from"../list/index.js";import{Tuple as o}from"../tuple/index.js";const s=n=>{let c={values:new e(n)},l=()=>Array.from(c.values.entries()).map(([e,t])=>o([e,t])),u=t=>s(new e(c.values).set(t.toArray()[0],t.toArray()[1]).entries()),d=t=>{let n=new e(c.values);return n.delete(t)?s(n.entries()):s(c.values.entries())},f=e=>{let t=e.toArray();return c.values.get(t[0])===t[1]},p=()=>c.values.size,m=e=>s(Array.from(c.values.entries()).map(([t,n])=>[t,e(n)])),h=e=>s(s(c.values.entries()).toList().flatMap(e).toArray()),g=e=>{let t=[];for(let[n,r]of c.values.entries()){let i=e.get(n);i._tag===`Some`&&i.value&&t.push([n,i.value(r)])}return s(t)},_=async t=>{let n=new e;for(let[e,r]of c.values.entries()){let e=await t(r);for(let t of e.toList()){let[e,r]=t.toArray();n.set(e,r)}}return s(n.entries())},v=e=>a(l()).reduce(e),y=e=>a(l()).reduceRight(e),b=e=>t=>a(l()).foldLeft(e)(t),x=e=>t=>a(l()).foldRight(e)(t),S=e=>r(c.values.get(e)),C=(e,t)=>r(c.values.get(e)).orElse(t),w=()=>c.values.size===0,T=(e,t)=>r(c.values.get(e)).or(t),E=(e,t)=>{if(w())return e();let n=l();if(n.length===0)return e();let r=n[0];return r===void 0?e():t(r)},D=()=>a(l()),O=()=>i(l()),k=()=>`Map(${l().toString()})`,A=e=>w()?e.Empty():e.NonEmpty(l());return{_tag:`Map`,[Symbol.iterator]:()=>c.values.entries(),add:u,remove:d,contains:f,get size(){return p()},map:m,ap:g,flatMap:h,flatMapAsync:_,reduce:v,reduceRight:y,foldLeft:b,foldRight:x,fold:E,match:A,get:S,getOrElse:C,get isEmpty(){return w()},orElse:T,toList:D,toSet:O,toString:k,toValue:()=>({_tag:`Map`,value:Array.from(c.values.entries())}),pipe:e=>e(Array.from(c.values.entries())),serialize:()=>t(`Map`,Array.from(c.values.entries()))}},c=e=>s(e),l=s([]),u={empty:()=>l,of:(...e)=>s(e),fromJSON:e=>d(JSON.parse(e).value),fromYAML:e=>{let t=e.split(`
1
+ import{i as e,rt as t}from"../Valuable-BlffnwkD.js";import{t as n}from"../Companion-VlxcFhzb.js";import{Option as r}from"../option/index.js";import{Set as i}from"../set/index.js";import{List as a}from"../list/index.js";import{Tuple as o}from"../tuple/index.js";const s=n=>{let c={values:new e(n)},l=()=>Array.from(c.values.entries()).map(([e,t])=>o([e,t])),u=t=>s(new e(c.values).set(t.toArray()[0],t.toArray()[1]).entries()),d=t=>{let n=new e(c.values);return n.delete(t)?s(n.entries()):s(c.values.entries())},f=e=>{let t=e.toArray();return c.values.get(t[0])===t[1]},p=()=>c.values.size,m=e=>s(Array.from(c.values.entries()).map(([t,n])=>[t,e(n)])),h=e=>s(s(c.values.entries()).toList().flatMap(e).toArray()),g=e=>{let t=[];for(let[n,r]of c.values.entries()){let i=e.get(n);i._tag===`Some`&&i.value&&t.push([n,i.value(r)])}return s(t)},_=async t=>{let n=new e;for(let[e,r]of c.values.entries()){let e=await t(r);for(let t of e.toList()){let[e,r]=t.toArray();n.set(e,r)}}return s(n.entries())},v=e=>a(l()).reduce(e),y=e=>a(l()).reduceRight(e),b=e=>t=>a(l()).foldLeft(e)(t),x=e=>t=>a(l()).foldRight(e)(t),S=e=>r(c.values.get(e)),C=(e,t)=>r(c.values.get(e)).orElse(t),w=()=>c.values.size===0,T=(e,t)=>r(c.values.get(e)).or(t),E=(e,t)=>{if(w())return e();let n=l();if(n.length===0)return e();let r=n[0];return r===void 0?e():t(r)},D=()=>a(l()),O=()=>i(l()),k=()=>`Map(${l().toString()})`,A=e=>w()?e.Empty():e.NonEmpty(l());return{_tag:`Map`,[Symbol.iterator]:()=>c.values.entries(),add:u,remove:d,contains:f,get size(){return p()},map:m,ap:g,flatMap:h,flatMapAsync:_,reduce:v,reduceRight:y,foldLeft:b,foldRight:x,fold:E,match:A,get:S,getOrElse:C,get isEmpty(){return w()},orElse:T,toList:D,toSet:O,toString:k,toValue:()=>({_tag:`Map`,value:Array.from(c.values.entries())}),pipe:e=>e(Array.from(c.values.entries())),serialize:()=>t(`Map`,Array.from(c.values.entries()))}},c=e=>s(e),l=s([]),u={empty:()=>l,of:(...e)=>s(e),fromJSON:e=>d(JSON.parse(e).value),fromYAML:e=>{let t=e.split(`
2
2
  `)[1]?.split(`: `)[1];return d(t?JSON.parse(t):[])},fromBinary:e=>{let t=Buffer.from(e,`base64`).toString();return u.fromJSON(t)}},d=n(c,u);export{d as Map};
@@ -1,2 +1,2 @@
1
- import{rt as e}from"../Valuable-B8h0iKI_.js";import{t}from"../Companion-VlxcFhzb.js";import{Try as n}from"../try/index.js";import{List as r}from"../list/index.js";import{Left as i,Right as a}from"../either/index.js";import o from"safe-stable-stringify";const s=t=>({_tag:`Some`,value:t,isEmpty:!1,isSome(){return!0},isNone(){return!1},orElse:()=>t,orThrow:()=>t,or:e=>s(t),orNull:()=>t,orUndefined:()=>t,map:e=>s(e(t)),ap:e=>e._tag===`Some`&&e.value?s(e.value(t)):c,filter(e){return e(t)?s(t):c},count:e=>e(t)?1:0,find:e=>e(t)?s(t):c,exists:e=>e(t),forEach:e=>e(t),fold:(e,n)=>n(t),match:e=>e.Some(t),flatMap:e=>e(t),flatMapAsync:async e=>await e(t),reduce:e=>e(void 0,t),reduceRight:e=>e(void 0,t),foldLeft:e=>n=>n(e,t),foldRight:e=>n=>n(t,e),toList:()=>r([t]),contains:e=>e===t,size:1,toOption:()=>s(t),toEither:e=>a(t),toTry:()=>n(()=>t),toPromise:()=>Promise.resolve(t),toString:()=>`Some(${o(t)})`,toValue:()=>({_tag:`Some`,value:t}),pipe:e=>e(t),serialize:()=>e(`Some`,t),doUnwrap(){return{ok:!0,value:t}}}),c={_tag:`None`,value:void 0,isEmpty:!0,isSome(){return!1},isNone(){return!0},orElse:e=>e,orThrow(e){throw e??Error(`Cannot extract value from None`)},or:e=>e,orNull:()=>null,orUndefined:()=>void 0,map:e=>c,ap:e=>c,filter(e){return c},count:e=>0,find:e=>c,exists:e=>!1,forEach:e=>{},flatMap:e=>c,flatMapAsync:e=>Promise.resolve(c),reduce:()=>void 0,reduceRight:()=>void 0,fold:(e,t)=>e(),match:e=>e.None(),foldLeft:e=>()=>e,foldRight:e=>()=>e,toList:()=>r([]),contains:()=>!1,size:0,toOption:()=>c,toEither:e=>i(e),toTry:()=>n(()=>{throw Error(`None`)}),toPromise:()=>Promise.reject(Error(`Cannot convert None to Promise`)),toString:()=>`None`,toValue:()=>({_tag:`None`,value:void 0}),pipe:e=>e(void 0),serialize:()=>e(`None`,null),doUnwrap(){return{ok:!1,empty:!0}}},l=()=>c,u=e=>e==null?l():s(e),d={from:e=>f(e),none:()=>l(),isSome:e=>e.isSome(),isNone:e=>e.isNone(),fromJSON:e=>{let t=JSON.parse(e);return t._tag===`Some`?s(t.value):l()},fromYAML:e=>{let t=e.split(`
1
+ import{rt as e}from"../Valuable-BlffnwkD.js";import{t}from"../Companion-VlxcFhzb.js";import{Try as n}from"../try/index.js";import{List as r}from"../list/index.js";import{Left as i,Right as a}from"../either/index.js";import o from"safe-stable-stringify";const s=t=>({_tag:`Some`,value:t,isEmpty:!1,isSome(){return!0},isNone(){return!1},orElse:()=>t,orThrow:()=>t,or:e=>s(t),orNull:()=>t,orUndefined:()=>t,map:e=>s(e(t)),ap:e=>e._tag===`Some`&&e.value?s(e.value(t)):c,filter(e){return e(t)?s(t):c},count:e=>e(t)?1:0,find:e=>e(t)?s(t):c,exists:e=>e(t),forEach:e=>e(t),fold:(e,n)=>n(t),match:e=>e.Some(t),flatMap:e=>e(t),flatMapAsync:async e=>await e(t),reduce:e=>e(void 0,t),reduceRight:e=>e(void 0,t),foldLeft:e=>n=>n(e,t),foldRight:e=>n=>n(t,e),toList:()=>r([t]),contains:e=>e===t,size:1,toOption:()=>s(t),toEither:e=>a(t),toTry:()=>n(()=>t),toPromise:()=>Promise.resolve(t),toString:()=>`Some(${o(t)})`,toValue:()=>({_tag:`Some`,value:t}),pipe:e=>e(t),serialize:()=>e(`Some`,t),doUnwrap(){return{ok:!0,value:t}}}),c={_tag:`None`,value:void 0,isEmpty:!0,isSome(){return!1},isNone(){return!0},orElse:e=>e,orThrow(e){throw e??Error(`Cannot extract value from None`)},or:e=>e,orNull:()=>null,orUndefined:()=>void 0,map:e=>c,ap:e=>c,filter(e){return c},count:e=>0,find:e=>c,exists:e=>!1,forEach:e=>{},flatMap:e=>c,flatMapAsync:e=>Promise.resolve(c),reduce:()=>void 0,reduceRight:()=>void 0,fold:(e,t)=>e(),match:e=>e.None(),foldLeft:e=>()=>e,foldRight:e=>()=>e,toList:()=>r([]),contains:()=>!1,size:0,toOption:()=>c,toEither:e=>i(e),toTry:()=>n(()=>{throw Error(`None`)}),toPromise:()=>Promise.reject(Error(`Cannot convert None to Promise`)),toString:()=>`None`,toValue:()=>({_tag:`None`,value:void 0}),pipe:e=>e(void 0),serialize:()=>e(`None`,null),doUnwrap(){return{ok:!1,empty:!0}}},l=()=>c,u=e=>e==null?l():s(e),d={from:e=>f(e),none:()=>l(),isSome:e=>e.isSome(),isNone:e=>e.isNone(),fromJSON:e=>{let t=JSON.parse(e);return t._tag===`Some`?s(t.value):l()},fromYAML:e=>{let t=e.split(`
2
2
  `),n=t[0]?.split(`: `)[1],r=t[1]?.split(`: `)[1];if(!n||!r)return l();let i=r===`null`?null:JSON.parse(r);return n===`Some`?s(i):l()},fromBinary:e=>{let t=Buffer.from(e,`base64`).toString();return d.fromJSON(t)}},f=t(u,d);export{l as None,f as Option,u as OptionConstructor,s as Some};
package/dist/set/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{et as e,rt as t}from"../Valuable-B8h0iKI_.js";import{t as n}from"../Companion-VlxcFhzb.js";import{Option as r}from"../option/index.js";import{List as i}from"../list/index.js";const a=n=>{let o=new e(n),s={_tag:`Set`,[Symbol.iterator]:()=>o[Symbol.iterator](),add:e=>a([...o,e]),remove:t=>{let n=new e(o);return n.delete(t),a(n)},contains:e=>o.has(e),has:e=>o.has(e),map:e=>a(Array.from(o).map(e)),ap:t=>{let n=new e;for(let e of o)for(let r of t)n.add(r(e));return a(n)},flatMap:t=>{let n=new e;for(let e of o)for(let r of t(e))n.add(r);return a(n)},flatMapAsync:async t=>{let n=new e;for(let e of o){let r=await t(e);for(let e of r)n.add(e)}return a(n)},fold:(e,t)=>{if(o.size===0)return e();let n=Array.from(o);if(n.length===0)return e();let r=n[0];return r===void 0?e():t(r)},foldLeft:e=>t=>{let n=e;for(let e of o)n=t(n,e);return n},foldRight:e=>t=>Array.from(o).reduceRight((e,n)=>t(n,e),e),get size(){return o.size},get isEmpty(){return o.size===0},reduce:e=>{let t=Array.from(o);if(t.length===0)throw Error(`Cannot reduce empty Set`);return t.reduce(e)},reduceRight:e=>{let t=Array.from(o);if(t.length===0)throw Error(`Cannot reduceRight empty Set`);return t.reduceRight(e)},count:e=>{let t=0;for(let n of o)e(n)&&t++;return t},find:e=>{for(let t of o)if(e(t))return r(t);return r(null)},exists:e=>{for(let t of o)if(e(t))return!0;return!1},forEach:e=>{o.forEach(e)},filter:t=>{let n=new e;for(let e of o)t(e)&&n.add(e);return a(n)},filterNot:t=>{let n=new e;for(let e of o)t(e)||n.add(e);return a(n)},drop:e=>a(Array.from(o).slice(e)),dropRight:e=>a(Array.from(o).slice(0,-e)),dropWhile:e=>{let t=Array.from(o),n=t.findIndex(t=>!e(t));return a(n===-1?[]:t.slice(n))},flatten:()=>{let t=new e;for(let e of o)if(Array.isArray(e))for(let n of e)t.add(n);else if(e&&typeof e==`object`&&Symbol.iterator in e)for(let n of e)t.add(n);else t.add(e);return a(t)},get head(){return Array.from(o)[0]},get headOption(){let e=Array.from(o)[0];return r(e)},take:e=>a(Array.from(o).slice(0,Math.max(0,e))),takeWhile:e=>{let t=Array.from(o),n=[];for(let r of t){if(!e(r))break;n.push(r)}return a(n)},takeRight:e=>{let t=Array.from(o);return a(e<=0?[]:t.slice(-e))},get last(){let e=Array.from(o);return e[e.length-1]},get lastOption(){let e=Array.from(o);return r(e[e.length-1])},get tail(){return a(Array.from(o).slice(1))},get init(){let e=Array.from(o);return a(e.length===0?[]:e.slice(0,-1))},toList:()=>i(Array.from(o)),toSet:()=>s,toArray:()=>Array.from(o),toString:()=>`Set(${Array.from(o).toString()})`,toValue:()=>({_tag:`Set`,value:Array.from(o)}),pipe:e=>e(Array.from(o)),serialize:()=>t(`Set`,Array.from(o))};return s},o=e=>a(e),s=a([]),c={empty:()=>s,of:(...e)=>a(e),fromJSON:e=>l(JSON.parse(e).value),fromYAML:e=>{let t=e.split(`
1
+ import{et as e,rt as t}from"../Valuable-BlffnwkD.js";import{t as n}from"../Companion-VlxcFhzb.js";import{Option as r}from"../option/index.js";import{List as i}from"../list/index.js";const a=n=>{let o=new e(n),s={_tag:`Set`,[Symbol.iterator]:()=>o[Symbol.iterator](),add:e=>a([...o,e]),remove:t=>{let n=new e(o);return n.delete(t),a(n)},contains:e=>o.has(e),has:e=>o.has(e),map:e=>a(Array.from(o).map(e)),ap:t=>{let n=new e;for(let e of o)for(let r of t)n.add(r(e));return a(n)},flatMap:t=>{let n=new e;for(let e of o)for(let r of t(e))n.add(r);return a(n)},flatMapAsync:async t=>{let n=new e;for(let e of o){let r=await t(e);for(let e of r)n.add(e)}return a(n)},fold:(e,t)=>{if(o.size===0)return e();let n=Array.from(o);if(n.length===0)return e();let r=n[0];return r===void 0?e():t(r)},foldLeft:e=>t=>{let n=e;for(let e of o)n=t(n,e);return n},foldRight:e=>t=>Array.from(o).reduceRight((e,n)=>t(n,e),e),get size(){return o.size},get isEmpty(){return o.size===0},reduce:e=>{let t=Array.from(o);if(t.length===0)throw Error(`Cannot reduce empty Set`);return t.reduce(e)},reduceRight:e=>{let t=Array.from(o);if(t.length===0)throw Error(`Cannot reduceRight empty Set`);return t.reduceRight(e)},count:e=>{let t=0;for(let n of o)e(n)&&t++;return t},find:e=>{for(let t of o)if(e(t))return r(t);return r(null)},exists:e=>{for(let t of o)if(e(t))return!0;return!1},forEach:e=>{o.forEach(e)},filter:t=>{let n=new e;for(let e of o)t(e)&&n.add(e);return a(n)},filterNot:t=>{let n=new e;for(let e of o)t(e)||n.add(e);return a(n)},drop:e=>a(Array.from(o).slice(e)),dropRight:e=>a(Array.from(o).slice(0,-e)),dropWhile:e=>{let t=Array.from(o),n=t.findIndex(t=>!e(t));return a(n===-1?[]:t.slice(n))},flatten:()=>{let t=new e;for(let e of o)if(Array.isArray(e))for(let n of e)t.add(n);else if(e&&typeof e==`object`&&Symbol.iterator in e)for(let n of e)t.add(n);else t.add(e);return a(t)},get head(){return Array.from(o)[0]},get headOption(){let e=Array.from(o)[0];return r(e)},take:e=>a(Array.from(o).slice(0,Math.max(0,e))),takeWhile:e=>{let t=Array.from(o),n=[];for(let r of t){if(!e(r))break;n.push(r)}return a(n)},takeRight:e=>{let t=Array.from(o);return a(e<=0?[]:t.slice(-e))},get last(){let e=Array.from(o);return e[e.length-1]},get lastOption(){let e=Array.from(o);return r(e[e.length-1])},get tail(){return a(Array.from(o).slice(1))},get init(){let e=Array.from(o);return a(e.length===0?[]:e.slice(0,-1))},toList:()=>i(Array.from(o)),toSet:()=>s,toArray:()=>Array.from(o),toString:()=>`Set(${Array.from(o).toString()})`,toValue:()=>({_tag:`Set`,value:Array.from(o)}),pipe:e=>e(Array.from(o)),serialize:()=>t(`Set`,Array.from(o))};return s},o=e=>a(e),s=a([]),c={empty:()=>s,of:(...e)=>a(e),fromJSON:e=>l(JSON.parse(e).value),fromYAML:e=>{let t=e.split(`
2
2
  `)[1]?.split(`: `)[1];return l(t?JSON.parse(t):[])},fromBinary:e=>{let t=Buffer.from(e,`base64`).toString();return c.fromJSON(t)}},l=n(o,c);export{l as Set};
package/dist/try/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{rt as e,tt as t}from"../Valuable-B8h0iKI_.js";import{t as n}from"../Companion-VlxcFhzb.js";import{None as r,Option as i,Some as a}from"../option/index.js";import{List as o}from"../list/index.js";import{Left as s,Right as c}from"../either/index.js";import l from"safe-stable-stringify";const u=t=>({_tag:`Success`,error:void 0,isSuccess(){return!0},isFailure(){return!1},orElse:e=>t,orThrow:e=>t,or:e=>u(t),orNull:()=>t,orUndefined:()=>t,toEither:e=>c(t),map:e=>m(()=>e(t)),ap:e=>e.map(e=>e(t)),flatMap:e=>e(t),flatMapAsync:async e=>e(t),fold:(e,n)=>n(t),match:e=>e.Success(t),foldLeft:e=>n=>n(e,t),foldRight:e=>n=>n(t,e),toString:()=>`Success(${l(t)})`,toPromise:()=>Promise.resolve(t),toValue:()=>({_tag:`Success`,value:t}),toOption:()=>a(t),toList:()=>o([t]),toTry:()=>u(t),pipe:e=>e(t),serialize:()=>e(`Success`,t),get size(){return 1},get isEmpty(){return!1},contains:e=>t===e,reduce:e=>t,reduceRight:e=>t,count:e=>e(t)?1:0,find:e=>e(t)?i(t):i(void 0),exists:e=>e(t),forEach:e=>e(t),doUnwrap(){return{ok:!0,value:t}}}),d=e=>({_tag:`Failure`,error:e,isSuccess(){return!1},isFailure(){return!0},orElse:e=>e,orThrow:t=>{throw t??e},or:e=>e,orNull:()=>null,orUndefined:()=>void 0,toEither:t=>s(e),map:t=>d(e),ap:t=>d(e),flatMap:t=>d(e),flatMapAsync:t=>Promise.resolve(d(e)),fold:(t,n)=>t(e),match:t=>t.Failure(e),foldLeft:e=>t=>e,foldRight:e=>t=>e,toString:()=>`Failure(${l(e)}))`,toPromise:()=>Promise.reject(e),toValue:()=>({_tag:`Failure`,value:e}),toOption:()=>r(),toList:()=>o([]),toTry:()=>d(e),pipe:t=>{throw e},serialize:()=>t({_tag:`Failure`,error:e.message,stack:e.stack}),get size(){return 0},get isEmpty(){return!0},contains:e=>!1,reduce:e=>{throw Error(`Cannot reduce a Failure`)},reduceRight:e=>{throw Error(`Cannot reduceRight a Failure`)},count:e=>0,find:e=>i(null),exists:e=>!1,forEach:e=>{},doUnwrap(){return{ok:!1,empty:!1,error:e}}}),f=e=>{try{return u(e())}catch(e){return d(e instanceof Error?e:Error(String(e)))}},p={isSuccess:e=>e.isSuccess(),isFailure:e=>e.isFailure(),fromJSON:e=>{let t=JSON.parse(e);if(t._tag===`Success`)return u(t.value);{let e=Error(t.error);return t.stack&&(e.stack=t.stack),d(e)}},fromYAML:e=>{let t=e.split(`
1
+ import{rt as e,tt as t}from"../Valuable-BlffnwkD.js";import{t as n}from"../Companion-VlxcFhzb.js";import{None as r,Option as i,Some as a}from"../option/index.js";import{List as o}from"../list/index.js";import{Left as s,Right as c}from"../either/index.js";import l from"safe-stable-stringify";const u=t=>({_tag:`Success`,error:void 0,isSuccess(){return!0},isFailure(){return!1},orElse:e=>t,orThrow:e=>t,or:e=>u(t),orNull:()=>t,orUndefined:()=>t,toEither:e=>c(t),map:e=>m(()=>e(t)),ap:e=>e.map(e=>e(t)),flatMap:e=>e(t),flatMapAsync:async e=>e(t),fold:(e,n)=>n(t),match:e=>e.Success(t),foldLeft:e=>n=>n(e,t),foldRight:e=>n=>n(t,e),toString:()=>`Success(${l(t)})`,toPromise:()=>Promise.resolve(t),toValue:()=>({_tag:`Success`,value:t}),toOption:()=>a(t),toList:()=>o([t]),toTry:()=>u(t),pipe:e=>e(t),serialize:()=>e(`Success`,t),get size(){return 1},get isEmpty(){return!1},contains:e=>t===e,reduce:e=>t,reduceRight:e=>t,count:e=>e(t)?1:0,find:e=>e(t)?i(t):i(void 0),exists:e=>e(t),forEach:e=>e(t),doUnwrap(){return{ok:!0,value:t}}}),d=e=>({_tag:`Failure`,error:e,isSuccess(){return!1},isFailure(){return!0},orElse:e=>e,orThrow:t=>{throw t??e},or:e=>e,orNull:()=>null,orUndefined:()=>void 0,toEither:t=>s(e),map:t=>d(e),ap:t=>d(e),flatMap:t=>d(e),flatMapAsync:t=>Promise.resolve(d(e)),fold:(t,n)=>t(e),match:t=>t.Failure(e),foldLeft:e=>t=>e,foldRight:e=>t=>e,toString:()=>`Failure(${l(e)}))`,toPromise:()=>Promise.reject(e),toValue:()=>({_tag:`Failure`,value:e}),toOption:()=>r(),toList:()=>o([]),toTry:()=>d(e),pipe:t=>{throw e},serialize:()=>t({_tag:`Failure`,error:e.message,stack:e.stack}),get size(){return 0},get isEmpty(){return!0},contains:e=>!1,reduce:e=>{throw Error(`Cannot reduce a Failure`)},reduceRight:e=>{throw Error(`Cannot reduceRight a Failure`)},count:e=>0,find:e=>i(null),exists:e=>!1,forEach:e=>{},doUnwrap(){return{ok:!1,empty:!1,error:e}}}),f=e=>{try{return u(e())}catch(e){return d(e instanceof Error?e:Error(String(e)))}},p={isSuccess:e=>e.isSuccess(),isFailure:e=>e.isFailure(),fromJSON:e=>{let t=JSON.parse(e);if(t._tag===`Success`)return u(t.value);{let e=Error(t.error);return t.stack&&(e.stack=t.stack),d(e)}},fromYAML:e=>{let t=e.split(`
2
2
  `),n=t[0]?.split(`: `)[1];if(!n)return d(Error(`Invalid YAML format for Try`));if(n===`Success`){let e=t[1]?.split(`: `)[1];return e?u(JSON.parse(e)):d(Error(`Invalid YAML format for Try Success`))}else{let e=t[1]?.split(`: `)[1];if(!e)return d(Error(`Invalid YAML format for Try Failure`));let n=t[2]?.split(`: `),r=n&&n.length>1?n.slice(1).join(`: `):void 0,i=Error(e);return r&&(i.stack=r),d(i)}},fromBinary:e=>{let t=Buffer.from(e,`base64`).toString();return p.fromJSON(t)}},m=n(f,p);export{m as Try};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functype",
3
- "version": "0.46.0",
3
+ "version": "0.46.1",
4
4
  "type": "module",
5
5
  "description": "A functional programming library for TypeScript, using immutable data structures and type classes",
6
6
  "author": "jordan.burke@gmail.com",