@fncts/typelevel 0.0.10 → 0.0.13

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