functype 0.9.1 → 0.9.2
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.
- package/dist/{Either-BHep7I0d.d.ts → Either-i_F6B_IB.d.ts} +1 -1
- package/dist/{Serializable-BbKuhDDL.d.ts → Serializable-CK9upOU0.d.ts} +22 -4
- package/dist/{chunk-GHBOC52G.mjs → chunk-55TOOU3K.mjs} +3 -3
- package/dist/chunk-55TOOU3K.mjs.map +1 -0
- package/dist/either/index.d.ts +2 -2
- package/dist/either/index.mjs +1 -1
- package/dist/fpromise/index.d.ts +2 -2
- package/dist/fpromise/index.mjs +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.mjs +1 -1
- package/dist/list/index.d.ts +2 -2
- package/dist/list/index.mjs +1 -1
- package/dist/map/index.d.ts +2 -2
- package/dist/map/index.mjs +1 -1
- package/dist/option/index.d.ts +2 -2
- package/dist/option/index.mjs +1 -1
- package/dist/set/index.d.ts +2 -2
- package/dist/set/index.mjs +1 -1
- package/dist/try/index.d.ts +2 -2
- package/dist/try/index.mjs +1 -1
- package/dist/tuple/index.d.ts +1 -1
- package/package.json +1 -1
- package/dist/chunk-GHBOC52G.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as Type, a as Typeable, S as Serializable, F as Foldable, P as Pipe } from './Serializable-
|
|
1
|
+
import { T as Type, a as Typeable, S as Serializable, F as Foldable, P as Pipe } from './Serializable-CK9upOU0.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Creates a Some variant of Option containing a value.
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
type Type = unknown;
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Base interface for objects with a type tag
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
interface TypeableBase<Tag extends string> {
|
|
8
|
+
readonly _tag: Tag;
|
|
9
|
+
}
|
|
3
10
|
/**
|
|
4
11
|
* Parameters for creating a Typeable instance
|
|
5
12
|
* @internal
|
|
@@ -8,9 +15,13 @@ type TypeableParams<Tag extends string, T> = {
|
|
|
8
15
|
_tag: Tag;
|
|
9
16
|
impl: T;
|
|
10
17
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Utility type to extract the Tag from a Typeable type
|
|
20
|
+
* @typeParam T - The Typeable type to extract the tag from
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
type ExtractTag<T> = T extends Typeable<infer Tag, unknown> ? Tag : never;
|
|
24
|
+
type Typeable<Tag extends string, T = object> = T & TypeableBase<Tag>;
|
|
14
25
|
/**
|
|
15
26
|
* Core utility for creating nominal typing in TypeScript by adding a type tag to any object.
|
|
16
27
|
* This allows for creating distinct types that are structurally identical but considered different by TypeScript's type system.
|
|
@@ -21,6 +32,13 @@ type Typeable<Tag extends string, T = object> = T & {
|
|
|
21
32
|
* @typeParam T - The base type to extend with the tag
|
|
22
33
|
*/
|
|
23
34
|
declare function Typeable<Tag extends string, T>({ _tag, impl }: TypeableParams<Tag, T>): Typeable<Tag, T>;
|
|
35
|
+
/**
|
|
36
|
+
* Type guard with automatic type inference using the full type
|
|
37
|
+
* @param value - The value to check
|
|
38
|
+
* @param tag - The tag to check for
|
|
39
|
+
* @returns Whether the value is a Typeable with the specified tag
|
|
40
|
+
*/
|
|
41
|
+
declare function isTypeable<T>(value: unknown, tag: string): value is T;
|
|
24
42
|
|
|
25
43
|
/**
|
|
26
44
|
* Foldable type class represents data structures that can be folded to a summary value.
|
|
@@ -75,4 +93,4 @@ interface Serializable<T> {
|
|
|
75
93
|
serialize(): SerializationMethods<T>;
|
|
76
94
|
}
|
|
77
95
|
|
|
78
|
-
export { type Foldable as F, type Pipe as P, type Serializable as S, type Type as T, Typeable as a, type SerializationMethods as b };
|
|
96
|
+
export { type ExtractTag as E, type Foldable as F, type Pipe as P, type Serializable as S, type Type as T, Typeable as a, type SerializationMethods as b, type TypeableParams as c, isTypeable as i };
|
|
@@ -34,10 +34,10 @@ evaluated: true
|
|
|
34
34
|
value: ${se(r)}`:`_tag: Lazy
|
|
35
35
|
evaluated: false`,toBinary:()=>Buffer.from(JSON.stringify(t&&!o?{_tag:"Lazy",evaluated:true,value:r}:{_tag:"Lazy",evaluated:false})).toString("base64")}),typeable:"Lazy"}},Tt={of:e=>Y(e),fromValue:e=>Y(()=>e),fromOption:(e,t)=>Y(()=>e._tag==="Some"?e.value:t()),fromTry:e=>Y(()=>e.get()),fromEither:e=>Y(()=>e.fold(t=>{throw t},t=>t)),fromPromise:e=>Y(()=>{throw new Error("Promise not yet resolved. Use await on the promise before creating Lazy.")}),fail:e=>Y(()=>{throw e})},M=a(Y,Tt);var ie=Map;var W=e=>{let r={values:new ie(e)},n=()=>Array.from(r.values.entries()).map(([T,y])=>b$1([T,y])),o=T=>W(new ie(r.values).set(T.toArray()[0],T.toArray()[1]).entries()),a=T=>{let y=new ie(r.values);return y.delete(T)?W(y.entries()):W(r.values.entries())},s=T=>{let y=T.toArray();return r.values.get(y[0])===y[1]},i=()=>r.values.size,u=T=>W(Array.from(r.values.entries()).map(([y,_])=>[y,T(_)])),l=T=>{let y=W(r.values.entries()).toList();return W(y.flatMap(T).toArray())},E=T=>{let y=[];for(let[_,X]of r.values.entries()){let ae=T.get(_);ae._tag==="Some"&&ae.value&&y.push([_,ae.value(X)]);}return W(y)},g=async T=>{let y=new ie;for(let[_,X]of r.values.entries()){let ae=await T(X);for(let Je of ae.toList()){let[We,je]=Je.toArray();y.set(We,je);}}return W(y.entries())},F=T=>m(n()).reduce(T),v=T=>m(n()).reduceRight(T),A=T=>y=>m(n()).foldLeft(T)(y),G=T=>y=>m(n()).foldRight(T)(y),j=T=>f(r.values.get(T)),Z=(T,y)=>f(r.values.get(T)).getOrElse(y),oe=()=>r.values.size===0,ue=(T,y)=>f(r.values.get(T)).orElse(y),le=(T,y)=>{if(oe())return T();let _=n();if(_.length===0)return T();let X=_[0];return X===void 0?T():y(X)},be=()=>m(n()),d=()=>Q(n()),B=()=>`Map(${n().toString()})`,O=T=>oe()?T.Empty():T.NonEmpty(n());return {_tag:"Map",[Symbol.iterator]:()=>r.values.entries(),add:o,remove:a,contains:s,get size(){return i()},map:u,ap:E,flatMap:l,flatMapAsync:g,reduce:F,reduceRight:v,foldLeft:A,foldRight:G,fold:le,match:O,get:j,getOrElse:Z,get isEmpty(){return oe()},orElse:ue,toList:be,toSet:d,toString:B,toValue:()=>({_tag:"Map",value:Array.from(r.values.entries())}),pipe:T=>T(Array.from(r.values.entries())),serialize:()=>({toJSON:()=>JSON.stringify({_tag:"Map",value:Array.from(r.values.entries())}),toYAML:()=>`_tag: Map
|
|
36
36
|
value: ${JSON.stringify(Array.from(r.values.entries()))}`,toBinary:()=>Buffer.from(JSON.stringify({_tag:"Map",value:Array.from(r.values.entries())})).toString("base64")})}},ft=e=>W(e),Ce={fromJSON:e=>{let t=JSON.parse(e);return Re(t.value)},fromYAML:e=>{let r=e.split(`
|
|
37
|
-
`)[1]?.split(": ")[1];if(!r)return Re([]);let n=JSON.parse(r);return Re(n)},fromBinary:e=>{let t=Buffer.from(e,"base64").toString();return Ce.fromJSON(t)}},Re=a(ft,Ce);var dt={default:e=>t=>e(t),when:(e,t)=>r=>e(r)?t(r):void 0};function Le(e){let t=e;return {get(){return t},set(n){t=n;},update(n){t=n(t);},getAndSet(n){let o=t;return t=n,o},updateAndGet(n){return t=n(t),t},getAndUpdate(n){let o=t;return t=n(t),o},compareAndSet(n,o){return t===n?(t=o,true):false},modify(n){let[o,a]=n(t);return t=o,a}}}Le.of=Le;function
|
|
37
|
+
`)[1]?.split(": ")[1];if(!r)return Re([]);let n=JSON.parse(r);return Re(n)},fromBinary:e=>{let t=Buffer.from(e,"base64").toString();return Ce.fromJSON(t)}},Re=a(ft,Ce);var dt={default:e=>t=>e(t),when:(e,t)=>r=>e(r)?t(r):void 0};function Le(e){let t=e;return {get(){return t},set(n){t=n;},update(n){t=n(t);},getAndSet(n){let o=t;return t=n,o},updateAndGet(n){return t=n(t),t},getAndUpdate(n){let o=t;return t=n(t),o},compareAndSet(n,o){return t===n?(t=o,true):false},modify(n){let[o,a]=n(t);return t=o,a}}}Le.of=Le;function Vn(e){let t=ce({_tag:e._tag,impl:e.impl});return {...t,toValue:()=>({_tag:t._tag,value:e.value})}}var z=(e=[])=>{let t="Stack",r=[...e],n=()=>r.length,o=()=>r.length===0;return {_tag:t,get size(){return n()},get isEmpty(){return o()},contains:d=>r.includes(d),reduce:d=>{if(r.length===0)throw new Error("Cannot reduce an empty stack");return r.reduce(d)},reduceRight:d=>{if(r.length===0)throw new Error("Cannot reduce an empty stack");return r.reduceRight(d)},push:d=>z([...r,d]),pop:()=>{if(o())return [z([]),f(null)];let d=[...r],B=d.pop();return [z(d),f(B)]},peek:()=>o()?f(null):f(r[r.length-1]),map:d=>z(r.map(d)),flatMap:d=>o()?z([]):r.reduce((B,O)=>d(O).toArray().reduce((y,_)=>y.push(_),B),z([])),ap:d=>{let B=[];return r.forEach(O=>{d.toArray().forEach(T=>{B.push(T(O));});}),z(B)},flatMapAsync:async d=>o()?z([]):(await Promise.all(r.map(async O=>await d(O)))).reduce((O,T)=>T.toArray().reduce((y,_)=>y.push(_),O),z([])),toList:()=>m(r),toArray:()=>[...r],toString:()=>`Stack(${r.join(", ")})`,fold:(d,B)=>{if(o())return d();let O=r[r.length-1];return O!==void 0?B(O):d()},foldLeft:d=>B=>r.reduce(B,d),foldRight:d=>B=>r.reduceRight((O,T)=>B(T,O),d),match:d=>o()?d.Empty():d.NonEmpty([...r]),toValue:()=>({_tag:"Stack",value:r}),pipe:d=>d([...r]),serialize:()=>({toJSON:()=>JSON.stringify({_tag:"Stack",value:r}),toYAML:()=>`_tag: Stack
|
|
38
38
|
value: ${JSON.stringify(r)}`,toBinary:()=>Buffer.from(JSON.stringify({_tag:"Stack",value:r})).toString("base64")})}},yt=(e=[])=>z(e),$e={empty:()=>z([]),of:e=>z([e]),fromJSON:e=>{let t=JSON.parse(e);return xe(t.value)},fromYAML:e=>{let r=e.split(`
|
|
39
39
|
`)[1]?.split(": ")[1];if(!r)return xe([]);let n=JSON.parse(r);return xe(n)},fromBinary:e=>{let t=Buffer.from(e,"base64").toString();return $e.fromJSON(t)}},xe=a(yt,$e);var w=e=>({_tag:"Some",value:e,isEmpty:false,get:()=>e,getOrElse:()=>e,getOrThrow:()=>e,orElse:t=>w(e),orNull:()=>e,orUndefined:()=>e,map:t=>w(t(e)),ap:t=>t._tag==="Some"&&t.value?w(t.value(e)):D,filter(t){return t(e)?w(e):D},count:t=>t(e)?1:0,find:t=>t(e)?w(e):D,exists:t=>t(e),forEach:t=>t(e),fold:(t,r)=>r(e),match:t=>t.Some(e),flatMap:t=>t(e),flatMapAsync:async t=>await t(e),reduce:t=>t(void 0,e),reduceRight:t=>t(void 0,e),foldLeft:t=>r=>r(t,e),foldRight:t=>r=>r(e,t),toList:()=>m([e]),contains:t=>t===e,size:1,toEither:t=>c(e),toString:()=>`Some(${se(e)})`,toValue:()=>({_tag:"Some",value:e}),pipe:t=>t(e),serialize:()=>({toJSON:()=>JSON.stringify({_tag:"Some",value:e}),toYAML:()=>`_tag: Some
|
|
40
40
|
value: ${se(e)}`,toBinary:()=>Buffer.from(JSON.stringify({_tag:"Some",value:e})).toString("base64")})}),D={_tag:"None",value:void 0,isEmpty:true,get:()=>{throw new Error("Cannot call get() on None")},getOrElse:e=>e,getOrThrow(e){throw e},orElse:e=>e,orNull:()=>null,orUndefined:()=>{},map:e=>D,ap:e=>D,filter(e){return D},count:e=>0,find:e=>D,exists:e=>false,forEach:e=>{},flatMap:e=>D,flatMapAsync:async e=>D,reduce:()=>{},reduceRight:()=>{},fold:(e,t)=>e(),match:e=>e.None(),foldLeft:e=>()=>e,foldRight:e=>()=>e,toList:()=>m([]),contains:()=>false,size:0,toEither:e=>p(e),toString:()=>"None",toValue:()=>({_tag:"None",value:void 0}),pipe:e=>e(void 0),serialize:()=>({toJSON:()=>JSON.stringify({_tag:"None",value:null}),toYAML:()=>`_tag: None
|
|
41
41
|
value: null`,toBinary:()=>Buffer.from(JSON.stringify({_tag:"None",value:null})).toString("base64")})},b=()=>D,mt=e=>e!=null?w(e):b(),De={from:e=>f(e),none:()=>b(),fromJSON:e=>{let t=JSON.parse(e);return t._tag==="Some"?w(t.value):b()},fromYAML:e=>{let t=e.split(`
|
|
42
|
-
`),r=t[0]?.split(": ")[1],n=t[1]?.split(": ")[1];if(!r||!n)return b();let o=n==="null"?null:JSON.parse(n);return r==="Some"?w(o):b()},fromBinary:e=>{let t=Buffer.from(e,"base64").toString();return De.fromJSON(t)}},f=a(mt,De);export{
|
|
43
|
-
//# sourceMappingURL=chunk-
|
|
42
|
+
`),r=t[0]?.split(": ")[1],n=t[1]?.split(": ")[1];if(!r||!n)return b();let o=n==="null"?null:JSON.parse(n);return r==="Some"?w(o):b()},fromBinary:e=>{let t=Buffer.from(e,"base64").toString();return De.fromJSON(t)}},f=a(mt,De);export{S as $,Gt as A,Zt as B,Xt as C,er as D,nr as E,ir as F,te as G,Te as H,L as I,tt as J,ge as K,rt as L,Ne as M,_e as N,Ee as O,V as P,ze as Q,fe as R,kr as S,wr as T,Sr as U,x as V,Mr as W,Kr as X,pt as Y,Zr as Z,Ae as _,w as a,cn as aa,b,M as ba,mt as c,ie as ca,f as d,Re as da,Q as e,dt as ea,ce as f,Le as fa,ye as g,Vn as ga,m as h,xe as ha,c as i,p as j,It as k,Mt as l,zt as m,Qe as n,He as o,Ft as p,ve as q,I as r,Ge as s,Jt as t,Wt as u,jt as v,qt as w,Yt as x,Qt as y,Ht as z};//# sourceMappingURL=chunk-55TOOU3K.mjs.map
|
|
43
|
+
//# sourceMappingURL=chunk-55TOOU3K.mjs.map
|