@fncts/base 0.0.22 → 0.0.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. package/_cjs/collection/immutable/Conc/definition.cjs +6 -5
  2. package/_cjs/collection/immutable/Conc/definition.cjs.map +1 -1
  3. package/_cjs/collection/immutable/HashMap/definition.cjs +9 -6
  4. package/_cjs/collection/immutable/HashMap/definition.cjs.map +1 -1
  5. package/_cjs/collection/immutable/HashSet/definition.cjs +9 -6
  6. package/_cjs/collection/immutable/HashSet/definition.cjs.map +1 -1
  7. package/_cjs/collection/immutable/ImmutableArray/definition.cjs +7 -4
  8. package/_cjs/collection/immutable/ImmutableArray/definition.cjs.map +1 -1
  9. package/_cjs/collection/immutable/RoseTree/definition.cjs +7 -4
  10. package/_cjs/collection/immutable/RoseTree/definition.cjs.map +1 -1
  11. package/_cjs/collection/immutable/SortedMap/definition.cjs +3 -2
  12. package/_cjs/collection/immutable/SortedMap/definition.cjs.map +1 -1
  13. package/_cjs/collection/immutable/Vector/definition.cjs +7 -4
  14. package/_cjs/collection/immutable/Vector/definition.cjs.map +1 -1
  15. package/_cjs/control/Eval/definition.cjs +11 -5
  16. package/_cjs/control/Eval/definition.cjs.map +1 -1
  17. package/_cjs/control/Z/definition.cjs +16 -9
  18. package/_cjs/control/Z/definition.cjs.map +1 -1
  19. package/_cjs/data/CaseClass.cjs +1 -1
  20. package/_cjs/data/CaseClass.cjs.map +1 -1
  21. package/_cjs/data/Cause/api.cjs +26 -1
  22. package/_cjs/data/Cause/api.cjs.map +1 -1
  23. package/_cjs/data/Cause/definition.cjs +3 -1
  24. package/_cjs/data/Cause/definition.cjs.map +1 -1
  25. package/_cjs/data/Datum/definition.cjs +10 -9
  26. package/_cjs/data/Datum/definition.cjs.map +1 -1
  27. package/_cjs/data/DatumEither/definition.cjs.map +1 -1
  28. package/_cjs/data/DatumEither.cjs +28 -0
  29. package/_cjs/data/DatumEither.cjs.map +1 -0
  30. package/_cjs/data/DecodeError/definition.cjs +3 -1
  31. package/_cjs/data/DecodeError/definition.cjs.map +1 -1
  32. package/_cjs/data/Decoder/definition.cjs +4 -2
  33. package/_cjs/data/Decoder/definition.cjs.map +1 -1
  34. package/_cjs/data/Duration/definition.cjs +5 -4
  35. package/_cjs/data/Duration/definition.cjs.map +1 -1
  36. package/_cjs/data/Either/api.cjs +6 -6
  37. package/_cjs/data/Either/api.cjs.map +1 -1
  38. package/_cjs/data/Either/definition.cjs +7 -3
  39. package/_cjs/data/Either/definition.cjs.map +1 -1
  40. package/_cjs/data/Encoder/definition.cjs +3 -1
  41. package/_cjs/data/Encoder/definition.cjs.map +1 -1
  42. package/_cjs/data/Environment/api.cjs +5 -15
  43. package/_cjs/data/Environment/api.cjs.map +1 -1
  44. package/_cjs/data/Environment/definition.cjs +9 -10
  45. package/_cjs/data/Environment/definition.cjs.map +1 -1
  46. package/_cjs/data/EnvironmentPatch.cjs +6 -2
  47. package/_cjs/data/EnvironmentPatch.cjs.map +1 -1
  48. package/_cjs/data/Exit/definition.cjs +12 -9
  49. package/_cjs/data/Exit/definition.cjs.map +1 -1
  50. package/_cjs/data/FiberId/definition.cjs +9 -8
  51. package/_cjs/data/FiberId/definition.cjs.map +1 -1
  52. package/_cjs/data/Guard/definition.cjs +7 -3
  53. package/_cjs/data/Guard/definition.cjs.map +1 -1
  54. package/_cjs/data/Maybe/definition.cjs +8 -4
  55. package/_cjs/data/Maybe/definition.cjs.map +1 -1
  56. package/_cjs/data/Tag/definition.cjs +7 -4
  57. package/_cjs/data/Tag/definition.cjs.map +1 -1
  58. package/_cjs/data/These/definition.cjs +10 -6
  59. package/_cjs/data/These/definition.cjs.map +1 -1
  60. package/_cjs/data/exceptions/InterruptedException.cjs +7 -3
  61. package/_cjs/data/exceptions/InterruptedException.cjs.map +1 -1
  62. package/_cjs/util/predicates.cjs +1 -1
  63. package/_cjs/util/predicates.cjs.map +1 -1
  64. package/_mjs/collection/immutable/Conc/definition.mjs +6 -5
  65. package/_mjs/collection/immutable/Conc/definition.mjs.map +1 -1
  66. package/_mjs/collection/immutable/HashMap/definition.mjs +6 -4
  67. package/_mjs/collection/immutable/HashMap/definition.mjs.map +1 -1
  68. package/_mjs/collection/immutable/HashSet/definition.mjs +6 -4
  69. package/_mjs/collection/immutable/HashSet/definition.mjs.map +1 -1
  70. package/_mjs/collection/immutable/ImmutableArray/definition.mjs +5 -3
  71. package/_mjs/collection/immutable/ImmutableArray/definition.mjs.map +1 -1
  72. package/_mjs/collection/immutable/RoseTree/definition.mjs +5 -3
  73. package/_mjs/collection/immutable/RoseTree/definition.mjs.map +1 -1
  74. package/_mjs/collection/immutable/SortedMap/definition.mjs +3 -2
  75. package/_mjs/collection/immutable/SortedMap/definition.mjs.map +1 -1
  76. package/_mjs/collection/immutable/Vector/definition.mjs +5 -3
  77. package/_mjs/collection/immutable/Vector/definition.mjs.map +1 -1
  78. package/_mjs/control/Eval/definition.mjs +9 -3
  79. package/_mjs/control/Eval/definition.mjs.map +1 -1
  80. package/_mjs/control/Z/definition.mjs +11 -7
  81. package/_mjs/control/Z/definition.mjs.map +1 -1
  82. package/_mjs/data/CaseClass.mjs +1 -1
  83. package/_mjs/data/CaseClass.mjs.map +1 -1
  84. package/_mjs/data/Cause/api.mjs +22 -0
  85. package/_mjs/data/Cause/api.mjs.map +1 -1
  86. package/_mjs/data/Cause/definition.mjs +1 -0
  87. package/_mjs/data/Cause/definition.mjs.map +1 -1
  88. package/_mjs/data/Datum/definition.mjs +10 -9
  89. package/_mjs/data/Datum/definition.mjs.map +1 -1
  90. package/_mjs/data/DatumEither/definition.mjs.map +1 -1
  91. package/_mjs/data/DatumEither.mjs +4 -0
  92. package/_mjs/data/DatumEither.mjs.map +1 -0
  93. package/_mjs/data/DecodeError/definition.mjs +3 -1
  94. package/_mjs/data/DecodeError/definition.mjs.map +1 -1
  95. package/_mjs/data/Decoder/definition.mjs +3 -1
  96. package/_mjs/data/Decoder/definition.mjs.map +1 -1
  97. package/_mjs/data/Duration/definition.mjs +5 -4
  98. package/_mjs/data/Duration/definition.mjs.map +1 -1
  99. package/_mjs/data/Either/api.mjs +6 -6
  100. package/_mjs/data/Either/api.mjs.map +1 -1
  101. package/_mjs/data/Either/definition.mjs +4 -1
  102. package/_mjs/data/Either/definition.mjs.map +1 -1
  103. package/_mjs/data/Encoder/definition.mjs +3 -1
  104. package/_mjs/data/Encoder/definition.mjs.map +1 -1
  105. package/_mjs/data/Environment/api.mjs +4 -12
  106. package/_mjs/data/Environment/api.mjs.map +1 -1
  107. package/_mjs/data/Environment/definition.mjs +6 -8
  108. package/_mjs/data/Environment/definition.mjs.map +1 -1
  109. package/_mjs/data/EnvironmentPatch.mjs +4 -1
  110. package/_mjs/data/EnvironmentPatch.mjs.map +1 -1
  111. package/_mjs/data/Exit/definition.mjs +10 -8
  112. package/_mjs/data/Exit/definition.mjs.map +1 -1
  113. package/_mjs/data/FiberId/definition.mjs +9 -8
  114. package/_mjs/data/FiberId/definition.mjs.map +1 -1
  115. package/_mjs/data/Guard/definition.mjs +4 -1
  116. package/_mjs/data/Guard/definition.mjs.map +1 -1
  117. package/_mjs/data/Maybe/definition.mjs +5 -2
  118. package/_mjs/data/Maybe/definition.mjs.map +1 -1
  119. package/_mjs/data/Tag/definition.mjs +5 -3
  120. package/_mjs/data/Tag/definition.mjs.map +1 -1
  121. package/_mjs/data/These/definition.mjs +10 -4
  122. package/_mjs/data/These/definition.mjs.map +1 -1
  123. package/_mjs/data/exceptions/InterruptedException.mjs +5 -3
  124. package/_mjs/data/exceptions/InterruptedException.mjs.map +1 -1
  125. package/_mjs/util/predicates.mjs +1 -1
  126. package/_mjs/util/predicates.mjs.map +1 -1
  127. package/_src/collection/immutable/Conc/definition.ts +3 -3
  128. package/_src/collection/immutable/HashMap/definition.ts +12 -7
  129. package/_src/collection/immutable/HashSet/definition.ts +11 -5
  130. package/_src/collection/immutable/ImmutableArray/definition.ts +8 -3
  131. package/_src/collection/immutable/RoseTree/definition.ts +8 -3
  132. package/_src/collection/immutable/SortedMap/definition.ts +1 -1
  133. package/_src/collection/immutable/Vector/definition.ts +12 -5
  134. package/_src/control/Eval/definition.ts +22 -10
  135. package/_src/control/Z/definition.ts +17 -14
  136. package/_src/data/CaseClass.ts +1 -1
  137. package/_src/data/Cause/api.ts +24 -0
  138. package/_src/data/Cause/definition.ts +25 -15
  139. package/_src/data/Datum/definition.ts +8 -7
  140. package/_src/data/DatumEither/definition.ts +0 -1
  141. package/_src/data/DatumEither.ts +4 -0
  142. package/_src/data/DecodeError/definition.ts +1 -1
  143. package/_src/data/Decoder/definition.ts +1 -1
  144. package/_src/data/Duration/definition.ts +2 -4
  145. package/_src/data/Either/api.ts +1 -3
  146. package/_src/data/Either/definition.ts +8 -3
  147. package/_src/data/Encoder/definition.ts +1 -1
  148. package/_src/data/Environment/api.ts +0 -11
  149. package/_src/data/Environment/definition.ts +9 -8
  150. package/_src/data/EnvironmentPatch.ts +8 -3
  151. package/_src/data/Exit/definition.ts +16 -12
  152. package/_src/data/FiberId/definition.ts +7 -9
  153. package/_src/data/Guard/definition.ts +7 -2
  154. package/_src/data/Maybe/definition.ts +11 -18
  155. package/_src/data/Tag/definition.ts +7 -4
  156. package/_src/data/These/definition.ts +7 -7
  157. package/_src/data/exceptions/InterruptedException.ts +2 -4
  158. package/_src/data.ts +1 -0
  159. package/_src/util/predicates.ts +2 -2
  160. package/collection/immutable/Conc/definition.d.ts +2 -2
  161. package/collection/immutable/HashMap/definition.d.ts +10 -6
  162. package/collection/immutable/HashSet/definition.d.ts +9 -4
  163. package/collection/immutable/ImmutableArray/definition.d.ts +6 -2
  164. package/collection/immutable/RoseTree/definition.d.ts +6 -2
  165. package/collection/immutable/SortedMap/definition.d.ts +1 -1
  166. package/collection/immutable/Vector/definition.d.ts +10 -4
  167. package/control/Eval/definition.d.ts +18 -7
  168. package/control/Z/definition.d.ts +12 -8
  169. package/data/Cause/api.d.ts +12 -0
  170. package/data/Cause/definition.d.ts +23 -7
  171. package/data/Datum/definition.d.ts +4 -3
  172. package/data/DatumEither/definition.d.ts +0 -1
  173. package/data/DatumEither.d.ts +2 -0
  174. package/data/DecodeError/definition.d.ts +1 -1
  175. package/data/Decoder/definition.d.ts +1 -1
  176. package/data/Duration/definition.d.ts +1 -1
  177. package/data/Either/definition.d.ts +7 -3
  178. package/data/EitherT/api.d.ts +2 -2
  179. package/data/Encoder/definition.d.ts +1 -1
  180. package/data/Environment/api.d.ts +0 -5
  181. package/data/Environment/definition.d.ts +8 -8
  182. package/data/EnvironmentPatch.d.ts +7 -3
  183. package/data/Exit/definition.d.ts +12 -6
  184. package/data/FiberId/definition.d.ts +3 -3
  185. package/data/Guard/definition.d.ts +6 -2
  186. package/data/Maybe/definition.d.ts +13 -11
  187. package/data/Tag/definition.d.ts +6 -2
  188. package/data/These/definition.d.ts +3 -3
  189. package/data/exceptions/InterruptedException.d.ts +1 -1
  190. package/data.d.ts +1 -0
  191. package/package.json +1 -1
  192. package/util/predicates.d.ts +1 -1
