@fncts/typelevel 0.0.3 → 0.0.6

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/Check.d.ts CHANGED
@@ -27,7 +27,7 @@ export declare namespace Check {
27
27
  /**
28
28
  * @tsplus type fncts.Check.Extends
29
29
  */
30
- type Extends<A, B> = [A] extends [never] ? never : [A] extends [B] ? unknown : never;
30
+ type Extends<A, B> = [A] extends [B] ? unknown : never;
31
31
  /**
32
32
  * @tsplus type fncts.Check.IsUnion
33
33
  */
@@ -39,11 +39,11 @@ export declare namespace Check {
39
39
  /**
40
40
  * @tsplus type fncts.Check.IsLiteral
41
41
  */
42
- type IsLiteral<A extends string | number> = Not<Extends<string, A> | Extends<number, A>>;
42
+ type IsLiteral<A extends string | number | boolean> = Not<Extends<string, A> | Extends<number, A> | Extends<boolean, A>>;
43
43
  /**
44
44
  * @tsplus type fncts.Check.IsStruct
45
45
  */
46
- type IsStruct<A> = Extends<keyof A, string> & Not<IsUnion<A>>;
46
+ type IsStruct<A> = Check.Extends<keyof A, string> & Check.Not<Check.IsUnion<A>>;
47
47
  /**
48
48
  * @tsplus type fncts.Check.HaveSameLength
49
49
  */
package/HKT.d.ts CHANGED
@@ -1,186 +1,149 @@
1
1
  import type * as Union from "./Union.js";
2
- export interface HKT {
3
- readonly K?: unknown;
4
- readonly Q?: unknown;
5
- readonly W?: unknown;
6
- readonly X?: unknown;
7
- readonly I?: unknown;
8
- readonly S?: unknown;
9
- readonly R?: unknown;
10
- readonly E?: unknown;
11
- readonly A?: unknown;
12
- readonly type?: unknown;
13
- readonly index?: unknown;
14
- readonly variance: {
15
- readonly K?: HKT.Variance;
16
- readonly Q?: HKT.Variance;
17
- readonly W?: HKT.Variance;
18
- readonly X?: HKT.Variance;
19
- readonly I?: HKT.Variance;
20
- readonly S?: HKT.Variance;
21
- readonly R?: HKT.Variance;
22
- readonly E?: HKT.Variance;
23
- readonly A?: HKT.Variance;
24
- };
25
- }
26
2
  export declare namespace HKT {
27
- const URI: unique symbol;
28
- const CURI: unique symbol;
29
- export type Variance = "-" | "+" | "_";
30
- export type VarianceOf<F extends HKT, N extends ParamName> = F["variance"][N];
31
- export type CovariantE = HKT & {
32
- readonly variance: {
33
- E: "+";
34
- };
35
- };
36
- export type ContravariantR = HKT & {
37
- readonly variance: {
38
- R: "-";
39
- };
40
- };
41
- export interface Typeclass<F extends HKT, C = None> {
42
- readonly [URI]: F;
43
- readonly [CURI]: C;
44
- }
45
- export interface Typeclass2<F extends HKT, G extends HKT, C = None, D = None> {
46
- readonly _F: F;
47
- readonly _G: G;
48
- readonly _CF: C;
49
- readonly _CG: D;
50
- }
51
- export interface Compose2<F extends HKT, G extends HKT, C = None, D = None> extends HKT {
52
- readonly type: Kind<F, C, this["K"], this["Q"], this["W"], this["X"], this["I"], this["S"], this["R"], this["E"], Kind<G, D, this["K"], this["Q"], this["W"], this["X"], this["I"], this["S"], this["R"], this["E"], this["A"]>>;
53
- }
54
- export interface FK<F, K, Q, W, X, I, S, R, E, A> {
55
- readonly _F: F;
56
- readonly _K: K;
57
- readonly _Q: Q;
58
- readonly _W: W;
59
- readonly _X: X;
60
- readonly _I: I;
61
- readonly _S: S;
62
- readonly _R: R;
63
- readonly _E: E;
64
- readonly _A: A;
65
- }
66
- export interface FK1<F, A> {
67
- readonly _F: F;
68
- readonly _K: unknown;
69
- readonly _Q: unknown;
70
- readonly _W: unknown;
71
- readonly _X: unknown;
72
- readonly _I: unknown;
73
- readonly _S: unknown;
74
- readonly _R: unknown;
75
- readonly _E: unknown;
76
- readonly _A: A;
77
- }
78
- export interface F<F> extends HKT {
79
- readonly type: FK<F, this["K"], this["Q"], this["W"], this["X"], this["I"], this["S"], this["R"], this["E"], this["A"]>;
80
- readonly variance: {
81
- readonly K: "_";
82
- readonly Q: "_";
83
- readonly W: "_";
84
- readonly X: "_";
85
- readonly I: "_";
86
- readonly S: "_";
87
- readonly R: "_";
88
- readonly E: "_";
89
- readonly A: "_";
90
- };
91
- }
92
- export interface FCoE<F> extends HKT {
93
- readonly type: FK<F, this["K"], this["Q"], this["W"], this["X"], this["I"], this["S"], this["R"], this["E"], this["A"]>;
94
- readonly variance: {
95
- readonly K: "_";
96
- readonly Q: "_";
97
- readonly W: "_";
98
- readonly X: "_";
99
- readonly I: "_";
100
- readonly S: "_";
101
- readonly R: "_";
102
- readonly E: "+";
103
- readonly A: "_";
104
- };
105
- }
106
- export interface FContraR<F> extends HKT {
107
- readonly type: FK<F, this["K"], this["Q"], this["W"], this["X"], this["I"], this["S"], this["R"], this["E"], this["A"]>;
108
- readonly variance: {
109
- readonly K: "_";
110
- readonly Q: "_";
111
- readonly W: "_";
112
- readonly X: "_";
113
- readonly I: "_";
114
- readonly S: "_";
115
- readonly R: "-";
116
- readonly E: "_";
117
- readonly A: "_";
118
- };
119
- }
120
- export type ParamName = "K" | "Q" | "W" | "X" | "I" | "S" | "R" | "E" | "A";
121
- export type Kind<F extends HKT, C, K, Q, W, X, I, S, R, E, A> = F extends {
122
- readonly type: unknown;
123
- } ? (F & {
124
- readonly K: OrFix<C, "K", K>;
125
- readonly Q: OrFix<C, "Q", Q>;
126
- readonly W: OrFix<C, "W", W>;
127
- readonly X: OrFix<C, "X", X>;
128
- readonly I: OrFix<C, "I", I>;
129
- readonly S: OrFix<C, "S", S>;
130
- readonly R: OrFix<C, "R", R>;
131
- readonly E: OrFix<C, "E", E>;
132
- readonly A: A;
133
- })["type"] : FK<F, K, Q, W, X, I, S, R, E, A>;
134
- export type Infer<F extends HKT, C, N extends ParamName | "C", K> = [K] extends [
135
- Kind<F, C, infer K, infer Q, infer W, infer X, infer I, infer S, infer R, infer E, infer A>
136
- ] ? N extends "C" ? C : N extends "K" ? K : N extends "Q" ? Q : N extends "W" ? W : N extends "X" ? X : N extends "I" ? I : N extends "S" ? S : N extends "R" ? R : N extends "E" ? E : N extends "A" ? A : never : never;
137
- export interface Lows {
138
- "-": unknown;
139
- "+": never;
140
- _: any;
141
- }
142
- export type Low<F extends HKT, N extends ParamName> = F["variance"][N] extends Variance ? Lows[F["variance"][N]] : never;
143
- export interface Mixes<P extends ReadonlyArray<unknown>> {
144
- "-": P extends [any] ? P[0] : P extends [any, any] ? P[0] & P[1] : P extends [any, any, any] ? P[0] & P[1] & P[2] : P extends [any, any, any, any] ? P[0] & P[1] & P[2] & P[3] : P extends [any, any, any, any, any] ? P[0] & P[1] & P[2] & P[3] & P[4] : Union.IntersectionOf<P[number]>;
145
- "+": P[number];
146
- _: P[0];
147
- }
148
- export type Mix<F extends HKT, N extends ParamName, P extends ReadonlyArray<unknown>> = F["variance"][N] extends Variance ? Mixes<P>[F["variance"][N]] : P[0];
149
- export type OrNever<K> = unknown extends K ? never : K;
150
- export type MixStruct<F extends HKT, N extends ParamName, X, Y> = F["variance"][N] extends "_" ? X : F["variance"][N] extends "+" ? Y[keyof Y] : F["variance"][N] extends "-" ? Union.IntersectionOf<{
151
- [k in keyof Y]: OrNever<Y[k]>;
152
- }[keyof Y]> : X;
153
- export interface Intros<A, B> {
154
- "-": B;
155
- "+": B;
156
- _: A;
157
- }
158
- export type Intro<F extends HKT, N extends ParamName, A, B> = F["variance"][N] extends Variance ? Intros<A, B>[F["variance"][N]] : A;
3
+ const F: unique symbol;
4
+ type F = typeof F;
5
+ const K: unique symbol;
6
+ type K = typeof K;
7
+ const Q: unique symbol;
8
+ type Q = typeof Q;
9
+ const W: unique symbol;
10
+ type W = typeof W;
11
+ const X: unique symbol;
12
+ type X = typeof X;
13
+ const I: unique symbol;
14
+ type I = typeof I;
15
+ const S: unique symbol;
16
+ type S = typeof S;
17
+ const R: unique symbol;
18
+ type R = typeof R;
19
+ const E: unique symbol;
20
+ type E = typeof E;
21
+ const A: unique symbol;
22
+ type A = typeof A;
23
+ const T: unique symbol;
24
+ type T = typeof T;
25
+ const Ix: unique symbol;
26
+ type Ix = typeof Ix;
27
+ const C: unique symbol;
28
+ type C = typeof C;
29
+ type _K<X extends HKT> = X extends {
30
+ [K]?: () => infer K;
31
+ } ? K : never;
32
+ type _Q<X extends HKT> = X extends {
33
+ [Q]?: (_: infer Q) => void;
34
+ } ? Q : never;
35
+ type _W<X extends HKT> = X extends {
36
+ [W]?: () => infer W;
37
+ } ? W : never;
38
+ type _X<X extends HKT> = X extends {
39
+ [X]?: () => infer X;
40
+ } ? X : never;
41
+ type _I<X extends HKT> = X extends {
42
+ [I]?: (_: infer I) => void;
43
+ } ? I : never;
44
+ type _S<X extends HKT> = X extends {
45
+ [S]?: () => infer S;
46
+ } ? S : never;
47
+ type _R<X extends HKT> = X extends {
48
+ [R]?: (_: infer R) => void;
49
+ } ? R : never;
50
+ type _E<X extends HKT> = X extends {
51
+ [E]?: () => infer E;
52
+ } ? E : never;
53
+ type _A<X extends HKT> = [X] extends [{
54
+ [A]?: () => infer A;
55
+ }] ? A : never;
56
+ type _Ix<X extends HKT> = X extends {
57
+ [Ix]?: infer Ix;
58
+ } ? Ix : never;
59
+ type IndexFor<X extends HKT, K> = X extends {
60
+ [Ix]?: infer Ix;
61
+ } ? Ix : K;
159
62
  /**
160
- * Type parameter constraint
63
+ * @tsplus type fncts.Kind
161
64
  */
162
- export type None = {};
163
- const Fix: unique symbol;
164
- export interface Fix<N extends ParamName, A> {
165
- [Fix]: {
166
- [K in N]: () => A;
167
- };
168
- }
169
- const Extend: unique symbol;
170
- export interface Extend<N extends ParamName, A> {
171
- [Extend]: {
172
- [K in N]: () => A;
173
- };
174
- }
175
- export type OrFix<C, N extends ParamName, A> = C extends Fix<N, infer X> ? X : A;
176
- export type OrExtend<C, N extends ParamName, A> = C extends Extend<N, infer X> ? A extends X ? A : X : A;
177
- export type GetExtends<C, N extends ParamName, A> = C extends Extend<N, infer X> ? X : A;
178
- export type IndexFor<F extends HKT, K> = F extends {
179
- readonly index: unknown;
180
- } ? F["index"] : K;
65
+ type Kind<F extends HKT, K, Q, W, X, I, S, R, E, A> = F & {
66
+ [F]?: F;
67
+ [K]?: () => K;
68
+ [Q]?: (_: Q) => void;
69
+ [W]?: () => W;
70
+ [X]?: () => X;
71
+ [I]?: (_: I) => void;
72
+ [S]?: () => S;
73
+ [R]?: (_: R) => void;
74
+ [E]?: () => E;
75
+ [A]?: () => A;
76
+ } extends {
77
+ [T]?: infer X;
78
+ } ? X : {
79
+ [F]?: F;
80
+ [K]?: () => K;
81
+ [Q]?: (_: Q) => void;
82
+ [W]?: () => W;
83
+ [X]?: () => X;
84
+ [I]?: (_: I) => void;
85
+ [S]?: () => S;
86
+ [R]?: (_: R) => void;
87
+ [E]?: () => E;
88
+ [A]?: () => A;
89
+ };
181
90
  /**
182
- * @tsplus macro identity
91
+ * @tsplus type fncts.Typeclass
183
92
  */
184
- export function instance<F>(_: Omit<F, typeof URI | typeof CURI | "_F" | "_G" | "_CF" | "_CG">): F;
185
- export {};
93
+ interface Typeclass<F extends HKT> {
94
+ [HKT.F]?: F;
95
+ }
96
+ type ParamName = "K" | "Q" | "W" | "X" | "I" | "S" | "R" | "E" | "A";
97
+ type Mix<N extends ParamName, P extends ReadonlyArray<unknown>> = VarianceToMix<P>[ParamToVariance[N]];
98
+ type MixStruct<N extends ParamName, X, Y> = ParamToVariance[N] extends "_" ? X : ParamToVariance[N] extends "+" ? Y[keyof Y] : ParamToVariance[N] extends "-" ? Union.IntersectionOf<{
99
+ [K in keyof Y]: OrNever<Y[K]>;
100
+ }[keyof Y]> : X;
101
+ type Intro<N extends ParamName, A, B> = VarianceToIntro<A, B>[ParamToVariance[N]];
102
+ type Low<N extends ParamName> = VarianceToLow[ParamToVariance[N]];
103
+ type Infer<F extends HKT, N extends ParamName, K> = [K] extends [
104
+ Kind<F, infer K, infer Q, infer W, infer X, infer I, infer S, infer R, infer E, infer A>
105
+ ] ? N extends "K" ? K : N extends "Q" ? Q : N extends "W" ? W : N extends "X" ? X : N extends "I" ? I : N extends "S" ? S : N extends "R" ? R : N extends "E" ? E : N extends "A" ? A : never : never;
106
+ type ErasedKind<F extends HKT> = HKT.Kind<F, any, any, any, any, any, any, any, any, any>;
107
+ }
108
+ export interface HKT {
109
+ [HKT.F]?: HKT;
110
+ [HKT.K]?: () => unknown;
111
+ [HKT.Q]?: (_: never) => void;
112
+ [HKT.W]?: () => unknown;
113
+ [HKT.X]?: () => unknown;
114
+ [HKT.I]?: (_: never) => void;
115
+ [HKT.S]?: () => unknown;
116
+ [HKT.R]?: (_: never) => void;
117
+ [HKT.E]?: () => unknown;
118
+ [HKT.A]?: () => unknown;
119
+ [HKT.T]?: unknown;
120
+ [HKT.Ix]?: unknown;
121
+ }
122
+ interface VarianceToMix<P extends ReadonlyArray<unknown>> {
123
+ "-": P extends [any] ? P[0] : P extends [any, any] ? P[0] & P[1] : P extends [any, any, any] ? P[0] & P[1] & P[2] : P extends [any, any, any, any] ? P[0] & P[1] & P[2] & P[3] : P extends [any, any, any, any, any] ? P[0] & P[1] & P[2] & P[3] & P[4] : Union.IntersectionOf<P[number]>;
124
+ "+": P[number];
125
+ _: P[0];
126
+ }
127
+ interface VarianceToIntro<A, B> {
128
+ "-": B;
129
+ "+": B;
130
+ _: A;
131
+ }
132
+ interface VarianceToLow {
133
+ "-": unknown;
134
+ "+": never;
135
+ _: any;
136
+ }
137
+ interface ParamToVariance {
138
+ K: "_";
139
+ Q: "-";
140
+ W: "+";
141
+ X: "+";
142
+ I: "_";
143
+ S: "_";
144
+ R: "-";
145
+ E: "+";
146
+ A: "+";
186
147
  }
148
+ declare type OrNever<K> = unknown extends K ? never : K;
149
+ export {};
package/_cjs/HKT.cjs CHANGED
@@ -4,23 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.HKT = void 0;
7
- // eslint-disable-next-line @typescript-eslint/no-namespace
8
7
  var HKT;
9
8
  exports.HKT = HKT;
10
9
 
11
- (function (HKT) {
12
- /*
13
- * Instance util
14
- */
15
-
16
- /**
17
- * @tsplus macro identity
18
- */
19
- function instance(_) {
20
- // @ts-expect-error: typelevel utility
21
- return _;
22
- }
23
-
24
- HKT.instance = instance;
25
- })(HKT || (exports.HKT = HKT = {}));
10
+ (function (HKT) {})(HKT || (exports.HKT = HKT = {}));
26
11
  //# sourceMappingURL=HKT.cjs.map
package/_cjs/HKT.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"HKT.cjs","names":["HKT","instance","_"],"sources":["../esm/HKT.js"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-namespace\nexport var HKT;\n(function (HKT) {\n /*\n * Instance util\n */\n /**\n * @tsplus macro identity\n */\n function instance(_) {\n // @ts-expect-error: typelevel utility\n return _;\n }\n HKT.instance = instance;\n})(HKT || (HKT = {}));\n"],"mappings":";;;;;;AAAA;AACO,IAAIA,GAAJ;;;AACP,CAAC,UAAUA,GAAV,EAAe;EACZ;AACJ;AACA;;EACI;AACJ;AACA;EACI,SAASC,QAAT,CAAkBC,CAAlB,EAAqB;IACjB;IACA,OAAOA,CAAP;EACH;;EACDF,GAAG,CAACC,QAAJ,GAAeA,QAAf;AACH,CAZD,EAYGD,GAAG,mBAAKA,GAAG,GAAG,EAAX,CAZN"}
1
+ {"version":3,"file":"HKT.cjs","names":["HKT"],"sources":["../esm/HKT.js"],"sourcesContent":["export var HKT;\n(function (HKT) {\n})(HKT || (HKT = {}));\n"],"mappings":";;;;;;AAAO,IAAIA,GAAJ;;;AACP,CAAC,UAAUA,GAAV,EAAe,CACf,CADD,EACGA,GAAG,mBAAKA,GAAG,GAAG,EAAX,CADN"}
package/_mjs/HKT.mjs CHANGED
@@ -1,19 +1,4 @@
1
- // eslint-disable-next-line @typescript-eslint/no-namespace
2
1
  export var HKT;
3
2
 
4
- (function (HKT) {
5
- /*
6
- * Instance util
7
- */
8
-
9
- /**
10
- * @tsplus macro identity
11
- */
12
- function instance(_) {
13
- // @ts-expect-error: typelevel utility
14
- return _;
15
- }
16
-
17
- HKT.instance = instance;
18
- })(HKT || (HKT = {}));
3
+ (function (HKT) {})(HKT || (HKT = {}));
19
4
  //# sourceMappingURL=HKT.mjs.map
package/_mjs/HKT.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"HKT.mjs","names":["HKT","instance","_"],"sources":["../esm/HKT.js"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-namespace\nexport var HKT;\n(function (HKT) {\n /*\n * Instance util\n */\n /**\n * @tsplus macro identity\n */\n function instance(_) {\n // @ts-expect-error: typelevel utility\n return _;\n }\n HKT.instance = instance;\n})(HKT || (HKT = {}));\n"],"mappings":"AAAA;AACA,OAAO,IAAIA,GAAJ;;AACP,CAAC,UAAUA,GAAV,EAAe;EACZ;AACJ;AACA;;EACI;AACJ;AACA;EACI,SAASC,QAAT,CAAkBC,CAAlB,EAAqB;IACjB;IACA,OAAOA,CAAP;EACH;;EACDF,GAAG,CAACC,QAAJ,GAAeA,QAAf;AACH,CAZD,EAYGD,GAAG,KAAKA,GAAG,GAAG,EAAX,CAZN"}
1
+ {"version":3,"file":"HKT.mjs","names":["HKT"],"sources":["../esm/HKT.js"],"sourcesContent":["export var HKT;\n(function (HKT) {\n})(HKT || (HKT = {}));\n"],"mappings":"AAAA,OAAO,IAAIA,GAAJ;;AACP,CAAC,UAAUA,GAAV,EAAe,CACf,CADD,EACGA,GAAG,KAAKA,GAAG,GAAG,EAAX,CADN"}
package/_src/Check.ts CHANGED
@@ -36,7 +36,7 @@ export declare namespace Check {
36
36
  /**
37
37
  * @tsplus type fncts.Check.Extends
38
38
  */
39
- type Extends<A, B> = [A] extends [never] ? never : [A] extends [B] ? unknown : never;
39
+ type Extends<A, B> = [A] extends [B] ? unknown : never;
40
40
 
41
41
  /**
42
42
  * @tsplus type fncts.Check.IsUnion
@@ -55,12 +55,12 @@ export declare namespace Check {
55
55
  /**
56
56
  * @tsplus type fncts.Check.IsLiteral
57
57
  */
58
- type IsLiteral<A extends string | number> = Not<Extends<string, A> | Extends<number, A>>;
58
+ type IsLiteral<A extends string | number | boolean> = Not<Extends<string, A> | Extends<number, A> | Extends<boolean, A>>;
59
59
 
60
60
  /**
61
61
  * @tsplus type fncts.Check.IsStruct
62
62
  */
63
- type IsStruct<A> = Extends<keyof A, string> & Not<IsUnion<A>>;
63
+ type IsStruct<A> = Check.Extends<keyof A, string> & Check.Not<Check.IsUnion<A>>;
64
64
 
65
65
  /**
66
66
  * @tsplus type fncts.Check.HaveSameLength
package/_src/HKT.ts CHANGED
@@ -1,221 +1,103 @@
1
1
  import type * as Union from "./Union.js";
2
2
 
3
- export interface HKT {
4
- readonly K?: unknown;
5
- readonly Q?: unknown;
6
- readonly W?: unknown;
7
- readonly X?: unknown;
8
- readonly I?: unknown;
9
- readonly S?: unknown;
10
- readonly R?: unknown;
11
- readonly E?: unknown;
12
- readonly A?: unknown;
13
- readonly type?: unknown;
14
-
15
- readonly index?: unknown;
16
-
17
- readonly variance: {
18
- readonly K?: HKT.Variance;
19
- readonly Q?: HKT.Variance;
20
- readonly W?: HKT.Variance;
21
- readonly X?: HKT.Variance;
22
- readonly I?: HKT.Variance;
23
- readonly S?: HKT.Variance;
24
- readonly R?: HKT.Variance;
25
- readonly E?: HKT.Variance;
26
- readonly A?: HKT.Variance;
27
- };
28
- }
29
-
30
- // eslint-disable-next-line @typescript-eslint/no-namespace
31
3
  export namespace HKT {
32
- declare const URI: unique symbol;
33
- declare const CURI: unique symbol;
34
-
35
- export type Variance = "-" | "+" | "_";
36
-
37
- export type VarianceOf<F extends HKT, N extends ParamName> = F["variance"][N];
38
-
39
- export type CovariantE = HKT & {
40
- readonly variance: {
41
- E: "+";
42
- };
43
- };
44
-
45
- export type ContravariantR = HKT & {
46
- readonly variance: {
47
- R: "-";
48
- };
49
- };
4
+ export declare const F: unique symbol;
5
+ export type F = typeof F;
6
+ export declare const K: unique symbol;
7
+ export type K = typeof K;
8
+ export declare const Q: unique symbol;
9
+ export type Q = typeof Q;
10
+ export declare const W: unique symbol;
11
+ export type W = typeof W;
12
+ export declare const X: unique symbol;
13
+ export type X = typeof X;
14
+ export declare const I: unique symbol;
15
+ export type I = typeof I;
16
+ export declare const S: unique symbol;
17
+ export type S = typeof S;
18
+ export declare const R: unique symbol;
19
+ export type R = typeof R;
20
+ export declare const E: unique symbol;
21
+ export type E = typeof E;
22
+ export declare const A: unique symbol;
23
+ export type A = typeof A;
24
+ export declare const T: unique symbol;
25
+ export type T = typeof T;
26
+ export declare const Ix: unique symbol;
27
+ export type Ix = typeof Ix;
28
+ export declare const C: unique symbol;
29
+ export type C = typeof C;
30
+
31
+ export type _K<X extends HKT> = X extends { [K]?: () => infer K } ? K : never;
32
+ export type _Q<X extends HKT> = X extends { [Q]?: (_: infer Q) => void } ? Q : never;
33
+ export type _W<X extends HKT> = X extends { [W]?: () => infer W } ? W : never;
34
+ export type _X<X extends HKT> = X extends { [X]?: () => infer X } ? X : never;
35
+ export type _I<X extends HKT> = X extends { [I]?: (_: infer I) => void } ? I : never;
36
+ export type _S<X extends HKT> = X extends { [S]?: () => infer S } ? S : never;
37
+ export type _R<X extends HKT> = X extends { [R]?: (_: infer R) => void } ? R : never;
38
+ export type _E<X extends HKT> = X extends { [E]?: () => infer E } ? E : never;
39
+ export type _A<X extends HKT> = [X] extends [{ [A]?: () => infer A }] ? A : never;
40
+
41
+ export type _Ix<X extends HKT> = X extends { [Ix]?: infer Ix } ? Ix : never;
42
+
43
+ export type IndexFor<X extends HKT, K> = X extends { [Ix]?: infer Ix } ? Ix : K;
50
44
 
51
- export interface Typeclass<F extends HKT, C = None> {
52
- readonly [URI]: F;
53
- readonly [CURI]: C;
54
- }
55
-
56
- export interface Typeclass2<F extends HKT, G extends HKT, C = None, D = None> {
57
- readonly _F: F;
58
- readonly _G: G;
59
- readonly _CF: C;
60
- readonly _CG: D;
61
- }
62
-
63
- export interface Compose2<F extends HKT, G extends HKT, C = None, D = None> extends HKT {
64
- readonly type: Kind<
65
- F,
66
- C,
67
- this["K"],
68
- this["Q"],
69
- this["W"],
70
- this["X"],
71
- this["I"],
72
- this["S"],
73
- this["R"],
74
- this["E"],
75
- Kind<
76
- G,
77
- D,
78
- this["K"],
79
- this["Q"],
80
- this["W"],
81
- this["X"],
82
- this["I"],
83
- this["S"],
84
- this["R"],
85
- this["E"],
86
- this["A"]
87
- >
88
- >;
89
- }
90
-
91
- export interface FK<F, K, Q, W, X, I, S, R, E, A> {
92
- readonly _F: F;
93
- readonly _K: K;
94
- readonly _Q: Q;
95
- readonly _W: W;
96
- readonly _X: X;
97
- readonly _I: I;
98
- readonly _S: S;
99
- readonly _R: R;
100
- readonly _E: E;
101
- readonly _A: A;
102
- }
45
+ /**
46
+ * @tsplus type fncts.Kind
47
+ */
48
+ export type Kind<F extends HKT, K, Q, W, X, I, S, R, E, A> = F & {
49
+ [F]?: F;
50
+ [K]?: () => K;
51
+ [Q]?: (_: Q) => void;
52
+ [W]?: () => W;
53
+ [X]?: () => X;
54
+ [I]?: (_: I) => void;
55
+ [S]?: () => S;
56
+ [R]?: (_: R) => void;
57
+ [E]?: () => E;
58
+ [A]?: () => A;
59
+ } extends { [T]?: infer X }
60
+ ? X
61
+ : {
62
+ [F]?: F;
63
+ [K]?: () => K;
64
+ [Q]?: (_: Q) => void;
65
+ [W]?: () => W;
66
+ [X]?: () => X;
67
+ [I]?: (_: I) => void;
68
+ [S]?: () => S;
69
+ [R]?: (_: R) => void;
70
+ [E]?: () => E;
71
+ [A]?: () => A;
72
+ };
103
73
 
104
- export interface FK1<F, A> {
105
- readonly _F: F;
106
- readonly _K: unknown;
107
- readonly _Q: unknown;
108
- readonly _W: unknown;
109
- readonly _X: unknown;
110
- readonly _I: unknown;
111
- readonly _S: unknown;
112
- readonly _R: unknown;
113
- readonly _E: unknown;
114
- readonly _A: A;
74
+ /**
75
+ * @tsplus type fncts.Typeclass
76
+ */
77
+ export interface Typeclass<F extends HKT> {
78
+ [HKT.F]?: F;
115
79
  }
116
80
 
117
- export interface F<F> extends HKT {
118
- readonly type: FK<
119
- F,
120
- this["K"],
121
- this["Q"],
122
- this["W"],
123
- this["X"],
124
- this["I"],
125
- this["S"],
126
- this["R"],
127
- this["E"],
128
- this["A"]
129
- >;
130
- readonly variance: {
131
- readonly K: "_";
132
- readonly Q: "_";
133
- readonly W: "_";
134
- readonly X: "_";
135
- readonly I: "_";
136
- readonly S: "_";
137
- readonly R: "_";
138
- readonly E: "_";
139
- readonly A: "_";
140
- };
141
- }
81
+ export type ParamName = "K" | "Q" | "W" | "X" | "I" | "S" | "R" | "E" | "A";
142
82
 
143
- export interface FCoE<F> extends HKT {
144
- readonly type: FK<
145
- F,
146
- this["K"],
147
- this["Q"],
148
- this["W"],
149
- this["X"],
150
- this["I"],
151
- this["S"],
152
- this["R"],
153
- this["E"],
154
- this["A"]
155
- >;
156
- readonly variance: {
157
- readonly K: "_";
158
- readonly Q: "_";
159
- readonly W: "_";
160
- readonly X: "_";
161
- readonly I: "_";
162
- readonly S: "_";
163
- readonly R: "_";
164
- readonly E: "+";
165
- readonly A: "_";
166
- };
167
- }
83
+ export type Mix<N extends ParamName, P extends ReadonlyArray<unknown>> = VarianceToMix<P>[ParamToVariance[N]];
168
84
 
169
- export interface FContraR<F> extends HKT {
170
- readonly type: FK<
171
- F,
172
- this["K"],
173
- this["Q"],
174
- this["W"],
175
- this["X"],
176
- this["I"],
177
- this["S"],
178
- this["R"],
179
- this["E"],
180
- this["A"]
181
- >;
182
- readonly variance: {
183
- readonly K: "_";
184
- readonly Q: "_";
185
- readonly W: "_";
186
- readonly X: "_";
187
- readonly I: "_";
188
- readonly S: "_";
189
- readonly R: "-";
190
- readonly E: "_";
191
- readonly A: "_";
192
- };
193
- }
85
+ export type MixStruct<N extends ParamName, X, Y> = ParamToVariance[N] extends "_"
86
+ ? X
87
+ : ParamToVariance[N] extends "+"
88
+ ? Y[keyof Y]
89
+ : ParamToVariance[N] extends "-"
90
+ ? Union.IntersectionOf<{ [K in keyof Y]: OrNever<Y[K]> }[keyof Y]>
91
+ : X;
194
92
 
195
- export type ParamName = "K" | "Q" | "W" | "X" | "I" | "S" | "R" | "E" | "A";
93
+ export type Intro<N extends ParamName, A, B> = VarianceToIntro<A, B>[ParamToVariance[N]];
196
94
 
197
- export type Kind<F extends HKT, C, K, Q, W, X, I, S, R, E, A> = F extends {
198
- readonly type: unknown;
199
- }
200
- ? (F & {
201
- readonly K: OrFix<C, "K", K>;
202
- readonly Q: OrFix<C, "Q", Q>;
203
- readonly W: OrFix<C, "W", W>;
204
- readonly X: OrFix<C, "X", X>;
205
- readonly I: OrFix<C, "I", I>;
206
- readonly S: OrFix<C, "S", S>;
207
- readonly R: OrFix<C, "R", R>;
208
- readonly E: OrFix<C, "E", E>;
209
- readonly A: A;
210
- })["type"]
211
- : FK<F, K, Q, W, X, I, S, R, E, A>;
95
+ export type Low<N extends ParamName> = VarianceToLow[ParamToVariance[N]];
212
96
 
213
- export type Infer<F extends HKT, C, N extends ParamName | "C", K> = [K] extends [
214
- Kind<F, C, infer K, infer Q, infer W, infer X, infer I, infer S, infer R, infer E, infer A>,
97
+ export type Infer<F extends HKT, N extends ParamName, K> = [K] extends [
98
+ Kind<F, infer K, infer Q, infer W, infer X, infer I, infer S, infer R, infer E, infer A>,
215
99
  ]
216
- ? N extends "C"
217
- ? C
218
- : N extends "K"
100
+ ? N extends "K"
219
101
  ? K
220
102
  : N extends "Q"
221
103
  ? Q
@@ -236,114 +118,64 @@ export namespace HKT {
236
118
  : never
237
119
  : never;
238
120
 
239
- /*
240
- * Lower bounds for variance
241
- */
242
-
243
- export interface Lows {
244
- "-": unknown;
245
- "+": never;
246
- _: any;
247
- }
248
-
249
- export type Low<F extends HKT, N extends ParamName> = F["variance"][N] extends Variance
250
- ? Lows[F["variance"][N]]
251
- : never;
252
-
253
- /*
254
- * Type mixing for variance
255
- */
256
-
257
- export interface Mixes<P extends ReadonlyArray<unknown>> {
258
- "-": P extends [any]
259
- ? P[0]
260
- : P extends [any, any]
261
- ? P[0] & P[1]
262
- : P extends [any, any, any]
263
- ? P[0] & P[1] & P[2]
264
- : P extends [any, any, any, any]
265
- ? P[0] & P[1] & P[2] & P[3]
266
- : P extends [any, any, any, any, any]
267
- ? P[0] & P[1] & P[2] & P[3] & P[4]
268
- : Union.IntersectionOf<P[number]>;
269
- "+": P[number];
270
- _: P[0];
271
- }
272
- export type Mix<
273
- F extends HKT,
274
- N extends ParamName,
275
- P extends ReadonlyArray<unknown>,
276
- > = F["variance"][N] extends Variance ? Mixes<P>[F["variance"][N]] : P[0];
277
-
278
- export type OrNever<K> = unknown extends K ? never : K;
279
-
280
- export type MixStruct<F extends HKT, N extends ParamName, X, Y> = F["variance"][N] extends "_"
281
- ? X
282
- : F["variance"][N] extends "+"
283
- ? Y[keyof Y]
284
- : F["variance"][N] extends "-"
285
- ? Union.IntersectionOf<{ [k in keyof Y]: OrNever<Y[k]> }[keyof Y]>
286
- : X;
287
-
288
- export interface Intros<A, B> {
289
- "-": B;
290
- "+": B;
291
- _: A;
292
- }
293
-
294
- /*
295
- * Type introduction for variance
296
- */
297
-
298
- export type Intro<F extends HKT, N extends ParamName, A, B> = F["variance"][N] extends Variance
299
- ? Intros<A, B>[F["variance"][N]]
300
- : A;
301
-
302
- /**
303
- * Type parameter constraint
304
- */
305
-
306
- export type None = {};
307
-
308
- declare const Fix: unique symbol;
309
-
310
- export interface Fix<N extends ParamName, A> {
311
- [Fix]: {
312
- [K in N]: () => A;
313
- };
314
- }
315
-
316
- declare const Extend: unique symbol;
121
+ export type ErasedKind<F extends HKT> = HKT.Kind<F, any, any, any, any, any, any, any, any, any>;
122
+ }
317
123
 
318
- export interface Extend<N extends ParamName, A> {
319
- [Extend]: {
320
- [K in N]: () => A;
321
- };
322
- }
124
+ export interface HKT {
125
+ [HKT.F]?: HKT;
126
+ [HKT.K]?: () => unknown;
127
+ [HKT.Q]?: (_: never) => void;
128
+ [HKT.W]?: () => unknown;
129
+ [HKT.X]?: () => unknown;
130
+ [HKT.I]?: (_: never) => void;
131
+ [HKT.S]?: () => unknown;
132
+ [HKT.R]?: (_: never) => void;
133
+ [HKT.E]?: () => unknown;
134
+ [HKT.A]?: () => unknown;
135
+ [HKT.T]?: unknown;
136
+ [HKT.Ix]?: unknown;
137
+ }
323
138
 
324
- export type OrFix<C, N extends ParamName, A> = C extends Fix<N, infer X> ? X : A;
139
+ interface VarianceToMix<P extends ReadonlyArray<unknown>> {
140
+ "-": P extends [any]
141
+ ? P[0]
142
+ : P extends [any, any]
143
+ ? P[0] & P[1]
144
+ : P extends [any, any, any]
145
+ ? P[0] & P[1] & P[2]
146
+ : P extends [any, any, any, any]
147
+ ? P[0] & P[1] & P[2] & P[3]
148
+ : P extends [any, any, any, any, any]
149
+ ? P[0] & P[1] & P[2] & P[3] & P[4]
150
+ : Union.IntersectionOf<P[number]>;
151
+ "+": P[number];
152
+ _: P[0];
153
+ }
325
154
 
326
- export type OrExtend<C, N extends ParamName, A> = C extends Extend<N, infer X>
327
- ? A extends X
328
- ? A
329
- : X
330
- : A;
155
+ interface VarianceToIntro<A, B> {
156
+ "-": B;
157
+ "+": B;
158
+ _: A;
159
+ }
331
160
 
332
- export type GetExtends<C, N extends ParamName, A> = C extends Extend<N, infer X> ? X : A;
161
+ interface VarianceToLow {
162
+ "-": unknown;
163
+ "+": never;
164
+ _: any;
165
+ }
333
166
 
334
- export type IndexFor<F extends HKT, K> = F extends { readonly index: unknown } ? F["index"] : K;
167
+ interface ParamToVariance {
168
+ K: "_";
169
+ Q: "-";
170
+ W: "+";
171
+ X: "+";
172
+ I: "_";
173
+ S: "_";
174
+ R: "-";
175
+ E: "+";
176
+ A: "+";
177
+ }
335
178
 
336
- /*
337
- * Instance util
338
- */
179
+ type OrNever<K> = unknown extends K ? never : K;
339
180
 
340
- /**
341
- * @tsplus macro identity
342
- */
343
- export function instance<F>(
344
- _: Omit<F, typeof URI | typeof CURI | "_F" | "_G" | "_CF" | "_CG">,
345
- ): F {
346
- // @ts-expect-error: typelevel utility
347
- return _;
348
- }
349
- }
181
+ declare const Fix: unique symbol;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fncts/typelevel",
3
- "version": "0.0.3",
3
+ "version": "0.0.6",
4
4
  "exports": {
5
5
  "./*": {
6
6
  "import": "./_mjs/*.mjs",