@fncts/base 0.0.9 → 0.0.12

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.
Files changed (172) hide show
  1. package/_cjs/collection/Iterable/api.cjs +32 -4
  2. package/_cjs/collection/Iterable/api.cjs.map +1 -1
  3. package/_cjs/collection/compat/Record/instances.cjs +77 -0
  4. package/_cjs/collection/compat/Record/instances.cjs.map +1 -0
  5. package/_cjs/collection/compat/Record.cjs +19 -0
  6. package/_cjs/collection/compat/Record.cjs.map +1 -0
  7. package/_cjs/collection/immutable/Conc/api.cjs +22 -1
  8. package/_cjs/collection/immutable/Conc/api.cjs.map +1 -1
  9. package/_cjs/collection/immutable/Dictionary/api.cjs +7 -8
  10. package/_cjs/collection/immutable/Dictionary/api.cjs.map +1 -1
  11. package/_cjs/collection/immutable/HashMap/api.cjs.map +1 -1
  12. package/_cjs/collection/immutable/ImmutableArray/api.cjs +1 -1
  13. package/_cjs/collection/immutable/ImmutableArray/api.cjs.map +1 -1
  14. package/_cjs/collection/immutable/ImmutableNonEmptyArray/instances.cjs.map +1 -1
  15. package/_cjs/collection/weak/IterableWeakMap.cjs +83 -0
  16. package/_cjs/collection/weak/IterableWeakMap.cjs.map +1 -0
  17. package/_cjs/collection/weak/IterableWeakSet.cjs +73 -0
  18. package/_cjs/collection/weak/IterableWeakSet.cjs.map +1 -0
  19. package/_cjs/data/Branded/definition.cjs.map +1 -1
  20. package/_cjs/data/Branded/derivations.cjs.map +1 -1
  21. package/_cjs/data/CaseClass.cjs.map +1 -1
  22. package/_cjs/data/Cause/api.cjs +1 -119
  23. package/_cjs/data/Cause/api.cjs.map +1 -1
  24. package/_cjs/data/Cause.cjs +65 -0
  25. package/_cjs/data/Cause.cjs.map +1 -1
  26. package/_cjs/data/Decoder/api.cjs +5 -3
  27. package/_cjs/data/Decoder/api.cjs.map +1 -1
  28. package/_cjs/data/Struct/api.cjs +10 -12
  29. package/_cjs/data/Struct/api.cjs.map +1 -1
  30. package/_cjs/data/These/api.cjs.map +1 -1
  31. package/_cjs/data/These/destructors.cjs.map +1 -1
  32. package/_cjs/data/These.cjs +13 -0
  33. package/_cjs/data/These.cjs.map +1 -1
  34. package/_cjs/data/exceptions/RuntimeError.cjs +6 -0
  35. package/_cjs/data/exceptions/RuntimeError.cjs.map +1 -0
  36. package/_cjs/data/exceptions.cjs +13 -0
  37. package/_cjs/data/exceptions.cjs.map +1 -1
  38. package/_cjs/data/object.cjs +13 -0
  39. package/_cjs/data/object.cjs.map +1 -1
  40. package/_cjs/json/EitherJson.cjs +4 -4
  41. package/_cjs/json/EitherJson.cjs.map +1 -1
  42. package/_cjs/json/MaybeJson.cjs +3 -3
  43. package/_cjs/json/MaybeJson.cjs.map +1 -1
  44. package/_cjs/json/TheseJson.cjs +7 -7
  45. package/_cjs/json/TheseJson.cjs.map +1 -1
  46. package/_cjs/optics/Traversal/definition.cjs +9 -11
  47. package/_cjs/optics/Traversal/definition.cjs.map +1 -1
  48. package/_cjs/typeclass/Guard/derivations.cjs.map +1 -1
  49. package/_cjs/typeclass/Monoid.cjs.map +1 -1
  50. package/_cjs/typeclass/Semialign.cjs.map +1 -1
  51. package/_cjs/typeclass/Showable/show.cjs +7 -7
  52. package/_cjs/typeclass/Showable/show.cjs.map +1 -1
  53. package/_cjs/util/AnsiFormat.cjs +5 -5
  54. package/_cjs/util/AnsiFormat.cjs.map +1 -1
  55. package/_mjs/collection/Iterable/api.mjs +27 -1
  56. package/_mjs/collection/Iterable/api.mjs.map +1 -1
  57. package/_mjs/collection/compat/Record/instances.mjs +59 -0
  58. package/_mjs/collection/compat/Record/instances.mjs.map +1 -0
  59. package/_mjs/collection/compat/Record.mjs +3 -0
  60. package/_mjs/collection/compat/Record.mjs.map +1 -0
  61. package/_mjs/collection/immutable/Conc/api.mjs +21 -2
  62. package/_mjs/collection/immutable/Conc/api.mjs.map +1 -1
  63. package/_mjs/collection/immutable/Dictionary/api.mjs +5 -7
  64. package/_mjs/collection/immutable/Dictionary/api.mjs.map +1 -1
  65. package/_mjs/collection/immutable/HashMap/api.mjs.map +1 -1
  66. package/_mjs/collection/immutable/ImmutableArray/api.mjs +1 -1
  67. package/_mjs/collection/immutable/ImmutableArray/api.mjs.map +1 -1
  68. package/_mjs/collection/immutable/ImmutableNonEmptyArray/instances.mjs.map +1 -1
  69. package/_mjs/collection/weak/IterableWeakMap.mjs +74 -0
  70. package/_mjs/collection/weak/IterableWeakMap.mjs.map +1 -0
  71. package/_mjs/collection/weak/IterableWeakSet.mjs +64 -0
  72. package/_mjs/collection/weak/IterableWeakSet.mjs.map +1 -0
  73. package/_mjs/data/Branded/definition.mjs.map +1 -1
  74. package/_mjs/data/Branded/derivations.mjs.map +1 -1
  75. package/_mjs/data/CaseClass.mjs.map +1 -1
  76. package/_mjs/data/Cause/api.mjs +1 -7
  77. package/_mjs/data/Cause/api.mjs.map +1 -1
  78. package/_mjs/data/Cause.mjs +8 -1
  79. package/_mjs/data/Cause.mjs.map +1 -1
  80. package/_mjs/data/Decoder/api.mjs +5 -3
  81. package/_mjs/data/Decoder/api.mjs.map +1 -1
  82. package/_mjs/data/Struct/api.mjs +9 -10
  83. package/_mjs/data/Struct/api.mjs.map +1 -1
  84. package/_mjs/data/These/api.mjs.map +1 -1
  85. package/_mjs/data/These/destructors.mjs.map +1 -1
  86. package/_mjs/data/These.mjs +1 -0
  87. package/_mjs/data/These.mjs.map +1 -1
  88. package/_mjs/data/exceptions/RuntimeError.mjs +2 -0
  89. package/_mjs/data/exceptions/RuntimeError.mjs.map +1 -0
  90. package/_mjs/data/exceptions.mjs +1 -0
  91. package/_mjs/data/exceptions.mjs.map +1 -1
  92. package/_mjs/data/object.mjs +1 -0
  93. package/_mjs/data/object.mjs.map +1 -1
  94. package/_mjs/json/EitherJson.mjs +4 -4
  95. package/_mjs/json/EitherJson.mjs.map +1 -1
  96. package/_mjs/json/MaybeJson.mjs +3 -3
  97. package/_mjs/json/MaybeJson.mjs.map +1 -1
  98. package/_mjs/json/TheseJson.mjs +7 -7
  99. package/_mjs/json/TheseJson.mjs.map +1 -1
  100. package/_mjs/optics/Traversal/definition.mjs +9 -10
  101. package/_mjs/optics/Traversal/definition.mjs.map +1 -1
  102. package/_mjs/typeclass/Guard/derivations.mjs.map +1 -1
  103. package/_mjs/typeclass/Monoid.mjs.map +1 -1
  104. package/_mjs/typeclass/Semialign.mjs.map +1 -1
  105. package/_mjs/typeclass/Showable/show.mjs +7 -7
  106. package/_mjs/typeclass/Showable/show.mjs.map +1 -1
  107. package/_mjs/util/AnsiFormat.mjs +5 -5
  108. package/_mjs/util/AnsiFormat.mjs.map +1 -1
  109. package/_src/collection/Iterable/api.ts +21 -0
  110. package/_src/collection/compat/Record/instances.ts +59 -0
  111. package/_src/collection/compat/Record.ts +3 -0
  112. package/_src/collection/immutable/Conc/api.ts +17 -1
  113. package/_src/collection/immutable/HashMap/api.ts +1 -2
  114. package/_src/collection/immutable/ImmutableNonEmptyArray/instances.ts +14 -14
  115. package/_src/collection/immutable/RoseTree.ts +1 -1
  116. package/_src/collection/immutable/Vector/definition.ts +2 -2
  117. package/_src/collection/weak/IterableWeakMap.ts +63 -0
  118. package/_src/collection/weak/IterableWeakSet.ts +56 -0
  119. package/_src/data/Branded/definition.ts +13 -9
  120. package/_src/data/Branded/derivations.ts +24 -23
  121. package/_src/data/Branded.ts +1 -1
  122. package/_src/data/CaseClass.ts +1 -2
  123. package/_src/data/Cause/api.ts +0 -8
  124. package/_src/data/Cause.ts +8 -0
  125. package/_src/data/Const/definition.ts +1 -1
  126. package/_src/data/DecodeError.ts +1 -1
  127. package/_src/data/Decoder/api.ts +2 -1
  128. package/_src/data/Duration/api.ts +1 -1
  129. package/_src/data/Identity/api.ts +1 -1
  130. package/_src/data/Identity/definition.ts +1 -1
  131. package/_src/data/These/api.ts +1 -1
  132. package/_src/data/These/constructors.ts +1 -1
  133. package/_src/data/These/definition.ts +1 -1
  134. package/_src/data/These/destructors.ts +3 -7
  135. package/_src/data/These.ts +1 -0
  136. package/_src/data/bigint/definition.ts +1 -1
  137. package/_src/data/bigint.ts +1 -1
  138. package/_src/data/boolean/instances.ts +1 -1
  139. package/_src/data/boolean.ts +1 -1
  140. package/_src/data/exceptions/RuntimeError.ts +0 -0
  141. package/_src/data/exceptions.ts +1 -0
  142. package/_src/data/number/instances.ts +1 -1
  143. package/_src/data/object.ts +1 -0
  144. package/_src/data/string/instances.ts +1 -1
  145. package/_src/json/MaybeJson.ts +4 -4
  146. package/_src/typeclass/Align.ts +1 -1
  147. package/_src/typeclass/Closure.ts +1 -1
  148. package/_src/typeclass/Eq/definition.ts +2 -2
  149. package/_src/typeclass/Guard/api.ts +1 -1
  150. package/_src/typeclass/Guard/definition.ts +1 -1
  151. package/_src/typeclass/Guard/derivations.ts +17 -16
  152. package/_src/typeclass/Guard.ts +0 -1
  153. package/_src/typeclass/Monoid.ts +4 -4
  154. package/_src/typeclass/Semialign.ts +6 -9
  155. package/_src/typeclass/Semigroup/derivations.ts +1 -1
  156. package/_src/typeclass/Showable/show.ts +8 -5
  157. package/_src/typeclass.ts +0 -1
  158. package/collection/Iterable/api.d.ts +10 -0
  159. package/collection/compat/Record/instances.d.ts +10 -0
  160. package/collection/compat/Record.d.ts +1 -0
  161. package/collection/immutable/Conc/api.d.ts +6 -1
  162. package/collection/immutable/ImmutableArray/api.d.ts +1 -0
  163. package/collection/weak/IterableWeakMap.d.ts +16 -0
  164. package/collection/weak/IterableWeakSet.d.ts +15 -0
  165. package/data/Cause/api.d.ts +0 -5
  166. package/data/Cause.d.ts +5 -0
  167. package/data/Decoder/api.d.ts +2 -1
  168. package/data/These.d.ts +1 -0
  169. package/data/exceptions/RuntimeError.d.ts +1 -0
  170. package/data/exceptions.d.ts +1 -0
  171. package/data/object.d.ts +1 -0
  172. package/package.json +2 -2
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @tsplus type fncts.IterableWeakSet
3
+ */
4
+ export class IterableWeakSet<A extends object> implements Iterable<A> {
5
+ private weakMap = new WeakMap<A, { ref: WeakRef<A> }>();
6
+ private refSet = new Set<WeakRef<A>>();
7
+ private finalizationGroup = new FinalizationRegistry<{ ref: WeakRef<A>; set: Set<WeakRef<A>> }>(
8
+ IterableWeakSet.cleanup,
9
+ );
10
+
11
+ private static cleanup<A extends object>({ ref, set }: { ref: WeakRef<A>; set: Set<WeakRef<A>> }) {
12
+ set.delete(ref);
13
+ }
14
+
15
+ constructor(iterable: Iterable<A>) {
16
+ for (const value of iterable) {
17
+ this.add(value);
18
+ }
19
+ }
20
+
21
+ add(this: this, value: A): this {
22
+ const ref = new WeakRef(value);
23
+
24
+ this.weakMap.set(value, { ref });
25
+ this.refSet.add(ref);
26
+ this.finalizationGroup.register(value, { set: this.refSet, ref }, ref);
27
+ return this;
28
+ }
29
+
30
+ delete(this: this, value: A): boolean {
31
+ const entry = this.weakMap.get(value);
32
+ if (!entry) {
33
+ return false;
34
+ }
35
+
36
+ this.weakMap.delete(value);
37
+ this.refSet.delete(entry.ref);
38
+ return true;
39
+ }
40
+
41
+ [Symbol.iterator](this: this): IterableIterator<A> {
42
+ return this.entries();
43
+ }
44
+
45
+ *entries(this: this): IterableIterator<A> {
46
+ for (const ref of this.refSet) {
47
+ const key = ref.deref();
48
+ if (!key) continue;
49
+ yield key;
50
+ }
51
+ }
52
+
53
+ has(this: this, value: A): boolean {
54
+ return this.weakMap.has(value);
55
+ }
56
+ }
@@ -17,18 +17,22 @@ export declare namespace Branded {
17
17
  export type Validated<A, K extends string> = A & Brand<A, K>;
18
18
 
19
19
  export type IsValidated<P extends Brand<any, any>> = {
20
- [K in keyof P[Branded.Symbol]]: P extends P[Branded.Symbol][K] ? 0 : 1
21
- }[keyof P[Branded.Symbol]] extends 0 ? unknown : never;
20
+ [K in keyof P[Branded.Symbol]]: P extends P[Branded.Symbol][K] ? 0 : 1;
21
+ }[keyof P[Branded.Symbol]] extends 0
22
+ ? unknown
23
+ : never;
22
24
 
