@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.
- package/_cjs/collection/Iterable/api.cjs +32 -4
- package/_cjs/collection/Iterable/api.cjs.map +1 -1
- package/_cjs/collection/compat/Record/instances.cjs +77 -0
- package/_cjs/collection/compat/Record/instances.cjs.map +1 -0
- package/_cjs/collection/compat/Record.cjs +19 -0
- package/_cjs/collection/compat/Record.cjs.map +1 -0
- package/_cjs/collection/immutable/Conc/api.cjs +22 -1
- package/_cjs/collection/immutable/Conc/api.cjs.map +1 -1
- package/_cjs/collection/immutable/Dictionary/api.cjs +7 -8
- package/_cjs/collection/immutable/Dictionary/api.cjs.map +1 -1
- package/_cjs/collection/immutable/HashMap/api.cjs.map +1 -1
- package/_cjs/collection/immutable/ImmutableArray/api.cjs +1 -1
- package/_cjs/collection/immutable/ImmutableArray/api.cjs.map +1 -1
- package/_cjs/collection/immutable/ImmutableNonEmptyArray/instances.cjs.map +1 -1
- package/_cjs/collection/weak/IterableWeakMap.cjs +83 -0
- package/_cjs/collection/weak/IterableWeakMap.cjs.map +1 -0
- package/_cjs/collection/weak/IterableWeakSet.cjs +73 -0
- package/_cjs/collection/weak/IterableWeakSet.cjs.map +1 -0
- package/_cjs/data/Branded/definition.cjs.map +1 -1
- package/_cjs/data/Branded/derivations.cjs.map +1 -1
- package/_cjs/data/CaseClass.cjs.map +1 -1
- package/_cjs/data/Cause/api.cjs +1 -119
- package/_cjs/data/Cause/api.cjs.map +1 -1
- package/_cjs/data/Cause.cjs +65 -0
- package/_cjs/data/Cause.cjs.map +1 -1
- package/_cjs/data/Decoder/api.cjs +5 -3
- package/_cjs/data/Decoder/api.cjs.map +1 -1
- package/_cjs/data/Struct/api.cjs +10 -12
- package/_cjs/data/Struct/api.cjs.map +1 -1
- package/_cjs/data/These/api.cjs.map +1 -1
- package/_cjs/data/These/destructors.cjs.map +1 -1
- package/_cjs/data/These.cjs +13 -0
- package/_cjs/data/These.cjs.map +1 -1
- package/_cjs/data/exceptions/RuntimeError.cjs +6 -0
- package/_cjs/data/exceptions/RuntimeError.cjs.map +1 -0
- package/_cjs/data/exceptions.cjs +13 -0
- package/_cjs/data/exceptions.cjs.map +1 -1
- package/_cjs/data/object.cjs +13 -0
- package/_cjs/data/object.cjs.map +1 -1
- package/_cjs/json/EitherJson.cjs +4 -4
- package/_cjs/json/EitherJson.cjs.map +1 -1
- package/_cjs/json/MaybeJson.cjs +3 -3
- package/_cjs/json/MaybeJson.cjs.map +1 -1
- package/_cjs/json/TheseJson.cjs +7 -7
- package/_cjs/json/TheseJson.cjs.map +1 -1
- package/_cjs/optics/Traversal/definition.cjs +9 -11
- package/_cjs/optics/Traversal/definition.cjs.map +1 -1
- package/_cjs/typeclass/Guard/derivations.cjs.map +1 -1
- package/_cjs/typeclass/Monoid.cjs.map +1 -1
- package/_cjs/typeclass/Semialign.cjs.map +1 -1
- package/_cjs/typeclass/Showable/show.cjs +7 -7
- package/_cjs/typeclass/Showable/show.cjs.map +1 -1
- package/_cjs/util/AnsiFormat.cjs +5 -5
- package/_cjs/util/AnsiFormat.cjs.map +1 -1
- package/_mjs/collection/Iterable/api.mjs +27 -1
- package/_mjs/collection/Iterable/api.mjs.map +1 -1
- package/_mjs/collection/compat/Record/instances.mjs +59 -0
- package/_mjs/collection/compat/Record/instances.mjs.map +1 -0
- package/_mjs/collection/compat/Record.mjs +3 -0
- package/_mjs/collection/compat/Record.mjs.map +1 -0
- package/_mjs/collection/immutable/Conc/api.mjs +21 -2
- package/_mjs/collection/immutable/Conc/api.mjs.map +1 -1
- package/_mjs/collection/immutable/Dictionary/api.mjs +5 -7
- package/_mjs/collection/immutable/Dictionary/api.mjs.map +1 -1
- package/_mjs/collection/immutable/HashMap/api.mjs.map +1 -1
- package/_mjs/collection/immutable/ImmutableArray/api.mjs +1 -1
- package/_mjs/collection/immutable/ImmutableArray/api.mjs.map +1 -1
- package/_mjs/collection/immutable/ImmutableNonEmptyArray/instances.mjs.map +1 -1
- package/_mjs/collection/weak/IterableWeakMap.mjs +74 -0
- package/_mjs/collection/weak/IterableWeakMap.mjs.map +1 -0
- package/_mjs/collection/weak/IterableWeakSet.mjs +64 -0
- package/_mjs/collection/weak/IterableWeakSet.mjs.map +1 -0
- package/_mjs/data/Branded/definition.mjs.map +1 -1
- package/_mjs/data/Branded/derivations.mjs.map +1 -1
- package/_mjs/data/CaseClass.mjs.map +1 -1
- package/_mjs/data/Cause/api.mjs +1 -7
- package/_mjs/data/Cause/api.mjs.map +1 -1
- package/_mjs/data/Cause.mjs +8 -1
- package/_mjs/data/Cause.mjs.map +1 -1
- package/_mjs/data/Decoder/api.mjs +5 -3
- package/_mjs/data/Decoder/api.mjs.map +1 -1
- package/_mjs/data/Struct/api.mjs +9 -10
- package/_mjs/data/Struct/api.mjs.map +1 -1
- package/_mjs/data/These/api.mjs.map +1 -1
- package/_mjs/data/These/destructors.mjs.map +1 -1
- package/_mjs/data/These.mjs +1 -0
- package/_mjs/data/These.mjs.map +1 -1
- package/_mjs/data/exceptions/RuntimeError.mjs +2 -0
- package/_mjs/data/exceptions/RuntimeError.mjs.map +1 -0
- package/_mjs/data/exceptions.mjs +1 -0
- package/_mjs/data/exceptions.mjs.map +1 -1
- package/_mjs/data/object.mjs +1 -0
- package/_mjs/data/object.mjs.map +1 -1
- package/_mjs/json/EitherJson.mjs +4 -4
- package/_mjs/json/EitherJson.mjs.map +1 -1
- package/_mjs/json/MaybeJson.mjs +3 -3
- package/_mjs/json/MaybeJson.mjs.map +1 -1
- package/_mjs/json/TheseJson.mjs +7 -7
- package/_mjs/json/TheseJson.mjs.map +1 -1
- package/_mjs/optics/Traversal/definition.mjs +9 -10
- package/_mjs/optics/Traversal/definition.mjs.map +1 -1
- package/_mjs/typeclass/Guard/derivations.mjs.map +1 -1
- package/_mjs/typeclass/Monoid.mjs.map +1 -1
- package/_mjs/typeclass/Semialign.mjs.map +1 -1
- package/_mjs/typeclass/Showable/show.mjs +7 -7
- package/_mjs/typeclass/Showable/show.mjs.map +1 -1
- package/_mjs/util/AnsiFormat.mjs +5 -5
- package/_mjs/util/AnsiFormat.mjs.map +1 -1
- package/_src/collection/Iterable/api.ts +21 -0
- package/_src/collection/compat/Record/instances.ts +59 -0
- package/_src/collection/compat/Record.ts +3 -0
- package/_src/collection/immutable/Conc/api.ts +17 -1
- package/_src/collection/immutable/HashMap/api.ts +1 -2
- package/_src/collection/immutable/ImmutableNonEmptyArray/instances.ts +14 -14
- package/_src/collection/immutable/RoseTree.ts +1 -1
- package/_src/collection/immutable/Vector/definition.ts +2 -2
- package/_src/collection/weak/IterableWeakMap.ts +63 -0
- package/_src/collection/weak/IterableWeakSet.ts +56 -0
- package/_src/data/Branded/definition.ts +13 -9
- package/_src/data/Branded/derivations.ts +24 -23
- package/_src/data/Branded.ts +1 -1
- package/_src/data/CaseClass.ts +1 -2
- package/_src/data/Cause/api.ts +0 -8
- package/_src/data/Cause.ts +8 -0
- package/_src/data/Const/definition.ts +1 -1
- package/_src/data/DecodeError.ts +1 -1
- package/_src/data/Decoder/api.ts +2 -1
- package/_src/data/Duration/api.ts +1 -1
- package/_src/data/Identity/api.ts +1 -1
- package/_src/data/Identity/definition.ts +1 -1
- package/_src/data/These/api.ts +1 -1
- package/_src/data/These/constructors.ts +1 -1
- package/_src/data/These/definition.ts +1 -1
- package/_src/data/These/destructors.ts +3 -7
- package/_src/data/These.ts +1 -0
- package/_src/data/bigint/definition.ts +1 -1
- package/_src/data/bigint.ts +1 -1
- package/_src/data/boolean/instances.ts +1 -1
- package/_src/data/boolean.ts +1 -1
- package/_src/data/exceptions/RuntimeError.ts +0 -0
- package/_src/data/exceptions.ts +1 -0
- package/_src/data/number/instances.ts +1 -1
- package/_src/data/object.ts +1 -0
- package/_src/data/string/instances.ts +1 -1
- package/_src/json/MaybeJson.ts +4 -4
- package/_src/typeclass/Align.ts +1 -1
- package/_src/typeclass/Closure.ts +1 -1
- package/_src/typeclass/Eq/definition.ts +2 -2
- package/_src/typeclass/Guard/api.ts +1 -1
- package/_src/typeclass/Guard/definition.ts +1 -1
- package/_src/typeclass/Guard/derivations.ts +17 -16
- package/_src/typeclass/Guard.ts +0 -1
- package/_src/typeclass/Monoid.ts +4 -4
- package/_src/typeclass/Semialign.ts +6 -9
- package/_src/typeclass/Semigroup/derivations.ts +1 -1
- package/_src/typeclass/Showable/show.ts +8 -5
- package/_src/typeclass.ts +0 -1
- package/collection/Iterable/api.d.ts +10 -0
- package/collection/compat/Record/instances.d.ts +10 -0
- package/collection/compat/Record.d.ts +1 -0
- package/collection/immutable/Conc/api.d.ts +6 -1
- package/collection/immutable/ImmutableArray/api.d.ts +1 -0
- package/collection/weak/IterableWeakMap.d.ts +16 -0
- package/collection/weak/IterableWeakSet.d.ts +15 -0
- package/data/Cause/api.d.ts +0 -5
- package/data/Cause.d.ts +5 -0
- package/data/Decoder/api.d.ts +2 -1
- package/data/These.d.ts +1 -0
- package/data/exceptions/RuntimeError.d.ts +1 -0
- package/data/exceptions.d.ts +1 -0
- package/data/object.d.ts +1 -0
- 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
|
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
|
-
|
27
|
-
|
28
|
-
?
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
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(
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
48
|
-
|
49
|
-
|
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
|
}
|
package/_src/data/Branded.ts
CHANGED
package/_src/data/CaseClass.ts
CHANGED
@@ -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
|
|
package/_src/data/Cause/api.ts
CHANGED
@@ -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
|
package/_src/data/Cause.ts
CHANGED
@@ -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
|
package/_src/data/DecodeError.ts
CHANGED
package/_src/data/Decoder/api.ts
CHANGED
@@ -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<_>
|
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
|
package/_src/data/These/api.ts
CHANGED
@@ -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
|
}
|
@@ -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
|
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
|
+
}
|
package/_src/data/These.ts
CHANGED
package/_src/data/bigint.ts
CHANGED
package/_src/data/boolean.ts
CHANGED
File without changes
|
package/_src/data/exceptions.ts
CHANGED
@@ -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
|
package/_src/data/object.ts
CHANGED
package/_src/json/MaybeJson.ts
CHANGED
@@ -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
|
+
}
|
package/_src/typeclass/Align.ts
CHANGED
@@ -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
|
+
}
|
@@ -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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
}
|
package/_src/typeclass/Guard.ts
CHANGED
package/_src/typeclass/Monoid.ts
CHANGED
@@ -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 [
|
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
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
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
|
|
@@ -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(
|
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(
|
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(/(
|
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
@@ -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";
|