@@ -0,0 +1,4 @@
1
+ // codegen:start { preset: barrel, include: ./DatumEither/*.ts }
2
+ export * from "./DatumEither/api.js";
3
+ export * from "./DatumEither/definition.js";
4
+ // codegen:end
@@ -6,7 +6,7 @@ export const DecodeErrorTypeId = Symbol.for("fncts.DecodeError");
6
6
  export type DecodeErrorTypeId = typeof DecodeErrorTypeId;
7
7
 
8
8
  export abstract class DecodeError {
9
- readonly _typeId: DecodeErrorTypeId = DecodeErrorTypeId;
9
+ readonly [DecodeErrorTypeId]: DecodeErrorTypeId = DecodeErrorTypeId;
10
10
  abstract render: Eval<RoseTree<string>>;
11
11
  }
12
12
 
@@ -16,7 +16,7 @@ export interface DecoderF extends HKT {
16
16
  * @tsplus derive nominal
17
17
  */
18
18
  export class Decoder<in out A> {
19
- readonly _typeId: DecoderTypeId = DecoderTypeId;
19
+ readonly [DecoderTypeId]: DecoderTypeId = DecoderTypeId;
20
20
  constructor(readonly decode: (input: unknown) => These<DecodeError, A>, readonly label: string) {}
21
21
  }
22
22
 
@@ -1,5 +1,3 @@
1
- import { hasTypeId } from "../../util/predicates.js";
2
-
3
1
  export const DurationTypeId = Symbol.for("fncts.Duration");
4
2
  export type DurationTypeId = typeof DurationTypeId;
5
3
 
@@ -8,7 +6,7 @@ export type DurationTypeId = typeof DurationTypeId;
8
6
  * @tsplus companion fncts.DurationOps
9
7
  */
10
8
  export class Duration implements Equatable, Hashable {
11
- readonly _typeId: DurationTypeId = DurationTypeId;
9
+ readonly [DurationTypeId]: DurationTypeId = DurationTypeId;
12
10
  constructor(readonly milliseconds: number) {}
13
11
 
14
12
  [Symbol.equals](that: unknown): boolean {
@@ -21,5 +19,5 @@ export class Duration implements Equatable, Hashable {
21
19
  }
22
20
 
23
21
  export function isDuration(u: unknown): u is Duration {
24
- return hasTypeId(u, DurationTypeId);
22
+ return isObject(u) && DurationTypeId in u;
25
23
  }
@@ -1,9 +1,7 @@
1
1
  import type * as P from "../../typeclass.js";
2
2
  import type { EitherF } from "./definition.js";
3
3
 
4
- import { hasTypeId } from "../../util/predicates.js";
5
4
  import { identity } from "../function.js";
6
- import { concrete } from "./definition.js";
7
5
  import { EitherTag, EitherTypeId, Left, Right } from "./definition.js";
8
6
 
9
7
  /**
@@ -128,7 +126,7 @@ export function getOrElse<E, B>(orElse: (e: E) => B) {
128
126
  * @tsplus static fncts.EitherOps isEither
129
127
  */
130
128
  export function isEither(u: unknown): u is Either<unknown, unknown> {
131
- return hasTypeId(u, EitherTypeId);
129
+ return isObject(u) && EitherTypeId in u;
132
130
  }
133
131
 
134
132
  /**
@@ -3,6 +3,9 @@ export const enum EitherTag {
3
3
  Right = "Right",
4
4
  }
5
5
 
6
+ export const EitherVariance = Symbol.for("fncts.Either.Variance");
7
+ export type EitherVariance = typeof EitherVariance;
8
+
6
9
  export const EitherTypeId = Symbol.for("fncts.data.Either");
7
10
  export type EitherTypeId = typeof EitherTypeId;
8
11
 
@@ -19,9 +22,11 @@ export interface EitherF extends HKT {
19
22
  * @tsplus companion fncts.EitherOps
20
23
  */
21
24
  export class Either<E, A> {
22
- readonly _typeId: EitherTypeId = EitherTypeId;
23
- readonly _E!: () => E;
24
- readonly _A!: () => A;
25
+ readonly [EitherTypeId]: EitherTypeId = EitherTypeId;
26
+ declare [EitherVariance]: {
27
+ readonly _E: (_: never) => E;
28
+ readonly _A: (_: never) => A;
29
+ };
25
30
  }
26
31
 
27
32
  /**
@@ -7,7 +7,7 @@ export type EncoderTypeId = typeof EncoderTypeId;
7
7
  * @tsplus derive nominal
8
8
  */
9
9
  export class Encoder<in out A> {
10
- readonly _typeId: EncoderTypeId = EncoderTypeId;
10
+ readonly [EncoderTypeId]: EncoderTypeId = EncoderTypeId;
11
11
  constructor(readonly encode: (inp: A) => unknown) {}
12
12
  }
13
13
 
@@ -49,17 +49,6 @@ export function union<R1>(that: Environment<R1>) {
49
49
  };
50
50
  }
51
51
 
52
- /**
53
- * @tsplus getter fncts.Environment clean
54
- */
55
- export function clean<R>(self: Environment<R>): Environment<R> {
56
- const [map, index] = self.map.toList.foldLeft(
57
- [HashMap.empty<Tag<unknown>, readonly [unknown, number]>(), 0],
58
- ([map, index], [tag, service]) => [map.set(tag, [service, index] as const), index + 1],
59
- );
60
- return new Environment(map);
61
- }
62
-
63
52
  /**
64
53
  * @tsplus pipeable fncts.Environment unsafeGet
65
54
  */
@@ -1,19 +1,20 @@
1
1
  import type { EnvironmentPatch } from "@fncts/base/data/EnvironmentPatch";
2
2
 
3
- /**
4
- * @tsplus static fncts.prelude.builtin.SymbolOps env
5
- */
6
- export const EnvSymbol = Symbol.for("fncts.Env");
3
+ export const EnvironmentVariance = Symbol.for("fncts.Environment.Variance");
4
+ export type EnvironmentVariance = typeof EnvironmentVariance;
7
5
 
8
- export type EnvSymbol = typeof EnvSymbol;
6
+ export const EnvironmentTypeId = Symbol.for("fncts.Environment");
7
+ export type EnvironmentTypeId = typeof EnvironmentTypeId;
9
8
 
10
9
  /**
11
10
  * @tsplus type fncts.Environment
12
11
  * @tsplus companion fncts.EnvironmentOps
13
12
  */
14
13
  export class Environment<R> implements Hashable, Equatable {
15
- readonly _typeId: EnvSymbol = EnvSymbol;
16
- readonly [EnvSymbol]!: (_: never) => R;
14
+ readonly [EnvironmentTypeId]: EnvironmentTypeId = EnvironmentTypeId;
15
+ declare [EnvironmentVariance]: {
16
+ _R: (_: never) => R;
17
+ };
17
18
  constructor(readonly map: HashMap<Tag<any>, unknown>, public cache: HashMap<Tag<any>, unknown> = HashMap.empty()) {}
18
19
 
19
20
  get [Symbol.hash](): number {
@@ -30,5 +31,5 @@ export declare namespace Environment {
30
31
  }
31
32
 
32
33
  export function isEnvironment(u: unknown): u is Environment<unknown> {
33
- return hasTypeId(u, EnvSymbol);
34
+ return isObject(u) && EnvironmentTypeId in u;
34
35
  }
@@ -6,6 +6,9 @@ export const enum EnvironmentPatchTag {
6
6
  Empty,
7
7
  }
8
8
 
9
+ export const EnvironmentPatchVariance = Symbol.for("fncts.Environment.Patch.Variance");
10
+ export type EnvironmentPatchVariance = typeof EnvironmentPatchVariance;
11
+
9
12
  export const EnvironmentPatchTypeId = Symbol.for("fncts.Environment.Patch");
10
13
  export type EnvironmentPatchTypeId = typeof EnvironmentPatchTypeId;
11
14
 
@@ -14,9 +17,11 @@ export type EnvironmentPatchTypeId = typeof EnvironmentPatchTypeId;
14
17
  * @tsplus companion fncts.Environment.PatchOps
15
18
  */
16
19
  export abstract class EnvironmentPatch<In, Out> {
17
- readonly _typeId: EnvironmentPatchTypeId = EnvironmentPatchTypeId;
18
- readonly _R!: (_: In) => void;
19
- readonly _A!: () => Out;
20
+ readonly [EnvironmentPatchTypeId]: EnvironmentPatchTypeId = EnvironmentPatchTypeId;
21
+ declare [EnvironmentPatchVariance]: {
22
+ readonly _R: (_: In) => void;
23
+ readonly _A: (_: never) => Out;
24
+ };
20
25
  }
21
26
 
22
27
  export class AddService<Env, Service> extends EnvironmentPatch<Env, Env & Has<Service>> {
@@ -1,5 +1,7 @@
1
1
  import * as P from "../../typeclass.js";
2
- import { hasTypeId } from "../../util/predicates.js";
2
+
3
+ export const ExitVariance = Symbol.for("fncts.Exit");
4
+ export type ExitVariance = typeof ExitVariance;
3
5
 
4
6
  export const ExitTypeId = Symbol.for("fncts.Exit");
5
7
  export type ExitTypeId = typeof ExitTypeId;
@@ -29,11 +31,12 @@ const _successHash = Hashable.string("fncts.Exit.Success");
29
31
  * @tsplus companion fncts.Exit.FailureOps
30
32
  */
31
33
  export class Failure<E> {
32
- readonly _E!: () => E;
33
- readonly _A!: () => never;
34
-
35
- readonly _typeId: ExitTypeId = ExitTypeId;
36
- readonly _tag = ExitTag.Failure;
34
+ readonly [ExitTypeId]: ExitTypeId = ExitTypeId;
35
+ declare [ExitVariance]: {
36
+ readonly _E: (_: never) => E;
37
+ readonly _A: (_: never) => never;
38
+ };
39
+ readonly _tag = ExitTag.Failure;
37
40
  constructor(readonly cause: Cause<E>) {}
38
41
 
39
42
  get [Symbol.hash](): number {
@@ -49,11 +52,12 @@ export class Failure<E> {
49
52
  * @tsplus companion fncts.Exit.SuccessOps
50
53
  */
51
54
  export class Success<A> implements P.Hashable, P.Equatable {
52
- readonly _E!: () => never;
53
- readonly _A!: () => A;
54
-
55
- readonly _typeId: ExitTypeId = ExitTypeId;
56
- readonly _tag = ExitTag.Success;
55
+ readonly [ExitTypeId]: ExitTypeId = ExitTypeId;
56
+ declare [ExitVariance]: {
57
+ readonly _E: (_: never) => never;
58
+ readonly _A: (_: never) => A;
59
+ };
60
+ readonly _tag = ExitTag.Success;
57
61
  constructor(readonly value: A) {}
58
62
 
59
63
  get [Symbol.hash](): number {
@@ -68,7 +72,7 @@ export class Success<A> implements P.Hashable, P.Equatable {
68
72
  * @tsplus static fncts.ExitOps isExit
69
73
  */
70
74
  export function isExit(u: unknown): u is Exit<unknown, unknown> {
71
- return hasTypeId(u, ExitTypeId);
75
+ return isObject(u) && ExitTypeId in u;
72
76
  }
73
77
 
74
78
  /**
@@ -1,13 +1,11 @@
1
- import { hasTypeId } from "../../util/predicates.js";
2
-
3
1
  export const FiberIdTypeId = Symbol.for("fncts.FiberId");
4
2
  export type FiberIdTypeId = typeof FiberIdTypeId;
5
3
 
6
4
  const _hashNone = Hashable.string("fncts.FiberId.None");
7
5
 
8
6
  export class None implements Hashable, Equatable {
9
- readonly _typeId: FiberIdTypeId = FiberIdTypeId;
10
- readonly _tag = "None";
7
+ readonly [FiberIdTypeId]: FiberIdTypeId = FiberIdTypeId;
8
+ readonly _tag = "None";
11
9
  [Symbol.equals](that: unknown) {
12
10
  return isFiberId(that) && isNone(that);
13
11
  }
@@ -19,8 +17,8 @@ export class None implements Hashable, Equatable {
19
17
  const _hashRuntime = Hashable.string("fncts.FiberId.Runtime");
20
18
 
21
19
  export class Runtime implements Hashable, Equatable {
22
- readonly _typeId: FiberIdTypeId = FiberIdTypeId;
23
- readonly _tag = "Runtime";
20
+ readonly [FiberIdTypeId]: FiberIdTypeId = FiberIdTypeId;
21
+ readonly _tag = "Runtime";
24
22
  constructor(readonly id: number, readonly startTime: number, readonly location?: string) {}
25
23
  get [Symbol.hash]() {
26
24
  return Hashable.combine(Hashable.combine(_hashRuntime, Hashable.number(this.id)), Hashable.unknown(this.location));
@@ -33,8 +31,8 @@ export class Runtime implements Hashable, Equatable {
33
31
  const _hashComposite = Hashable.string("fncts.FiberId.Composite");
34
32
 
35
33
  export class Composite implements Hashable, Equatable {
36
- readonly _typeId: FiberIdTypeId = FiberIdTypeId;
37
- readonly _tag = "Composite";
34
+ readonly [FiberIdTypeId]: FiberIdTypeId = FiberIdTypeId;
35
+ readonly _tag = "Composite";
38
36
  constructor(readonly fiberIds: HashSet<Runtime>) {}
39
37
  [Symbol.equals](that: unknown) {
40
38
  return isFiberId(that) && isComposite(that) && this.fiberIds == that.fiberIds;
@@ -66,7 +64,7 @@ export declare namespace FiberId {
66
64
  * @tsplus static fncts.FiberIdOps isFiberId
67
65
  */
68
66
  export function isFiberId(u: unknown): u is FiberId {
69
- return hasTypeId(u, FiberIdTypeId);
67
+ return isObject(u) && FiberIdTypeId in u;
70
68
  }
71
69
 
72
70
  /**
@@ -2,6 +2,9 @@ export interface GuardF extends HKT {
2
2
  readonly type: Guard<this["A"]>;
3
3
  }
4
4
 
5
+ export const GuardVariance = Symbol.for("fncts.Guard.Variance");
6
+ export type GuardVariance = typeof GuardVariance;
7
+
5
8
  export const GuardTypeId = Symbol.for("fncts.Guard");
6
9
  export type GuardTypeId = typeof GuardTypeId;
7
10
 
@@ -10,8 +13,10 @@ export type GuardTypeId = typeof GuardTypeId;
10
13
  * @tsplus companion fncts.GuardOps
11
14
  */
12
15
  export class Guard<A> {
13
- readonly _typeId: GuardTypeId = GuardTypeId;
14
- declare _A: () => A;
16
+ readonly [GuardTypeId]: GuardTypeId = GuardTypeId;
17
+ declare [GuardVariance]: {
18
+ readonly _A: (_: never) => A;
19
+ };
15
20
  constructor(readonly is: Refinement<unknown, A>) {}
16
21
  }
17
22
 
@@ -5,8 +5,11 @@ export const enum MaybeTag {
5
5
  Nothing = "Nothing",
6
6
  }
7
7
 
8
+ export const MaybeVariance = Symbol.for("fncts.Maybe.Variance");
9
+ export type MaybeVariance = typeof MaybeVariance;
10
+
8
11
  export const MaybeTypeId = Symbol.for("fncts.Maybe");
9
- export type MaybeTypdId = typeof MaybeTypeId;
12
+ export type MaybeTypeId = typeof MaybeTypeId;
10
13
 
11
14
  export interface MaybeF extends HKT {
12
15
  type: Maybe<this["A"]>;
@@ -22,9 +25,11 @@ const _nothingHash = Hashable.string("fncts.Nothing");
22
25
  * @tsplus type fncts.Maybe
23
26
  * @tsplus companion fncts.MaybeOps
24
27
  */
25
- export class Maybe<A> {
26
- declare _A: () => A;
27
- readonly _typeId: MaybeTypdId = MaybeTypeId;
28
+ export abstract class Maybe<A> {
29
+ declare [MaybeVariance]: {
30
+ readonly _A: (_: never) => A;
31
+ };
32
+ readonly [MaybeTypeId]: MaybeTypeId = MaybeTypeId;
28
33
  }
29
34
 
30
35
  /**
@@ -63,15 +68,7 @@ export class Nothing extends Maybe<never> {
63
68
  */
64
69
  export function unifyMaybe<X extends Maybe<any>>(
65
70
  self: X,
66
- ): Maybe<
67
- [X] extends [
68
- {
69
- _A: () => infer A;
70
- },
71
- ]
72
- ? A
73
- : never
74
- > {
71
+ ): Maybe<[X] extends [{ [MaybeVariance]: { _A: (_: never) => infer A } }] ? A : never> {
75
72
  return self;
76
73
  }
77
74
 
@@ -79,11 +76,7 @@ export function unifyMaybe<X extends Maybe<any>>(
79
76
  * @tsplus static fncts.MaybeOps isMaybe
80
77
  */
81
78
  export function isMaybe(u: unknown): u is Maybe<unknown> {
82
- return (
83
- isObject(u) &&
84
- (MaybeTypeId in u ||
85
- ("_tag" in u && typeof u["_tag"] === "string" && (u["_tag"] === "Nothing" || u["_tag"] === "Just")))
86
- );
79
+ return isObject(u) && MaybeTypeId in u;
87
80
  }
88
81
 
89
82
  /**
@@ -1,4 +1,5 @@
1
- import { AtomicNumber } from "@fncts/base/internal/AtomicNumber";
1
+ export const TagVariance = Symbol.for("fncts.Tag.Variance");
2
+ export type TagVariance = typeof TagVariance;
2
3
 
3
4
  export const TagTypeId = Symbol.for("fncts.Tag");
4
5
  export type TagTypeId = typeof TagTypeId;
@@ -12,8 +13,10 @@ const _tagHash = Hashable.string("fncts.Tag");
12
13
  * @tsplus companion fncts.TagOps
13
14
  */
14
15
  export class Tag<in out T> implements Hashable, Equatable {
15
- declare _T: (_: T) => T;
16
- readonly _typeId: TagTypeId = TagTypeId;
16
+ readonly [TagTypeId]: TagTypeId = TagTypeId;
17
+ declare [TagVariance]: {
18
+ readonly _T: (_: T) => T;
19
+ };
17
20
 
18
21
  constructor(readonly id: string) {}
19
22
 
@@ -27,5 +30,5 @@ export class Tag<in out T> implements Hashable, Equatable {
27
30
  }
28
31
 
29
32
  export function isTag(u: unknown): u is Tag<unknown> {
30
- return hasTypeId(u, TagTypeId);
33
+ return isObject(u) && TagTypeId in u;
31
34
  }
@@ -11,8 +11,8 @@ export type TheseTypeId = typeof TheseTypeId;
11
11
  * @tsplus type fncts.These.Left
12
12
  */
13
13
  export class Left<E> {
14
- readonly _typeId: TheseTypeId = TheseTypeId;
15
- readonly _tag = TheseTag.Left;
14
+ readonly [TheseTypeId]: TheseTypeId = TheseTypeId;
15
+ readonly _tag = TheseTag.Left;
16
16
  constructor(readonly left: E) {}
17
17
  }
18
18
 
@@ -20,8 +20,8 @@ export class Left<E> {
20
20
  * @tsplus type fncts.These.Right
21
21
  */
22
22
  export class Right<A> {
23
- readonly _typeId: TheseTypeId = TheseTypeId;
24
- readonly _tag = TheseTag.Right;
23
+ readonly [TheseTypeId]: TheseTypeId = TheseTypeId;
24
+ readonly _tag = TheseTag.Right;
25
25
  constructor(readonly right: A) {}
26
26
  }
27
27
 
@@ -29,8 +29,8 @@ export class Right<A> {
29
29
  * @tsplus type fncts.These.Both
30
30
  */
31
31
  export class Both<E, A> {
32
- readonly _typeId: TheseTypeId = TheseTypeId;
33
- readonly _tag = TheseTag.Both;
32
+ readonly [TheseTypeId]: TheseTypeId = TheseTypeId;
33
+ readonly _tag = TheseTag.Both;
34
34
  constructor(readonly left: E, readonly right: A) {}
35
35
  }
36
36
 
@@ -50,5 +50,5 @@ export const These: TheseOps = {};
50
50
  * @tsplus static fncts.TheseOps isThese
51
51
  */
52
52
  export function isThese(u: unknown): u is These<unknown, unknown> {
53
- return hasTypeId(u, TheseTypeId);
53
+ return isObject(u) && TheseTypeId in u;
54
54
  }
@@ -1,13 +1,11 @@
1
- import { hasTypeId } from "../../util/predicates.js";
2
-
3
1
  export const InterruptedExceptionTypeId = Symbol.for("fncts.InterruptedException");
4
2
  export type InterruptedExceptionTypeId = typeof InterruptedExceptionTypeId;
5
3
 
6
4
  export class InterruptedException {
7
- readonly _typeId: InterruptedExceptionTypeId = InterruptedExceptionTypeId;
5
+ readonly [InterruptedExceptionTypeId]: InterruptedExceptionTypeId = InterruptedExceptionTypeId;
8
6
  constructor(readonly message?: string) {}
9
7
  }
10
8
 
11
9
  export function isInterruptedException(u: unknown): u is InterruptedException {
12
- return hasTypeId(u, InterruptedExceptionTypeId);
10
+ return isObject(u) && InterruptedExceptionTypeId in u;
13
11
  }
package/_src/data.ts CHANGED
@@ -6,6 +6,7 @@ export type {} from "./data/Byte.js";
6
6
  export type {} from "./data/CaseClass.js";
7
7
  export type {} from "./data/Cause.js";
8
8
  export type {} from "./data/Const.js";
9
+ export type {} from "./data/DatumEither.js";
9
10
  export type {} from "./data/DecodeError.js";
10
11
  export type {} from "./data/Decoder.js";
11
12
  export type {} from "./data/Duration.js";
@@ -45,9 +45,9 @@ export function hasTypeId<X extends symbol>(
45
45
  value: unknown,
46
46
  typeId: X,
47
47
  ): value is {
48
- readonly _typeId: X;
48
+ readonly [K in X]: X;
49
49
  } & Record<PropertyKey, unknown> {
50
- return isObject(value) && "_typeId" in value && value["_typeId"] === typeId;
50
+ return isObject(value) && typeId in value;
51
51
  }
52
52
 
53
53
  export function isFunction(value: unknown): value is Function {
@@ -32,14 +32,14 @@ export interface ConcF extends HKT {
32
32
  */
33
33
  export declare abstract class Conc<A> implements Iterable<A>, Hashable, Equatable {
34
34
  _A: () => A;
35
- readonly _typeId: ConcTypeId;
35
+ readonly [ConcTypeId]: ConcTypeId;
36
36
  abstract readonly length: number;
37
37
  abstract [Symbol.iterator](): Iterator<A>;
38
38
  get [Symbol.hash](): number;
39
39
  [Symbol.equals](that: unknown): boolean;
40
40
  }
41
41
  declare abstract class ConcImplementation<A> implements Iterable<A> {
42
- readonly _typeId: ConcTypeId;
42
+ readonly [ConcTypeId]: ConcTypeId;
43
43
  _A: () => A;
44
44
  get [Symbol.hash](): number;
45
45
  [Symbol.equals](that: unknown): boolean;
@@ -12,21 +12,25 @@ export interface HashMapF extends HKT {
12
12
  };
13
13
  index: this["K"];
14
14
  }
15
- export declare const TypeId: unique symbol;
16
- export type TypeId = typeof TypeId;
15
+ export declare const HashMapVariance: unique symbol;
16
+ export type HashMapVariance = typeof HashMapVariance;
17
+ export declare const HashMapTypeId: unique symbol;
18
+ export type HashMapTypeId = typeof HashMapTypeId;
17
19
  /**
18
20
  * @tsplus type fncts.HashMap
19
21
  * @tsplus companion fncts.HashMapOps
20
22
  */
21
- export declare class HashMap<K, V> implements Iterable<readonly [K, V]>, Hashable, Equatable {
23
+ export declare class HashMap<in out K, in out V> implements Iterable<readonly [K, V]>, Hashable, Equatable {
22
24
  editable: boolean;
23
25
  edit: number;
24
26
  readonly config: HashEq<K>;
25
27
  root: Node<K, V>;
26
28
  size: number;
27
- readonly _typeId: TypeId;
28
- _K: () => K;
29
- _A: () => V;
29
+ readonly [HashMapTypeId]: HashMapTypeId;
30
+ [HashMapVariance]: {
31
+ readonly _K: (_: K) => K;
32
+ readonly _A: (_: V) => V;
33
+ };
30
34
  constructor(editable: boolean, edit: number, config: HashEq<K>, root: Node<K, V>, size: number);
31
35
  [Symbol.iterator](): Iterator<readonly [K, V]>;
32
36
  get [Symbol.hash](): number;
@@ -1,12 +1,14 @@
1
1
  import { Hashable } from "@fncts/base/data/Hashable";
2
2
  import * as P from "@fncts/base/typeclass";
3
- export declare const TypeId: unique symbol;
4
- export type TypeId = typeof TypeId;
3
+ export declare const HashSetVariance: unique symbol;
4
+ export type HashSetVariance = typeof HashSetVariance;
5
+ export declare const HashSetTypeId: unique symbol;
6
+ export type HashSetTypeId = typeof HashSetTypeId;
5
7
  /**
6
8
  * @tsplus type fncts.HashSet
7
9
  * @tsplus companion fncts.HashSetOps
8
10
  */
9
- export declare class HashSet<A> implements Iterable<A>, P.Hashable, P.Equatable {
11
+ export declare class HashSet<in out A> implements Iterable<A>, P.Hashable, P.Equatable {
10
12
  /**
11
13
  * @internal
12
14
  */
@@ -27,7 +29,10 @@ export declare class HashSet<A> implements Iterable<A>, P.Hashable, P.Equatable
27
29
  * @internal
28
30
  */
29
31
  _size: number;
30
- readonly _typeId: TypeId;
32
+ readonly [HashSetTypeId]: HashSetTypeId;
33
+ [HashSetVariance]: {
34
+ readonly _A: (_: A) => A;
35
+ };
31
36
  constructor(
32
37
  /**
33
38
  * @internal
@@ -1,6 +1,8 @@
1
1
  import { HKT } from "@fncts/typelevel/HKT";
2
2
  import { Equatable } from "@fncts/base/data/Equatable";
3
3
  import { Hashable } from "@fncts/base/data/Hashable";
4
+ export declare const ImmutableArrayVariance: unique symbol;
5
+ export type ImmutableArrayVariance = typeof ImmutableArrayVariance;
4
6
  export declare const ImmutableArrayTypeId: unique symbol;
5
7
  export type ImmutableArrayTypeId = typeof ImmutableArrayTypeId;
6
8
  export interface ImmutableArrayF extends HKT {
@@ -16,8 +18,10 @@ export interface ImmutableArrayF extends HKT {
16
18
  */
17
19
  export declare class ImmutableArray<A> implements Equatable, Hashable, Iterable<A> {
18
20
  readonly _array: ReadonlyArray<A>;
19
- readonly _typeId: ImmutableArrayTypeId;
20
- readonly _A: () => A;
21
+ readonly [ImmutableArrayTypeId]: ImmutableArrayTypeId;
22
+ [ImmutableArrayVariance]: {
23
+ readonly _A: (_: never) => A;
24
+ };
21
25
  constructor(_array: ReadonlyArray<A>);
22
26
  [Symbol.equals](that: unknown): boolean;
23
27
  get [Symbol.hash](): number;
@@ -2,6 +2,8 @@ import { HKT } from "@fncts/typelevel/HKT";
2
2
  import { Hashable } from "@fncts/base/data/Hashable";
3
3
  import { Equatable } from "@fncts/base/data/Equatable";
4
4
  import { Vector } from "@fncts/base/collection/immutable/Vector";
5
+ export declare const RoseTreeVariance: unique symbol;
6
+ export type RoseTreeVariance = typeof RoseTreeVariance;
5
7
  export declare const RoseTreeTypeId: unique symbol;
6
8
  export type RoseTreeTypeId = typeof RoseTreeTypeId;
7
9
  export interface RoseTreeF extends HKT {
@@ -17,8 +19,10 @@ export interface RoseTreeF extends HKT {
17
19
  export declare class RoseTree<A> implements Hashable, Equatable {
18
20
  readonly value: A;
19
21
  readonly forest: Vector<RoseTree<A>>;
20
- readonly _typeId: RoseTreeTypeId;
21
- _A: () => A;
22
+ readonly [RoseTreeTypeId]: RoseTreeTypeId;
23
+ [RoseTreeVariance]: {
24
+ readonly _A: (_: never) => A;
25
+ };
22
26
  constructor(value: A, forest: Vector<RoseTree<A>>);
23
27
  [Symbol.equals](that: unknown): boolean;
24
28
  get [Symbol.hash](): number;
@@ -10,7 +10,7 @@ export type TypeId = typeof TypeId;
10
10
  export declare class SortedMap<K, V> implements SortedMapIterable<K, V> {
11
11
  readonly ord: Ord<K>;
12
12
  readonly root: RBNode<K, V>;
13
- readonly _typeId: TypeId;
13
+ readonly [TypeId]: TypeId;
14
14
  constructor(ord: Ord<K>, root: RBNode<K, V>);
15
15
  [Symbol.iterator](): SortedMapIterator<K, V>;
16
16
  }
@@ -2,6 +2,8 @@ import { HKT } from "@fncts/typelevel/HKT";
2
2
  import { Hashable } from "@fncts/base/data/Hashable";
3
3
  import { Equatable } from "@fncts/base/data/Equatable";
4
4
  import type { Node } from "@fncts/base/collection/immutable/Vector/internal";
5
+ export declare const VectorVariance: unique symbol;
6
+ export type VectorVariance = typeof VectorVariance;
5
7
  export declare const VectorTypeId: unique symbol;
6
8
  export type VectorTypeId = typeof VectorTypeId;
7
9
  export interface VectorF extends HKT {
@@ -29,8 +31,10 @@ export declare class Vector<A> implements Iterable<A> {
29
31
  readonly root: Node | undefined;
30
32
  /** @private */
31
33
  readonly suffix: A[];
32
- readonly _typeId: VectorTypeId;
33
- readonly _A: () => A;
34
+ readonly [VectorTypeId]: VectorTypeId;
35
+ [VectorVariance]: {
36
+ readonly _A: (_: never) => A;
37
+ };
34
38
  constructor(
35
39
  /** @private */
36
40
  bits: number,
@@ -50,8 +54,10 @@ export declare class Vector<A> implements Iterable<A> {
50
54
  * @tsplus type fncts.MutableVector
51
55
  */
52
56
  export interface MutableVector<A> {
53
- readonly _typeId: VectorTypeId;
54
- readonly _A: () => A;
57
+ readonly [VectorTypeId]: VectorTypeId;
58
+ readonly [VectorVariance]: {
59
+ readonly _A: (_: never) => A;
60
+ };
55
61
  bits: number;
56
62
  offset: number;
57
63
  length: number;