23
25
  export type Unbrand<P extends Brand<any, any>> = P extends infer Q & Brands<P> ? Q : P;
24
26
 
25
- export type Brands<P extends Brand<any, any>> = Union.IntersectionOf<{
26
- [K in keyof P[Branded.Symbol]]: P extends P[Branded.Symbol][K]
27
- ? K extends string
28
- ? Brand<P[Branded.Symbol][K], K>
29
- : never
30
- : never;
31
- }[keyof P[Branded.Symbol]]>;
27
+ export type Brands<P extends Brand<any, any>> = Union.IntersectionOf<
28
+ {
29
+ [K in keyof P[Branded.Symbol]]: P extends P[Branded.Symbol][K]
30
+ ? K extends string
31
+ ? Brand<P[Branded.Symbol][K], K>
32
+ : never
33
+ : never;
34
+ }[keyof P[Branded.Symbol]]
35
+ >;
32
36
  }
33
37
 
34
38
  /**
@@ -10,11 +10,11 @@ import { Decoder } from "@fncts/base/data/Decoder/definition";
10
10
  export function deriveGuard<A extends Branded.Brand<any, any>>(
11
11
  ...[base, brands]: Check<Branded.IsValidated<A>> extends Check.True
12
12
  ? [
13
- base: Guard<Branded.Unbrand<A>>,
14
- brands: {
15
- [K in keyof A[Branded.Symbol] & string]: Brand<A[Branded.Symbol][K], K>;
16
- }
17
- ]
13
+ base: Guard<Branded.Unbrand<A>>,
14
+ brands: {
15
+ [K in keyof A[Branded.Symbol] & string]: Brand<A[Branded.Symbol][K], K>;
16
+ },
17
+ ]
18
18
  : never
19
19
  ): Guard<A> {
20
20
  const validations = Object.values(brands) as ReadonlyArray<Brand<A, any>>;
@@ -35,23 +35,24 @@ export function deriveDecoder<A extends Branded.Brand<any, any>>(
35
35
  : never
36
36
  ): Decoder<A> {
37
37
  const label = "Brand<" + Object.keys(brands).join(" & ") + ">";
38
- return Decoder((u) => base.decode(u).match2(
39
- These.left,
40
- (warning, value) => {
41
- const failedBrands: Array<string> = [];
42
- for (const brand in brands) {
43
- if (!brands[brand]!.validate(value as any)) {
44
- failedBrands.push(brand);
38
+ return Decoder(
39
+ (u) =>
40
+ base.decode(u).match2(These.left, (warning, value) => {
41
+ const failedBrands: Array<string> = [];
42
+ for (const brand in brands) {
43
+ if (!brands[brand]!.validate(value as any)) {
44
+ failedBrands.push(brand);
45
+ }
46
+ }
47
+ if (failedBrands.length > 0) {
48
+ const error = new BrandedError(label, Vector.from(failedBrands));
49
+ return warning.match(
50
+ () => These.left(error),
51
+ (warning) => These.left(new CompoundError(label, Vector(warning, error))),
52
+ );
45
53
  }
46
- }
47
- if (failedBrands.length > 0) {
48
- const error = new BrandedError(label, Vector.from(failedBrands));
49
- return warning.match(
50
- () => These.left(error),
51
- (warning) => These.left(new CompoundError(label, Vector(warning, error)))
52
- );
53
- }
54
- return These.rightOrBoth(warning, value);
55
- }
56
- ), label);
54
+ return These.rightOrBoth(warning, value);
55
+ }),
56
+ label,
57
+ );
57
58
  }
@@ -1,4 +1,4 @@
1
1
  // codegen:start { preset: barrel, include: ./Branded/*.ts }
2
2
  export * from "./Branded/definition.js";
3
3
  export * from "./Branded/derivations.js";
4
- // codegen:end
4
+ // codegen:end
@@ -66,8 +66,7 @@ export const CaseClass: CaseConstructor = class<T extends Record<PropertyKey, an
66
66
 
67
67
  while (result && i < len) {
68
68
  result =
69
- this[keysSymbol][i] === thatKeys[i] &&
70
- (this[this[keysSymbol]![i]!] as {}) == (that as T)[thatKeys[i]!];
69
+ this[keysSymbol][i] === thatKeys[i] && (this[this[keysSymbol]![i]!] as {}) == (that as T)[thatKeys[i]!];
71
70
  i++;
72
71
  }
73
72
 
@@ -1017,11 +1017,3 @@ export function traced<E>(cause: Cause<E>, trace: Trace): Cause<E> {
1017
1017
  export function untraced<E>(self: Cause<E>): Cause<E> {
1018
1018
  return self.mapTrace(() => Trace.none);
1019
1019
  }
1020
-
1021
- // codegen:start { preset: barrel, include: api/*.ts }
1022
- export * from "./api/fold.js";
1023
- export * from "./api/isEmpty.js";
1024
- export * from "./api/linearize.js";
1025
- export * from "./api/prettyPrint.js";
1026
- export * from "./api/unified.js";
1027
- // codegen:end
@@ -2,3 +2,11 @@
2
2
  export * from "./Cause/api.js";
3
3
  export * from "./Cause/definition.js";
4
4
  // codegen:end
5
+
6
+ // codegen:start { preset: barrel, include: Cause/api/*.ts }
7
+ export * from "./Cause/api/fold.js";
8
+ export * from "./Cause/api/isEmpty.js";
9
+ export * from "./Cause/api/linearize.js";
10
+ export * from "./Cause/api/prettyPrint.js";
11
+ export * from "./Cause/api/unified.js";
12
+ // codegen:end
@@ -25,4 +25,4 @@ export interface Const1<E, A> {
25
25
  readonly [HKT.E]: () => E;
26
26
  readonly [HKT.A]: () => A;
27
27
  readonly [HKT.T]: Const<E, HKT._A<this>>;
28
- }
28
+ }
@@ -1,3 +1,3 @@
1
1
  // codegen:start { preset: barrel, include: ./DecodeError/*.ts }
2
2
  export * from "./DecodeError/definition.js";
3
- // codegen:end
3
+ // codegen:end
@@ -41,6 +41,7 @@ export const number: Decoder<number> = fromGuard(Number.Guard, (u) => new Primit
41
41
  export const boolean: Decoder<boolean> = fromGuard(Boolean.Guard, (u) => new PrimitiveError(u, "boolean"), "boolean");
42
42
 
43
43
  /**
44
+ * @tsplus static fncts.DecoderOps record
44
45
  * @tsplus implicit
45
46
  */
