@fncts/base 0.0.30 → 0.0.32
Sign up to get free protection for your applications and to get access to all the features.
- package/_cjs/collection/compat/Array/api.cjs +53 -0
- package/_cjs/collection/compat/Array/api.cjs.map +1 -1
- package/_cjs/collection/immutable/Conc/api.cjs +4 -1
- package/_cjs/collection/immutable/Conc/api.cjs.map +1 -1
- package/_cjs/collection/immutable/Dictionary/api.cjs +54 -8
- package/_cjs/collection/immutable/Dictionary/api.cjs.map +1 -1
- package/_cjs/collection/immutable/HashMap/api.cjs +7 -4
- package/_cjs/collection/immutable/HashMap/api.cjs.map +1 -1
- package/_cjs/collection/immutable/HashSet/api.cjs +7 -4
- package/_cjs/collection/immutable/HashSet/api.cjs.map +1 -1
- package/_cjs/collection/immutable/ImmutableArray/api.cjs +9 -6
- package/_cjs/collection/immutable/ImmutableArray/api.cjs.map +1 -1
- package/_cjs/collection/internal.cjs +6 -0
- package/_cjs/collection/internal.cjs.map +1 -0
- package/_cjs/collection/mutable/ArrayDeque.cjs +214 -0
- package/_cjs/collection/mutable/ArrayDeque.cjs.map +1 -0
- package/_cjs/collection/mutable/Queue.cjs +21 -0
- package/_cjs/collection/mutable/Queue.cjs.map +1 -0
- package/_cjs/control/InterruptiblePromise.cjs +23 -0
- package/_cjs/control/InterruptiblePromise.cjs.map +1 -0
- package/_cjs/control/Pure/api.cjs +20 -8
- package/_cjs/control/Pure/api.cjs.map +1 -1
- package/_cjs/data/Cause/api.cjs +8 -2
- package/_cjs/data/Cause/api.cjs.map +1 -1
- package/_cjs/data/Date/definition.cjs +6 -0
- package/_cjs/data/Date/definition.cjs.map +1 -0
- package/_cjs/data/Date.cjs +17 -0
- package/_cjs/data/Date.cjs.map +1 -0
- package/_cjs/data/Datum/api.cjs +8 -2
- package/_cjs/data/Datum/api.cjs.map +1 -1
- package/_cjs/data/DatumEither/api.cjs +8 -2
- package/_cjs/data/DatumEither/api.cjs.map +1 -1
- package/_cjs/data/Either/api.cjs +24 -6
- package/_cjs/data/Either/api.cjs.map +1 -1
- package/_cjs/data/Either/destructors.cjs +3 -3
- package/_cjs/data/Either/destructors.cjs.map +1 -1
- package/_cjs/data/Either/instances.cjs +10 -1
- package/_cjs/data/Either/instances.cjs.map +1 -1
- package/_cjs/data/EitherT/api.cjs +8 -2
- package/_cjs/data/EitherT/api.cjs.map +1 -1
- package/_cjs/data/Exit/constructors.cjs +4 -1
- package/_cjs/data/Exit/constructors.cjs.map +1 -1
- package/_cjs/data/Global.cjs +22 -0
- package/_cjs/data/Global.cjs.map +1 -0
- package/_cjs/data/Maybe/api.cjs +4 -1
- package/_cjs/data/Maybe/api.cjs.map +1 -1
- package/_cjs/optics/Fold/api/focus.cjs +17 -0
- package/_cjs/optics/Fold/api/focus.cjs.map +1 -0
- package/_cjs/optics/Fold/definition.cjs.map +1 -1
- package/_cjs/optics/Getter/definition.cjs.map +1 -1
- package/_cjs/optics/Index/api.cjs +16 -0
- package/_cjs/optics/Index/api.cjs.map +1 -1
- package/_cjs/optics/Iso/api.cjs +14 -0
- package/_cjs/optics/Iso/api.cjs.map +1 -1
- package/_cjs/optics/Iso/definition.cjs.map +1 -1
- package/_cjs/optics/Lens/api.cjs +50 -24
- package/_cjs/optics/Lens/api.cjs.map +1 -1
- package/_cjs/optics/Lens/definition.cjs +1 -1
- package/_cjs/optics/Lens/definition.cjs.map +1 -1
- package/_cjs/optics/Optional/api/focus.cjs +23 -0
- package/_cjs/optics/Optional/api/focus.cjs.map +1 -0
- package/_cjs/optics/Optional/api.cjs +16 -0
- package/_cjs/optics/Optional/api.cjs.map +1 -0
- package/_cjs/optics/Optional/definition.cjs +4 -1
- package/_cjs/optics/Optional/definition.cjs.map +1 -1
- package/_cjs/optics/Optional.cjs +22 -0
- package/_cjs/optics/Optional.cjs.map +1 -1
- package/_cjs/optics/Prism/api/focus.cjs +21 -0
- package/_cjs/optics/Prism/api/focus.cjs.map +1 -0
- package/_cjs/optics/Prism/definition.cjs +4 -1
- package/_cjs/optics/Prism/definition.cjs.map +1 -1
- package/_cjs/optics/Prism.cjs +11 -0
- package/_cjs/optics/Prism.cjs.map +1 -1
- package/_cjs/optics/Setter/api/focus.cjs +18 -0
- package/_cjs/optics/Setter/api/focus.cjs.map +1 -0
- package/_cjs/optics/Setter/definition.cjs.map +1 -1
- package/_cjs/optics/Traversal/api/focus.cjs +23 -0
- package/_cjs/optics/Traversal/api/focus.cjs.map +1 -0
- package/_cjs/optics/Traversal/definition.cjs.map +1 -1
- package/_cjs/optics/Traversal.cjs +11 -0
- package/_cjs/optics/Traversal.cjs.map +1 -1
- package/_cjs/typeclass/MonadExcept.cjs +4 -1
- package/_cjs/typeclass/MonadExcept.cjs.map +1 -1
- package/_mjs/collection/compat/Array/api.mjs +48 -0
- package/_mjs/collection/compat/Array/api.mjs.map +1 -1
- package/_mjs/collection/immutable/Conc/api.mjs +4 -1
- package/_mjs/collection/immutable/Conc/api.mjs.map +1 -1
- package/_mjs/collection/immutable/Dictionary/api.mjs +47 -5
- package/_mjs/collection/immutable/Dictionary/api.mjs.map +1 -1
- package/_mjs/collection/immutable/HashMap/api.mjs +7 -4
- package/_mjs/collection/immutable/HashMap/api.mjs.map +1 -1
- package/_mjs/collection/immutable/HashSet/api.mjs +7 -4
- package/_mjs/collection/immutable/HashSet/api.mjs.map +1 -1
- package/_mjs/collection/immutable/ImmutableArray/api.mjs +9 -6
- package/_mjs/collection/immutable/ImmutableArray/api.mjs.map +1 -1
- package/_mjs/collection/internal.mjs +2 -0
- package/_mjs/collection/internal.mjs.map +1 -0
- package/_mjs/collection/mutable/ArrayDeque.mjs +205 -0
- package/_mjs/collection/mutable/ArrayDeque.mjs.map +1 -0
- package/_mjs/collection/mutable/Queue.mjs +14 -0
- package/_mjs/collection/mutable/Queue.mjs.map +1 -0
- package/_mjs/control/InterruptiblePromise.mjs +15 -0
- package/_mjs/control/InterruptiblePromise.mjs.map +1 -0
- package/_mjs/control/Pure/api.mjs +20 -8
- package/_mjs/control/Pure/api.mjs.map +1 -1
- package/_mjs/data/Cause/api.mjs +8 -2
- package/_mjs/data/Cause/api.mjs.map +1 -1
- package/_mjs/data/Date/definition.mjs +2 -0
- package/_mjs/data/Date/definition.mjs.map +1 -0
- package/_mjs/data/Date.mjs +3 -0
- package/_mjs/data/Date.mjs.map +1 -0
- package/_mjs/data/Datum/api.mjs +8 -2
- package/_mjs/data/Datum/api.mjs.map +1 -1
- package/_mjs/data/DatumEither/api.mjs +8 -2
- package/_mjs/data/DatumEither/api.mjs.map +1 -1
- package/_mjs/data/Either/api.mjs +24 -6
- package/_mjs/data/Either/api.mjs.map +1 -1
- package/_mjs/data/Either/destructors.mjs +3 -3
- package/_mjs/data/Either/destructors.mjs.map +1 -1
- package/_mjs/data/Either/instances.mjs +10 -1
- package/_mjs/data/Either/instances.mjs.map +1 -1
- package/_mjs/data/EitherT/api.mjs +8 -2
- package/_mjs/data/EitherT/api.mjs.map +1 -1
- package/_mjs/data/Exit/constructors.mjs +4 -1
- package/_mjs/data/Exit/constructors.mjs.map +1 -1
- package/_mjs/data/Global.mjs +15 -0
- package/_mjs/data/Global.mjs.map +1 -0
- package/_mjs/data/Maybe/api.mjs +4 -1
- package/_mjs/data/Maybe/api.mjs.map +1 -1
- package/_mjs/optics/Fold/api/focus.mjs +11 -0
- package/_mjs/optics/Fold/api/focus.mjs.map +1 -0
- package/_mjs/optics/Fold/definition.mjs.map +1 -1
- package/_mjs/optics/Getter/definition.mjs.map +1 -1
- package/_mjs/optics/Index/api.mjs +16 -0
- package/_mjs/optics/Index/api.mjs.map +1 -1
- package/_mjs/optics/Iso/api.mjs +13 -0
- package/_mjs/optics/Iso/api.mjs.map +1 -1
- package/_mjs/optics/Iso/definition.mjs.map +1 -1
- package/_mjs/optics/Lens/api.mjs +46 -22
- package/_mjs/optics/Lens/api.mjs.map +1 -1
- package/_mjs/optics/Lens/definition.mjs +1 -1
- package/_mjs/optics/Lens/definition.mjs.map +1 -1
- package/_mjs/optics/Optional/api/focus.mjs +15 -0
- package/_mjs/optics/Optional/api/focus.mjs.map +1 -0
- package/_mjs/optics/Optional/api.mjs +8 -0
- package/_mjs/optics/Optional/api.mjs.map +1 -0
- package/_mjs/optics/Optional/definition.mjs +4 -1
- package/_mjs/optics/Optional/definition.mjs.map +1 -1
- package/_mjs/optics/Optional.mjs +2 -0
- package/_mjs/optics/Optional.mjs.map +1 -1
- package/_mjs/optics/Prism/api/focus.mjs +13 -0
- package/_mjs/optics/Prism/api/focus.mjs.map +1 -0
- package/_mjs/optics/Prism/definition.mjs +4 -1
- package/_mjs/optics/Prism/definition.mjs.map +1 -1
- package/_mjs/optics/Prism.mjs +1 -0
- package/_mjs/optics/Prism.mjs.map +1 -1
- package/_mjs/optics/Setter/api/focus.mjs +12 -0
- package/_mjs/optics/Setter/api/focus.mjs.map +1 -0
- package/_mjs/optics/Setter/definition.mjs.map +1 -1
- package/_mjs/optics/Traversal/api/focus.mjs +15 -0
- package/_mjs/optics/Traversal/api/focus.mjs.map +1 -0
- package/_mjs/optics/Traversal/definition.mjs.map +1 -1
- package/_mjs/optics/Traversal.mjs +1 -0
- package/_mjs/optics/Traversal.mjs.map +1 -1
- package/_mjs/typeclass/MonadExcept.mjs +4 -1
- package/_mjs/typeclass/MonadExcept.mjs.map +1 -1
- package/_src/collection/compat/Array/api.ts +51 -0
- package/_src/collection/immutable/Conc/api.ts +4 -4
- package/_src/collection/immutable/Dictionary/api.ts +40 -0
- package/_src/collection/immutable/HashMap/api.ts +4 -4
- package/_src/collection/immutable/HashSet/api.ts +4 -4
- package/_src/collection/immutable/ImmutableArray/api.ts +4 -4
- package/_src/collection/internal.ts +0 -0
- package/_src/collection/mutable/ArrayDeque.ts +231 -0
- package/_src/collection/mutable/Queue.ts +14 -0
- package/_src/collection/mutable.ts +2 -0
- package/_src/control/InterruptiblePromise.ts +23 -0
- package/_src/control/Pure/api.ts +7 -4
- package/_src/data/Cause/api.ts +8 -8
- package/_src/data/Date/definition.ts +6 -0
- package/_src/data/Date.ts +3 -0
- package/_src/data/Datum/api.ts +8 -8
- package/_src/data/DatumEither/api.ts +8 -8
- package/_src/data/Either/api.ts +18 -18
- package/_src/data/Either/destructors.ts +3 -3
- package/_src/data/Either/instances.ts +12 -12
- package/_src/data/EitherT/api.ts +8 -8
- package/_src/data/Exit/constructors.ts +1 -1
- package/_src/data/Global.ts +17 -0
- package/_src/data/Maybe/api.ts +4 -4
- package/_src/data.ts +2 -0
- package/_src/optics/Fold/api/focus.ts +12 -0
- package/_src/optics/Fold/definition.ts +9 -0
- package/_src/optics/Getter/definition.ts +9 -1
- package/_src/optics/Index/api.ts +15 -1
- package/_src/optics/Iso/api.ts +16 -0
- package/_src/optics/Iso/definition.ts +6 -1
- package/_src/optics/Lens/api.ts +36 -8
- package/_src/optics/Lens/definition.ts +4 -1
- package/_src/optics/Optional/api/focus.ts +16 -0
- package/_src/optics/Optional/api.ts +10 -0
- package/_src/optics/Optional/definition.ts +23 -4
- package/_src/optics/Optional.ts +2 -0
- package/_src/optics/Prism/api/focus.ts +14 -0
- package/_src/optics/Prism/definition.ts +6 -2
- package/_src/optics/Prism.ts +1 -0
- package/_src/optics/Setter/api/focus.ts +13 -0
- package/_src/optics/Setter/definition.ts +13 -0
- package/_src/optics/Traversal/api/focus.ts +16 -0
- package/_src/optics/Traversal/definition.ts +10 -0
- package/_src/optics/Traversal.ts +1 -0
- package/_src/typeclass/MonadExcept.ts +1 -1
- package/collection/compat/Array/api.d.ts +19 -0
- package/collection/immutable/Dictionary/api.d.ts +21 -0
- package/collection/internal.d.ts +1 -0
- package/collection/mutable/ArrayDeque.d.ts +41 -0
- package/collection/mutable/Queue.d.ts +9 -0
- package/collection/mutable.d.ts +2 -0
- package/control/InterruptiblePromise.d.ts +12 -0
- package/data/Date/definition.d.ts +9 -0
- package/data/Date.d.ts +1 -0
- package/data/Either/destructors.d.ts +4 -1
- package/data/Global.d.ts +4 -0
- package/data.d.ts +2 -0
- package/optics/Fold/api/focus.d.ts +6 -0
- package/optics/Fold/definition.d.ts +6 -0
- package/optics/Getter/definition.d.ts +7 -1
- package/optics/Index/api.d.ts +5 -0
- package/optics/Iso/api.d.ts +6 -0
- package/optics/Iso/definition.d.ts +4 -1
- package/optics/Lens/api.d.ts +11 -0
- package/optics/Lens/definition.d.ts +4 -1
- package/optics/Optional/api/focus.d.ts +6 -0
- package/optics/Optional/api.d.ts +6 -0
- package/optics/Optional/definition.d.ts +15 -0
- package/optics/Optional.d.ts +2 -0
- package/optics/Prism/api/focus.d.ts +6 -0
- package/optics/Prism/definition.d.ts +4 -1
- package/optics/Prism.d.ts +1 -0
- package/optics/Setter/api/focus.d.ts +6 -0
- package/optics/Setter/definition.d.ts +10 -0
- package/optics/Traversal/api/focus.d.ts +6 -0
- package/optics/Traversal/definition.d.ts +5 -0
- package/optics/Traversal.d.ts +1 -0
- package/package.json +1 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Traversal.mjs","names":[],"sources":["../../_src/optics/Traversal.ts"],"sourcesContent":[null],"mappings":"AAAA;AACA,cAAc,4BAA2B;AACzC;AACA;AACA,cAAc,6BAA4B;AAC1C,cAAc,qCAAoC"}
|
1
|
+
{"version":3,"file":"Traversal.mjs","names":[],"sources":["../../_src/optics/Traversal.ts"],"sourcesContent":[null],"mappings":"AAAA;AACA,cAAc,4BAA2B;AACzC;AACA;AACA,cAAc,6BAA4B;AAC1C,cAAc,2BAA0B;AACxC,cAAc,qCAAoC"}
|
@@ -1,6 +1,9 @@
|
|
1
1
|
import * as tsplus_module_1 from "@fncts/base/data/Either/destructors";
|
2
2
|
export const MonadExcept = {};
|
3
3
|
export function absolve(F) {
|
4
|
-
return F.flatMap(r => tsplus_module_1.match(
|
4
|
+
return F.flatMap(r => tsplus_module_1.match({
|
5
|
+
Left: F.fail,
|
6
|
+
Right: F.pure
|
7
|
+
})(r));
|
5
8
|
}
|
6
9
|
//# sourceMappingURL=MonadExcept.mjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"MonadExcept.mjs","names":["MonadExcept","absolve","F","flatMap","r","tsplus_module_1","match","fail","pure"],"sources":["../../_src/typeclass/MonadExcept.ts"],"sourcesContent":[null],"mappings":";AAaA,OAAO,MAAMA,WAAW,GAAmB,EAAE;AAU7C,OAAM,SAAUC,OAAOA,CACrBC,CAAwB;EAExB,OAAOA,CAAC,CAACC,OAAO,CAAEC,CAAC,IAAKC,eAAA,CAAAC,KAAA,
|
1
|
+
{"version":3,"file":"MonadExcept.mjs","names":["MonadExcept","absolve","F","flatMap","r","tsplus_module_1","match","Left","fail","Right","pure"],"sources":["../../_src/typeclass/MonadExcept.ts"],"sourcesContent":[null],"mappings":";AAaA,OAAO,MAAMA,WAAW,GAAmB,EAAE;AAU7C,OAAM,SAAUC,OAAOA,CACrBC,CAAwB;EAExB,OAAOA,CAAC,CAACC,OAAO,CAAEC,CAAC,IAAKC,eAAA,CAAAC,KAAA,CAAQ;IAAEC,IAAI,EAAEL,CAAC,CAACM,IAAI;IAAEC,KAAK,EAAEP,CAAC,CAACQ;EAAI,CAAE,EAAvCN,CAAC,CAAuC,CAAC;AACnE"}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import type { Eq } from "@fncts/base/typeclass";
|
2
|
+
|
2
3
|
/**
|
3
4
|
* @tsplus getter fncts.Array elem
|
4
5
|
* @tsplus getter fncts.ReadonlyArray elem
|
@@ -15,6 +16,41 @@ export function elem<A>(self: ReadonlyArray<A>) {
|
|
15
16
|
};
|
16
17
|
}
|
17
18
|
|
19
|
+
/**
|
20
|
+
* @tsplus pipeable fncts.Array filterMap
|
21
|
+
* @tsplus pipeable fncts.ReadonlyArray filterMap
|
22
|
+
*/
|
23
|
+
export function filterMap<A, B>(f: (a: A) => Maybe<B>) {
|
24
|
+
return (self: ReadonlyArray<A>): ReadonlyArray<B> => {
|
25
|
+
const out: Array<B> = [];
|
26
|
+
for (let i = 0; i < self.length; i++) {
|
27
|
+
const v = f(self[i]!);
|
28
|
+
Maybe.concrete(v);
|
29
|
+
if (v._tag === MaybeTag.Just) {
|
30
|
+
out.push(v.value);
|
31
|
+
}
|
32
|
+
}
|
33
|
+
return out;
|
34
|
+
};
|
35
|
+
}
|
36
|
+
|
37
|
+
/**
|
38
|
+
* @tsplus pipeable fncts.Array filterMap
|
39
|
+
* @tsplus pipeable fncts.ReadonlyArray filterMap
|
40
|
+
*/
|
41
|
+
export function filterMapUndefined<A, B>(f: (a: A) => B | undefined) {
|
42
|
+
return (self: ReadonlyArray<A>): ReadonlyArray<B> => {
|
43
|
+
const out: Array<B> = [];
|
44
|
+
for (let i = 0; i < self.length; i++) {
|
45
|
+
const v = f(self[i]!);
|
46
|
+
if (v !== undefined) {
|
47
|
+
out.push(v);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
return out;
|
51
|
+
};
|
52
|
+
}
|
53
|
+
|
18
54
|
/**
|
19
55
|
* @tsplus fluent fncts.Array isEmpty
|
20
56
|
* @tsplus fluent fncts.ReadonlyArray isEmpty
|
@@ -54,3 +90,18 @@ export function foldLeftWithIndex<A, B>(b: B, f: (i: number, b: B, a: A) => B) {
|
|
54
90
|
return out;
|
55
91
|
};
|
56
92
|
}
|
93
|
+
|
94
|
+
/**
|
95
|
+
* @tsplus pipeable fncts.Array updateAt
|
96
|
+
* @tsplus pipeable fncts.ReadonlyArray updateAt
|
97
|
+
*/
|
98
|
+
export function updateAt<A>(i: number, a: A) {
|
99
|
+
return (self: ReadonlyArray<A>): ReadonlyArray<A> => {
|
100
|
+
if (i in self) {
|
101
|
+
const copy = self.slice();
|
102
|
+
copy[i] = a;
|
103
|
+
return copy;
|
104
|
+
}
|
105
|
+
return self;
|
106
|
+
};
|
107
|
+
}
|
@@ -864,10 +864,10 @@ export function partitionMapWithIndex<A, B, C>(f: (i: number, a: A) => Either<B,
|
|
864
864
|
const array = result.value;
|
865
865
|
for (let j = 0; j < array.length; j++) {
|
866
866
|
const eab = f(i, array[j]!);
|
867
|
-
eab.match(
|
868
|
-
(b) => left.append(b),
|
869
|
-
(c) => right.append(c),
|
870
|
-
);
|
867
|
+
eab.match({
|
868
|
+
Left: (b) => left.append(b),
|
869
|
+
Right: (c) => right.append(c),
|
870
|
+
});
|
871
871
|
i++;
|
872
872
|
}
|
873
873
|
}
|
@@ -32,6 +32,38 @@ export function get(key: string) {
|
|
32
32
|
};
|
33
33
|
}
|
34
34
|
|
35
|
+
/**
|
36
|
+
* @tsplus pipeable fncts.Dictionary set
|
37
|
+
*/
|
38
|
+
export function set<A>(key: string, value: A) {
|
39
|
+
return (self: Dictionary<A>): Dictionary<A> => {
|
40
|
+
return Dictionary({ ...self.toRecord, [key]: value });
|
41
|
+
};
|
42
|
+
}
|
43
|
+
|
44
|
+
/**
|
45
|
+
* @tsplus pipeable fncts.Dictionary remove
|
46
|
+
*/
|
47
|
+
export function remove(key: string) {
|
48
|
+
return <A>(self: Dictionary<A>): Dictionary<A> => {
|
49
|
+
const out = { ...self.toRecord };
|
50
|
+
delete out[key];
|
51
|
+
return Dictionary(out);
|
52
|
+
};
|
53
|
+
}
|
54
|
+
|
55
|
+
/**
|
56
|
+
* @tsplus pipeable fncts.Dictionary update
|
57
|
+
*/
|
58
|
+
export function update<A>(key: string, f: (a: Maybe<A>) => Maybe<A>) {
|
59
|
+
return (self: Dictionary<A>): Dictionary<A> => {
|
60
|
+
return f(self.get(key)).match(
|
61
|
+
() => self.remove(key),
|
62
|
+
(a) => self.set(key, a),
|
63
|
+
);
|
64
|
+
};
|
65
|
+
}
|
66
|
+
|
35
67
|
/**
|
36
68
|
* @tsplus getter fncts.Dictionary keys
|
37
69
|
*/
|
@@ -64,6 +96,14 @@ export function mapWithIndex<A, B>(f: (k: string, a: A) => B) {
|
|
64
96
|
};
|
65
97
|
}
|
66
98
|
|
99
|
+
/**
|
100
|
+
* @tsplus static fncts.DictionaryOps __call
|
101
|
+
* @tsplus macro identity
|
102
|
+
*/
|
103
|
+
export function fromRecord<A>(self: Record<string, A>): Dictionary<A> {
|
104
|
+
return Dictionary.get(self);
|
105
|
+
}
|
106
|
+
|
67
107
|
/**
|
68
108
|
* @tsplus getter fncts.Dictionary toRecord
|
69
109
|
* @tsplus macro identity
|
@@ -476,14 +476,14 @@ export function partitionMapWithIndex<K, V, A, B>(f: (i: K, a: V) => Either<A, B
|
|
476
476
|
const left = makeWith<K, A>(self.config).beginMutation;
|
477
477
|
const right = makeWith<K, B>(self.config).beginMutation;
|
478
478
|
self.forEachWithIndex((k, v) => {
|
479
|
-
f(k, v).match(
|
480
|
-
(a) => {
|
479
|
+
f(k, v).match({
|
480
|
+
Left: (a) => {
|
481
481
|
left.set(k, a);
|
482
482
|
},
|
483
|
-
(b) => {
|
483
|
+
Right: (b) => {
|
484
484
|
right.set(k, b);
|
485
485
|
},
|
486
|
-
);
|
486
|
+
});
|
487
487
|
});
|
488
488
|
return [left.endMutation, right.endMutation];
|
489
489
|
};
|
@@ -300,14 +300,14 @@ export function partitionMapWith<B, C>(
|
|
300
300
|
const right = beginMutation(emptyWith(C));
|
301
301
|
const left = beginMutation(emptyWith(B));
|
302
302
|
fa.forEach((v) => {
|
303
|
-
f(v).match(
|
304
|
-
(b) => {
|
303
|
+
f(v).match({
|
304
|
+
Left: (b) => {
|
305
305
|
left.add(b);
|
306
306
|
},
|
307
|
-
(c) => {
|
307
|
+
Right: (c) => {
|
308
308
|
right.add(c);
|
309
309
|
},
|
310
|
-
);
|
310
|
+
});
|
311
311
|
});
|
312
312
|
return [endMutation(left), endMutation(right)];
|
313
313
|
};
|
@@ -1430,16 +1430,16 @@ export function _wiltWithIndex<A>(self: ImmutableArray<A>) {
|
|
1430
1430
|
.foldLeftWithIndex(G.pure([[] as Array<B>, [] as Array<B2>] as const), (i, fbs, a) =>
|
1431
1431
|
f(i, a).pipe(
|
1432
1432
|
G.zipWith(fbs, (eb, r) =>
|
1433
|
-
eb.match(
|
1434
|
-
(b1) => {
|
1433
|
+
eb.match({
|
1434
|
+
Left: (b1) => {
|
1435
1435
|
r[0].push(b1);
|
1436
1436
|
return r;
|
1437
1437
|
},
|
1438
|
-
(b2) => {
|
1438
|
+
Right: (b2) => {
|
1439
1439
|
r[1].push(b2);
|
1440
1440
|
return r;
|
1441
1441
|
},
|
1442
|
-
),
|
1442
|
+
}),
|
1443
1443
|
),
|
1444
1444
|
),
|
1445
1445
|
)
|
File without changes
|
@@ -0,0 +1,231 @@
|
|
1
|
+
const STABLE_SIZE = 128;
|
2
|
+
const DEFAULT_INITIAL_SIZE = 16;
|
3
|
+
|
4
|
+
/**
|
5
|
+
* @tsplus type fncts.MutableArrayDeque
|
6
|
+
* @tsplus companion fncts.MutableArrayDeque
|
7
|
+
*/
|
8
|
+
export class ArrayDeque<A> {
|
9
|
+
constructor(protected array: Array<A>, private start: number, private end: number) {}
|
10
|
+
|
11
|
+
static empty<A>(initialSize = DEFAULT_INITIAL_SIZE): ArrayDeque<A> {
|
12
|
+
return new ArrayDeque(new Array(initialSize), 0, 0);
|
13
|
+
}
|
14
|
+
|
15
|
+
protected requireBounds(idx: number, until: number = this.length) {
|
16
|
+
if (idx < 0 || idx > until) throw new IndexOutOfBoundsError(`${idx} is out of bounds (min 0, max ${until - 1})`);
|
17
|
+
}
|
18
|
+
|
19
|
+
get(idx: number): A {
|
20
|
+
this.requireBounds(idx);
|
21
|
+
return this._get(idx);
|
22
|
+
}
|
23
|
+
|
24
|
+
update(idx: number, elem: A): void {
|
25
|
+
this.requireBounds(idx);
|
26
|
+
this._set(idx, elem);
|
27
|
+
}
|
28
|
+
|
29
|
+
addOne(elem: A): this {
|
30
|
+
this.ensureSize(this.length + 1);
|
31
|
+
return this.appendAssumingCapacity(elem);
|
32
|
+
}
|
33
|
+
|
34
|
+
prepend(elem: A): this {
|
35
|
+
this.ensureSize(this.length + 1);
|
36
|
+
return this.prependAssumingCapacity(elem);
|
37
|
+
}
|
38
|
+
|
39
|
+
insert(idx: number, elem: A): void {
|
40
|
+
this.requireBounds(idx, this.length + 1);
|
41
|
+
const n = this.length;
|
42
|
+
if (idx === 0) {
|
43
|
+
this.prepend(elem);
|
44
|
+
} else if (idx === n) {
|
45
|
+
this.addOne(elem);
|
46
|
+
} else {
|
47
|
+
const finalLength = n + 1;
|
48
|
+
if (this.mustGrow(finalLength)) {
|
49
|
+
const array2 = new Array(finalLength);
|
50
|
+
this.copySliceToArray(0, array2, 0, idx);
|
51
|
+
array2[idx] = elem;
|
52
|
+
this.copySliceToArray(idx, array2, idx + 1, n);
|
53
|
+
this.reset(array2, 0, finalLength);
|
54
|
+
} else if (n <= idx * 2) {
|
55
|
+
let i = n - 1;
|
56
|
+
for (; i >= idx; i--) {
|
57
|
+
this._set(i + 1, this._get(i));
|
58
|
+
}
|
59
|
+
this.end = this.end_plus(1);
|
60
|
+
i += 1;
|
61
|
+
this._set(i, elem);
|
62
|
+
} else {
|
63
|
+
let i = 0;
|
64
|
+
for (; i < idx; i++) {
|
65
|
+
this._set(i - 1, this._get(1));
|
66
|
+
}
|
67
|
+
this.start = this.start_minus(1);
|
68
|
+
this._set(i, elem);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
remove(idx: number, count: number): void {
|
74
|
+
if (count > 0) {
|
75
|
+
this.requireBounds(idx);
|
76
|
+
const n = this.length;
|
77
|
+
const removals = Math.min(n - idx, count);
|
78
|
+
const finalLength = n - removals;
|
79
|
+
const suffixStart = idx + removals;
|
80
|
+
if (this.shouldShrink(finalLength)) {
|
81
|
+
const array2 = new Array(finalLength);
|
82
|
+
this.copySliceToArray(0, array2, 0, idx);
|
83
|
+
this.copySliceToArray(suffixStart, array2, idx, n);
|
84
|
+
this.reset(array2, 0, finalLength);
|
85
|
+
} else if (2 * idx <= finalLength) {
|
86
|
+
let i = suffixStart - 1;
|
87
|
+
for (; i >= removals; i--) {
|
88
|
+
this._set(i, this._get(i - removals));
|
89
|
+
}
|
90
|
+
for (; i >= 0; i--) {
|
91
|
+
this._set(i, null!);
|
92
|
+
}
|
93
|
+
this.start = this.start_plus(removals);
|
94
|
+
} else {
|
95
|
+
let i = idx;
|
96
|
+
for (; i < finalLength; i++) {
|
97
|
+
this._set(i, this._get(i + removals));
|
98
|
+
}
|
99
|
+
for (; i < n; i++) {
|
100
|
+
this._set(i, null!);
|
101
|
+
}
|
102
|
+
this.end = this.end_minus(removals);
|
103
|
+
}
|
104
|
+
} else if (count < 0) {
|
105
|
+
throw new Error(`Removing negative number of elements ${count}`);
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
removeHead(resizeInternalRepr = false): A {
|
110
|
+
if (this.isEmpty) throw new NoSuchElementError("empty collection");
|
111
|
+
else return this.removeHeadAssumingNonEmpty(resizeInternalRepr);
|
112
|
+
}
|
113
|
+
|
114
|
+
removeHeadOption(resizeInternalRepr = false): Maybe<A> {
|
115
|
+
if (this.isEmpty) return Nothing();
|
116
|
+
else return Just(this.removeHeadAssumingNonEmpty(resizeInternalRepr));
|
117
|
+
}
|
118
|
+
|
119
|
+
removeLastOption(resizeInternalRepr = false): Maybe<A> {
|
120
|
+
if (this.isEmpty) return Nothing();
|
121
|
+
else return Just(this.removeLastAssumingNonEmpty(resizeInternalRepr));
|
122
|
+
}
|
123
|
+
|
124
|
+
get isEmpty(): boolean {
|
125
|
+
return this.length === 0;
|
126
|
+
}
|
127
|
+
|
128
|
+
private removeHeadAssumingNonEmpty(resizeInternalRepr = false): A {
|
129
|
+
const elem = this.array[this.start];
|
130
|
+
this.array[this.start] = null!;
|
131
|
+
this.start = this.start_plus(1);
|
132
|
+
if (resizeInternalRepr) this.resize(this.length);
|
133
|
+
return elem!;
|
134
|
+
}
|
135
|
+
|
136
|
+
private removeLastAssumingNonEmpty(resizeInternalRepr = false): A {
|
137
|
+
this.end = this.end_minus(1);
|
138
|
+
const elem = this.array[this.end];
|
139
|
+
this.array[this.end] = null!;
|
140
|
+
if (resizeInternalRepr) this.resize(this.length);
|
141
|
+
return elem!;
|
142
|
+
}
|
143
|
+
|
144
|
+
protected prependAssumingCapacity(elem: A): this {
|
145
|
+
this.start = this.start_minus(1);
|
146
|
+
this.array[this.start] = elem;
|
147
|
+
return this;
|
148
|
+
}
|
149
|
+
|
150
|
+
protected appendAssumingCapacity(elem: A): this {
|
151
|
+
this.array[this.end] = elem;
|
152
|
+
this.end = this.end_plus(1);
|
153
|
+
return this;
|
154
|
+
}
|
155
|
+
|
156
|
+
private ensureSize(hint: number) {
|
157
|
+
if (hint > this.length && this.mustGrow(hint)) {
|
158
|
+
this.resize(hint);
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
162
|
+
private resize(len: number) {
|
163
|
+
const n = this.length;
|
164
|
+
const array2 = this.copySliceToArray(0, new Array(len), 0, n);
|
165
|
+
this.reset(array2, 0, n);
|
166
|
+
}
|
167
|
+
|
168
|
+
private reset(array: Array<A>, start: number, end: number) {
|
169
|
+
this.requireBounds(start, array.length);
|
170
|
+
this.requireBounds(end, array.length);
|
171
|
+
this.array = array;
|
172
|
+
this.start = start;
|
173
|
+
this.end = end;
|
174
|
+
}
|
175
|
+
|
176
|
+
private mustGrow(len: number) {
|
177
|
+
return len >= this.array.length;
|
178
|
+
}
|
179
|
+
|
180
|
+
protected start_plus(idx: number) {
|
181
|
+
return (this.start + idx) & (this.array.length - 1);
|
182
|
+
}
|
183
|
+
|
184
|
+
private start_minus(idx: number) {
|
185
|
+
return (this.start - idx) & (this.array.length - 1);
|
186
|
+
}
|
187
|
+
|
188
|
+
private end_plus(idx: number) {
|
189
|
+
return (this.end + idx) & (this.array.length - 1);
|
190
|
+
}
|
191
|
+
|
192
|
+
private end_minus(idx: number) {
|
193
|
+
return (this.end - idx) & (this.array.length - 1);
|
194
|
+
}
|
195
|
+
|
196
|
+
private _get(idx: number): A {
|
197
|
+
return this.array[this.start_plus(idx)]!;
|
198
|
+
}
|
199
|
+
|
200
|
+
private _set(idx: number, a: A): void {
|
201
|
+
this.array[this.start_plus(idx)] = a;
|
202
|
+
}
|
203
|
+
|
204
|
+
get length() {
|
205
|
+
return this.end_minus(this.start);
|
206
|
+
}
|
207
|
+
|
208
|
+
copySliceToArray(srcStart: number, dest: Array<A>, destStart: number, maxItems: number): Array<A> {
|
209
|
+
this.requireBounds(destStart, dest.length + 1);
|
210
|
+
const toCopy = Math.min(maxItems, Math.min(this.length - srcStart, dest.length - destStart));
|
211
|
+
if (toCopy > 0) {
|
212
|
+
this.requireBounds(srcStart);
|
213
|
+
const startIdx = this.start_plus(srcStart);
|
214
|
+
const block1 = Math.min(toCopy, this.array.length - startIdx);
|
215
|
+
copyArray(this.array, startIdx, dest, destStart, block1);
|
216
|
+
const block2 = toCopy - block1;
|
217
|
+
if (block2 > 0) copyArray(this.array, 0, dest, destStart + block1, block2);
|
218
|
+
}
|
219
|
+
return dest;
|
220
|
+
}
|
221
|
+
|
222
|
+
private shouldShrink(len: number) {
|
223
|
+
return this.array.length > STABLE_SIZE && this.array.length - len - (len >> 1) > len;
|
224
|
+
}
|
225
|
+
}
|
226
|
+
|
227
|
+
function copyArray<A>(src: Array<A>, srcPos: number, dest: Array<A>, destPos: number, length: number): void {
|
228
|
+
for (let i = srcPos, j = 0; j < length; i++, j++) {
|
229
|
+
dest[destPos + j] = src[i]!;
|
230
|
+
}
|
231
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { ArrayDeque } from "@fncts/base/collection/mutable/ArrayDeque";
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @tsplus type fncts.MutableQueue
|
5
|
+
* @tsplus companion fncts.MutableQueue
|
6
|
+
*/
|
7
|
+
export class Queue<A> extends ArrayDeque<A> {
|
8
|
+
enqueue(elem: A): this {
|
9
|
+
return this.addOne(elem);
|
10
|
+
}
|
11
|
+
dequeue(): A {
|
12
|
+
return this.removeHead();
|
13
|
+
}
|
14
|
+
}
|
@@ -1,6 +1,8 @@
|
|
1
1
|
// codegen:start { preset: type-barrel, include: ./mutable/*.ts }
|
2
|
+
export type {} from "./mutable/ArrayDeque.js";
|
2
3
|
export type {} from "./mutable/HashMap.js";
|
3
4
|
export type {} from "./mutable/HashSet.js";
|
4
5
|
export type {} from "./mutable/internal.js";
|
5
6
|
export type {} from "./mutable/ListBuffer.js";
|
7
|
+
export type {} from "./mutable/Queue.js";
|
6
8
|
// codegen:end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
/**
|
2
|
+
* @tsplus type fncts.InterruptiblePromise
|
3
|
+
* @tsplus companion fncts.InterruptiblePromiseOps
|
4
|
+
*/
|
5
|
+
export interface InterruptiblePromise<A> extends Promise<A> {
|
6
|
+
interrupt: () => void;
|
7
|
+
}
|
8
|
+
|
9
|
+
/**
|
10
|
+
* @tsplus static fncts.InterruptiblePromiseOps __call
|
11
|
+
*/
|
12
|
+
export function make<A>(
|
13
|
+
executor: (resolve: (value: A | PromiseLike<A>) => void, reject: (reason?: unknown) => void) => (() => void) | void,
|
14
|
+
): InterruptiblePromise<A> {
|
15
|
+
const promise: InterruptiblePromise<A> = new Promise((resolve, reject) => {
|
16
|
+
const canceller = executor(resolve, reject);
|
17
|
+
promise.interrupt = () => {
|
18
|
+
canceller?.();
|
19
|
+
reject(new InterruptedException());
|
20
|
+
};
|
21
|
+
}) as InterruptiblePromise<A>;
|
22
|
+
return promise;
|
23
|
+
}
|
package/_src/control/Pure/api.ts
CHANGED
@@ -8,7 +8,7 @@ import { identity, tuple } from "../../data/function.js";
|
|
8
8
|
export function absolve<W, S1, S2, R, E, E1, A>(
|
9
9
|
fa: Pure<W, S1, S2, R, E, Either<E1, A>>,
|
10
10
|
): Pure<W, S1, S2, R, E | E1, A> {
|
11
|
-
return fa.flatMap((ea) => ea.match(Pure.failNow, Pure.succeedNow));
|
11
|
+
return fa.flatMap((ea) => ea.match({ Left: Pure.failNow, Right: Pure.succeedNow }));
|
12
12
|
}
|
13
13
|
|
14
14
|
/**
|
@@ -350,7 +350,10 @@ export function matchPure<S5, S2, E, A, W1, S3, R1, E1, B, W2, S4, R2, E2, C>(
|
|
350
350
|
onSuccess: (a: A) => Pure<W2, S2, S4, R2, E2, C>,
|
351
351
|
) {
|
352
352
|
return <W, S1, R>(fa: Pure<W, S1, S2, R, E, A>): Pure<W | W1 | W2, S1 & S5, S3 | S4, R | R1 | R2, E1 | E2, B | C> => {
|
353
|
-
return fa.matchCausePure(
|
353
|
+
return fa.matchCausePure(
|
354
|
+
(cause) => cause.failureOrCause.match({ Left: onFailure, Right: Pure.failCauseNow }),
|
355
|
+
onSuccess,
|
356
|
+
);
|
354
357
|
};
|
355
358
|
}
|
356
359
|
|
@@ -378,7 +381,7 @@ export function matchLogPure<W, S5, S2, E, A, W1, S3, R1, E1, B, W2, S4, R2, E2,
|
|
378
381
|
) {
|
379
382
|
return <S1, R>(fa: Pure<W, S1, S2, R, E, A>): Pure<W | W1 | W2, S1 & S5, S3 | S4, R | R1 | R2, E1 | E2, B | C> => {
|
380
383
|
return fa.matchLogCausePure(
|
381
|
-
(ws, cause) => cause.failureOrCause.match((e) => onFailure(ws, e), Pure.failCauseNow),
|
384
|
+
(ws, cause) => cause.failureOrCause.match({ Left: (e) => onFailure(ws, e), Right: Pure.failCauseNow }),
|
382
385
|
onSuccess,
|
383
386
|
);
|
384
387
|
};
|
@@ -428,7 +431,7 @@ export function modifyEither<S1, S2, E, A>(
|
|
428
431
|
): Pure<never, S1, S2, never, E, A> {
|
429
432
|
return Pure.get<S1>()
|
430
433
|
.map(f)
|
431
|
-
.flatMap((r) => r.match(Pure.failNow, ([a, s2]) => Pure.succeedNow(a).mapState(() => s2)));
|
434
|
+
.flatMap((r) => r.match({ Left: Pure.failNow, Right: ([a, s2]) => Pure.succeedNow(a).mapState(() => s2) }));
|
432
435
|
}
|
433
436
|
|
434
437
|
/**
|
package/_src/data/Cause/api.ts
CHANGED
@@ -333,10 +333,10 @@ export function flipCauseEither<E, A>(self: Cause<Either<E, A>>): Either<Cause<E
|
|
333
333
|
result = Either.left(c);
|
334
334
|
break pushing;
|
335
335
|
case CauseTag.Fail:
|
336
|
-
result = c.value.match(
|
337
|
-
(l) => Either.left(Cause.fail(l, Trace.none)),
|
338
|
-
(r) => Either.right(r),
|
339
|
-
);
|
336
|
+
result = c.value.match({
|
337
|
+
Left: (l) => Either.left(Cause.fail(l, Trace.none)),
|
338
|
+
Right: (r) => Either.right(r),
|
339
|
+
});
|
340
340
|
break pushing;
|
341
341
|
case CauseTag.Sequential:
|
342
342
|
stack.push(new FCEStackFrameThenLeft(c));
|
@@ -886,10 +886,10 @@ function sequenceCauseEitherEval<E, A>(self: Cause<Either<E, A>>): Eval<Either<C
|
|
886
886
|
}
|
887
887
|
case CauseTag.Fail: {
|
888
888
|
return Eval.now(
|
889
|
-
self.value.match(
|
890
|
-
(e) => Either.left(Cause.fail(e, Trace.none)),
|
891
|
-
(a) => Either.right(a),
|
892
|
-
),
|
889
|
+
self.value.match({
|
890
|
+
Left: (e) => Either.left(Cause.fail(e, Trace.none)),
|
891
|
+
Right: (a) => Either.right(a),
|
892
|
+
}),
|
893
893
|
);
|
894
894
|
}
|
895
895
|
case CauseTag.Halt: {
|
package/_src/data/Datum/api.ts
CHANGED
@@ -336,15 +336,15 @@ export function partitionMap<A, B, C>(f: (a: A) => Either<B, C>) {
|
|
336
336
|
Initial: () => [Initial(), Initial()],
|
337
337
|
Pending: () => [Pending(), Pending()],
|
338
338
|
Refresh: (a) =>
|
339
|
-
f(a).match(
|
340
|
-
(b) => [Refresh(b), Initial()],
|
341
|
-
(c) => [Initial(), Refresh(c)],
|
342
|
-
),
|
339
|
+
f(a).match({
|
340
|
+
Left: (b) => [Refresh(b), Initial()],
|
341
|
+
Right: (c) => [Initial(), Refresh(c)],
|
342
|
+
}),
|
343
343
|
Replete: (a) =>
|
344
|
-
f(a).match(
|
345
|
-
(b) => [Replete(b), Initial()],
|
346
|
-
(c) => [Initial(), Replete(c)],
|
347
|
-
),
|
344
|
+
f(a).match({
|
345
|
+
Left: (b) => [Replete(b), Initial()],
|
346
|
+
Right: (c) => [Initial(), Replete(c)],
|
347
|
+
}),
|
348
348
|
});
|
349
349
|
};
|
350
350
|
}
|
@@ -303,16 +303,16 @@ export function partitionMap<A, B, C>(f: (a: A) => Either<B, C>) {
|
|
303
303
|
Pending: () => [self.unsafeCoerce(), self.unsafeCoerce()],
|
304
304
|
RefreshLeft: () => [self.unsafeCoerce(), self.unsafeCoerce()],
|
305
305
|
RefreshRight: (a) =>
|
306
|
-
f(a).match(
|
307
|
-
(b) => [DatumEither.refreshRight(b), DatumEither.initial()],
|
308
|
-
(c) => [DatumEither.initial(), DatumEither.refreshRight(c)],
|
309
|
-
),
|
306
|
+
f(a).match({
|
307
|
+
Left: (b) => [DatumEither.refreshRight(b), DatumEither.initial()],
|
308
|
+
Right: (c) => [DatumEither.initial(), DatumEither.refreshRight(c)],
|
309
|
+
}),
|
310
310
|
RepleteLeft: () => [self.unsafeCoerce(), self.unsafeCoerce()],
|
311
311
|
RepleteRight: (a) =>
|
312
|
-
f(a).match(
|
313
|
-
(b) => [DatumEither.repleteRight(b), DatumEither.initial()],
|
314
|
-
(c) => [DatumEither.initial(), DatumEither.repleteRight(c)],
|
315
|
-
),
|
312
|
+
f(a).match({
|
313
|
+
Left: (b) => [DatumEither.repleteRight(b), DatumEither.initial()],
|
314
|
+
Right: (c) => [DatumEither.initial(), DatumEither.repleteRight(c)],
|
315
|
+
}),
|
316
316
|
});
|
317
317
|
};
|
318
318
|
}
|