46
47
  export const record: Decoder<{}> = fromGuard(Object.Guard, (u) => new PrimitiveError(u, "{}"), "{}");
@@ -95,7 +96,7 @@ export function deriveUnion<A extends ReadonlyArray<unknown>>(
95
96
  }
96
97
 
97
98
  /**
98
- * @tsplus derive fncts.Decoder<_> 10
99
+ * @tsplus derive fncts.Decoder<_> 20
99
100
  */
100
101
  export function deriveStruct<A extends Record<string, any>>(
101
102
  ...[requiredFields, optionalFields]: Check<Check.IsStruct<A>> extends Check.True
@@ -73,4 +73,4 @@ export function difference(self: Duration, that: Duration): Duration {
73
73
  */
74
74
  export function fromInterval(start: number, end: number): Duration {
75
75
  return Duration.milliseconds(Math.round(end) - Math.round(start));
76
- }
76
+ }
@@ -40,4 +40,4 @@ export function zip_<A, B>(fa: Identity<A>, fb: Identity<B>): Identity<readonly
40
40
  */
41
41
  export function getIdentity<A>(self: Identity<A>): A {
42
42
  return Identity.reverseGet(self);
43
- }
43
+ }
@@ -1,5 +1,5 @@
1
1
  export interface IdentityN {
2
- readonly [HKT.T]: Identity<HKT._A<this>>
2
+ readonly [HKT.T]: Identity<HKT._A<this>>;
3
3
  }
4
4
 
5
5
  /**
@@ -177,7 +177,7 @@ export function condemn<E, A>(self: These<E, A>): These<E, A> {
177
177
  * @tsplus fluent fncts.These condemnWhen
178
178
  */
179
179
  export function condemnWhen<E, A>(self: These<E, A>, p: Predicate<E>): These<E, A> {
180
- if(self._tag === TheseTag.Both && p(self.left)) {
180
+ if (self._tag === TheseTag.Both && p(self.left)) {
181
181
  return These.left(self.left);
182
182
  }
183
183
  return self;
@@ -30,6 +30,6 @@ export function both<E = never, A = never>(e: E, a: A): These<E, A> {
30
30
  export function rightOrBoth<E = never, A = never>(e: Maybe<E>, a: A): These<E, A> {
31
31
  return e.match(
32
32
  () => These.right(a),
33
- (e) => These.both(e, a)
33
+ (e) => These.both(e, a),
34
34
  );
35
35
  }
@@ -51,4 +51,4 @@ export const These: TheseOps = {};
51
51
  */
52
52
  export function isThese(u: unknown): u is These<unknown, unknown> {
53
53
  return hasTypeId(u, TheseTypeId);
54
- }
54
+ }
@@ -50,16 +50,12 @@ export function match_<E, A, B, C, D>(
50
50
  /**
51
51
  * @tsplus fluent fncts.These match2
52
52
  */
53
- export function match2<E, A, B, C>(
54
- self: These<E, A>,
55
- left: (e: E) => B,
56
- right: (e: Maybe<E>, a: A) => C
57
- ): B | C {
58
- switch(self._tag) {
53
+ export function match2<E, A, B, C>(self: These<E, A>, left: (e: E) => B, right: (e: Maybe<E>, a: A) => C): B | C {
54
+ switch (self._tag) {
59
55
  case TheseTag.Left:
60
56
  return left(self.left);
61
57
  case TheseTag.Right:
62
58
  case TheseTag.Both:
63
59
  return right(self.leftMaybe, self.right);
64
60
  }
65
- }
61
+ }
@@ -3,4 +3,5 @@ export * from "./These/api.js";
3
3
  export * from "./These/constructors.js";
4
4
  export * from "./These/definition.js";
5
5
  export * from "./These/destructors.js";
6
+ export * from "./These/instances.js";
6
7
  // codegen:end
@@ -10,4 +10,4 @@ declare global {
10
10
  interface BigIntConstructor {}
11
11
  }
12
12
 
13
- export {};
13
+ export {};
@@ -1,4 +1,4 @@
1
1
  // codegen:start { preset: barrel, include: ./bigint/*.ts }
2
2
  export * from "./bigint/definition.js";
3
3
  export * from "./bigint/instances.js";
4
- // codegen:end
4
+ // codegen:end
@@ -5,4 +5,4 @@ import { isBoolean } from "@fncts/base/util/predicates";
5
5
  * @tsplus static fncts.BooleanOps Guard
6
6
  * @tsplus implicit
7
7
  */
8
- export const Guard: P.Guard<boolean> = P.Guard(isBoolean);
8
+ export const Guard: P.Guard<boolean> = P.Guard(isBoolean);
@@ -1,4 +1,4 @@
1
1
  // codegen:start { preset: barrel, include: ./boolean/*.ts }
2
2
  export * from "./boolean/definition.js";
3
3
  export * from "./boolean/instances.js";
4
- // codegen:end
4
+ // codegen:end
File without changes
@@ -6,4 +6,5 @@ export * from "./exceptions/IndexOutOfBoundsError.js";
6
6
  export * from "./exceptions/InterruptedException.js";
7
7
  export * from "./exceptions/InvalidCapacityError.js";
8
8
  export * from "./exceptions/NoSuchElementError.js";
9
+ export * from "./exceptions/RuntimeError.js";
9
10
  // codegen:end
@@ -22,4 +22,4 @@ export const Ord: P.Ord<number> = P.Ord({
22
22
  * @tsplus static fncts.NumberOps Guard
23
23
  * @tsplus implicit
24
24
  */
25
- export const Guard: P.Guard<number> = P.Guard(isNumber);
25
+ export const Guard: P.Guard<number> = P.Guard(isNumber);
@@ -1,3 +1,4 @@
1
1
  // codegen:start { preset: barrel, include: ./object/*.ts }
2
2
  export * from "./object/definition.js";
3
+ export * from "./object/instances.js";
3
4
  // codegen:end
@@ -33,4 +33,4 @@ export const Ord: P.Ord<string> = P.Ord({
33
33
  * @tsplus static fncts.StringOps Guard
34
34
  * @tsplus implicit
35
35
  */
36
- export const Guard: P.Guard<string> = P.Guard(isString);
36
+ export const Guard: P.Guard<string> = P.Guard(isString);
@@ -1,10 +1,10 @@
1
1
  export interface NothingJson {
2
- readonly _tag: "Nothing"
2
+ readonly _tag: "Nothing";
3
3
  }
4
4
 
5
5
  export interface JustJson<A> {
6
- readonly _tag: "Just"
7
- readonly value: A
6
+ readonly _tag: "Just";
7
+ readonly value: A;
8
8
  }
9
9
 
10
10
  /**
@@ -24,4 +24,4 @@ export const MaybeJson: MaybeJsonOps = {};
24
24
  */
25
25
  export function getDecoder<A>(value: Decoder<A>): Decoder<MaybeJson<A>> {
26
26
  return Derive();
27
- }
27
+ }
@@ -11,4 +11,4 @@ export interface Align<F extends HKT> extends Semialign<F>, Nil<F> {}
11
11
  */
12
12
  export interface AlignOps {}
13
13
 
14
- export const Align: AlignOps = {};
14
+ export const Align: AlignOps = {};
@@ -17,4 +17,4 @@ export const Closure: ClosureOps = {};
17
17
  */
18
18
  export function mkClosure<A>(F: Closure<A>): Closure<A> {
19
19
  return F;
20
- }
20
+ }
@@ -2,7 +2,7 @@
2
2
  * @tsplus type fncts.Eq
3
3
  */
4
4
  export interface Eq<A> {
5
- readonly equals: (x: A, y: A) => boolean
5
+ readonly equals: (x: A, y: A) => boolean;
6
6
  }
7
7
 
8
8
  /**
@@ -17,4 +17,4 @@ export const Eq: EqOps = {};
17
17
  */
18
18
  export function mkEq<A>(E: Eq<A>): Eq<A> {
19
19
  return E;
20
- }
20
+ }
@@ -29,4 +29,4 @@ export function assert<A>(self: Guard<A>, u: unknown): asserts u is A {
29
29
  if (!self.is(u)) {
30
30
  throw new AssertionError("Guard failed check failed");
31
31
  }
32
- }
32
+ }
@@ -20,4 +20,4 @@ export class Guard<A> {
20
20
  */
21
21
  export function makeGuard<A>(refinement: Refinement<unknown, A>): Guard<A> {
22
22
  return new Guard(refinement);
23
- }
23
+ }
@@ -4,9 +4,7 @@ import type { OptionalKeys, RequiredKeys } from "@fncts/typelevel/Object";
4
4
  /**
5
5
  * @tsplus derive fncts.Guard lazy
6
6
  */
7
- export function deriveLazy<A>(
8
- f: (_: Guard<A>) => Guard<A>
9
- ): Guard<A> {
7
+ export function deriveLazy<A>(f: (_: Guard<A>) => Guard<A>): Guard<A> {
10
8
  let cached: Guard<A> | undefined;
11
9
  const guard: Guard<A> = Guard((u: unknown): u is A => {
12
10
  if (!cached) {
@@ -30,18 +28,21 @@ export function deriveLiteral<A extends string | number | boolean>(
30
28
  * @tsplus derive fncts.Guard<_> 20
31
29
  */
32
30
  export function deriveStruct<A extends Record<string, any>>(
33
- ...[requiredFields, optionalFields]: Check<Check.IsStruct<A>> extends Check.True ? [
34
- ...[
35
- requiredFields: {
36
- [k in RequiredKeys<A>]: Guard<A[k]>;
37
- }
38
- ],
39
- ...([OptionalKeys<A>] extends [never] ? [] : [
40
- optionalFields: {
41
- [k in OptionalKeys<A>]: Guard<NonNullable<A[k]>>;
42
- }
43
- ])
44
- ]
31
+ ...[requiredFields, optionalFields]: Check<Check.IsStruct<A>> extends Check.True
32
+ ? [
33
+ ...[
34
+ requiredFields: {
35
+ [k in RequiredKeys<A>]: Guard<A[k]>;
36
+ },
37
+ ],
38
+ ...([OptionalKeys<A>] extends [never]
39
+ ? []
40
+ : [
41
+ optionalFields: {
42
+ [k in OptionalKeys<A>]: Guard<NonNullable<A[k]>>;
43
+ },
44
+ ]),
45
+ ]
45
46
  : never
46
47
  ): Guard<A> {
47
48
  return Guard((u): u is A => {
@@ -71,7 +72,7 @@ export function deriveStruct<A extends Record<string, any>>(
71
72
  export function deriveUnion<A extends unknown[]>(...members: { [K in keyof A]: Guard<A[K]> }): Guard<A[number]> {
72
73
  return Guard((u): u is A[number] => {
73
74
  for (const member of members) {
74
- if(member.is(u)) {
75
+ if (member.is(u)) {
75
76
  return true;
76
77
  }
77
78
  }
@@ -2,4 +2,3 @@
2
2
  export * from "./Guard/api.js";
3
3
  export * from "./Guard/definition.js";
4
4
  // codegen:end
5
-
@@ -48,7 +48,7 @@ export function deriveLazy<A>(fn: (_: Monoid<A>) => Monoid<A>): Monoid<A> {
48
48
  cached = fn(M);
49
49
  }
50
50
  return cached.nat;
51
- }
51
+ },
52
52
  });
53
53
  return M;
54
54
  }
@@ -74,8 +74,8 @@ export function deriveStruct<A extends Record<string, any>>(
74
74
  ]
75
75
  : never
76
76
  ): Monoid<A> {
77
- const [ requiredFields, optionalFields ] = args;
78
- const nat: Record<string, unknown> = {};
77
+ const [requiredFields, optionalFields] = args;
78
+ const nat: Record<string, unknown> = {};
79
79
  for (const field in requiredFields) {
80
80
  nat[field] = (requiredFields[field] as Monoid<any>).nat;
81
81
  }
@@ -84,6 +84,6 @@ export function deriveStruct<A extends Record<string, any>>(
84
84
  }
85
85
  return Monoid({
86
86
  ...Semigroup.deriveStruct<A>(...args),
87
- nat: nat as A
87
+ nat: nat as A,
88
88
  });
89
89
  }
@@ -204,7 +204,6 @@ export function alignCombine<F extends HKT, K, Q, W, X, I, S, R, E, A, K1, Q1, W
204
204
  HKT.Mix<"E", [E, E1]>,
205
205
  A
206
206
  > {
207
-
208
207
  return self.alignWith(that, (th) => th.match(identity, identity, S.combine));
209
208
  }
210
209
 
@@ -331,14 +330,12 @@ export function padZipWith<F extends HKT, K, Q, W, X, I, S, R, E, A, K1, Q1, W1,
331
330
  HKT.Mix<"E", [E, E1]>,
332
331
  D
333
332
  > {
334
- return fa.alignWith(
335
- fb,
336
- (th) =>
337
- th.match(
338
- (a) => f([Just(a), Nothing()]),
339
- (b) => f([Nothing(), Just(b)]),
340
- (a, b) => f([Just(a), Just(b)]),
341
- ),
333
+ return fa.alignWith(fb, (th) =>
334
+ th.match(
335
+ (a) => f([Just(a), Nothing()]),
336
+ (b) => f([Nothing(), Just(b)]),
337
+ (a, b) => f([Just(a), Just(b)]),
338
+ ),
342
339
  );
343
340
  }
344
341
 
@@ -61,4 +61,4 @@ export function deriveStruct<A extends Record<string, any>>(
61
61
  return out as A;
62
62
  },
63
63
  });
64
- }
64
+ }
@@ -544,9 +544,9 @@ function showSet(value: Set<unknown>): ShowComputationChunk {
544
544
  function showMap(value: Map<unknown, unknown>): ShowComputationChunk {
545
545
  return Z.update((_: ShowContext) => _.copy({ indentationLevel: _.indentationLevel + 2 }))
546
546
  .apSecond(
547
- (value as Iterable<[unknown, unknown]>).traverseToConc(([k, v]) =>
548
- _show(k).crossWith(_show(v), (k, v) => `${k} => ${v}`),
549
- Z.Applicative
547
+ (value as Iterable<[unknown, unknown]>).traverseToConc(
548
+ ([k, v]) => _show(k).crossWith(_show(v), (k, v) => `${k} => ${v}`),
549
+ Z.Applicative,
550
550
  ),
551
551
  )
552
552
  .apFirst(
@@ -578,7 +578,10 @@ function showTypedArray(value: TypedArray): ShowComputationChunk {
578
578
  .apSecond(
579
579
  Z.succeedNow(output).flatMap((output) =>
580
580
  Conc("BYTES_PER_ELEMENT", "length", "byteLength", "byteOffset", "buffer")
581
- .traverse((key) => _show(value[key as keyof TypedArray]).map((shown) => `[${key}]: ${shown}`), Z.Applicative)
581
+ .traverse(
582
+ (key) => _show(value[key as keyof TypedArray]).map((shown) => `[${key}]: ${shown}`),
583
+ Z.Applicative,
584
+ )
582
585
  .map((shownKeys) => output.concat(shownKeys)),
583
586
  ),
584
587
  )
@@ -888,7 +891,7 @@ function _showString(context: ShowContext, value: string): string {
888
891
  ) {
889
892
  return (
890
893
  result
891
- .split(/(?<=\n)/)
894
+ .split(/(?!\n)/)
892
895
  .map((line) => context.stylize(strEscape(line), "string"))
893
896
  .join(` +\n${" ".repeat(context.indentationLevel + 2)}`) + trailer
894
897
  );
package/_src/typeclass.ts CHANGED
@@ -37,4 +37,3 @@ export * from "./typeclass/TraversableWithIndex.js";
37
37
  export * from "./typeclass/Witherable.js";
38
38
  export * from "./typeclass/WitherableWithIndex.js";
39
39
  // codegen:end
40
-
@@ -79,6 +79,11 @@ export declare function filterWithIndex_<A>(self: Iterable<A>, p: PredicateWithI
79
79
  */
80
80
  export declare function find_<A, B extends A>(ia: Iterable<A>, refinement: Refinement<A, B>): Maybe<B>;
81
81
  export declare function find_<A>(ia: Iterable<A>, predicate: Predicate<A>): Maybe<A>;
82
+ /**
83
+ * @tsplus fluent fncts.Iterable findIndex
84
+ * @tsplus location "@fncts/base/collection/Iterable/api"
85
+ */
86
+ export declare function findIndex<A>(self: Iterable<A>, p: Predicate<A>): number;
82
87
  /**
83
88
  * @tsplus fluent fncts.Iterable foldLeftWithIndex
84
89
  * @tsplus location "@fncts/base/collection/Iterable/api"
@@ -147,6 +152,11 @@ export declare function partitionWithIndex_<A>(self: Iterable<A>, p: PredicateWi
147
152
  * @tsplus location "@fncts/base/collection/Iterable/api"
148
153
  */
149
154
  export declare function size<A>(self: Iterable<A>): number;
155
+ /**
156
+ * @tsplus getter fncts.Iterable sum
157
+ * @tsplus location "@fncts/base/collection/Iterable/api"
158
+ */
159
+ export declare function sum(self: Iterable<number>): number;
150
160
  /**
151
161
  * @tsplus fluent fncts.Iterable take
152
162
  * @tsplus location "@fncts/base/collection/Iterable/api"
@@ -0,0 +1,10 @@
1
+ import { Guard } from "@fncts/base/typeclass/Guard";
2
+ import { Decoder } from "@fncts/base/data/Decoder";
3
+ import type { Check } from "@fncts/typelevel/Check";
4
+ /**
5
+ * @tsplus derive fncts.Decoder<_> 15
6
+ * @tsplus location "@fncts/base/collection/compat/Record/instances"
7
+ */
8
+ export declare function deriveDecoder<A extends Record<string, any>>(...[keyGuard, valueDecoder, requiredKeysRecord]: [A] extends [Record<infer X, infer Y>] ? Check<Check.Not<Check.IsUnion<A>> & Check.IsEqual<A, Record<X, Y>>> extends Check.True ? [keyGuard: Guard<X>, valueDecoder: Decoder<Y>, requiredKeysRecord: {
9
+ [k in X]: 0;
10
+ }] : never : never): Decoder<A>;
@@ -0,0 +1 @@
1
+ export * from "./Record/instances.js";