@fncts/base 0.0.30 → 0.0.32
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/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
package/_src/data/Either/api.ts
CHANGED
|
@@ -97,20 +97,20 @@ export function foldMap<A, M>(f: (a: A) => M, /** @tsplus auto */ M: P.Monoid<M>
|
|
|
97
97
|
* @tsplus getter fncts.Either getLeft
|
|
98
98
|
*/
|
|
99
99
|
export function getLeft<E, A>(self: Either<E, A>): Maybe<E> {
|
|
100
|
-
return self.match(
|
|
101
|
-
(e) => Just(e),
|
|
102
|
-
(_a) => Nothing(),
|
|
103
|
-
);
|
|
100
|
+
return self.match({
|
|
101
|
+
Left: (e) => Just(e),
|
|
102
|
+
Right: (_a) => Nothing(),
|
|
103
|
+
});
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
/**
|
|
107
107
|
* @tsplus getter fncts.Either getRight
|
|
108
108
|
*/
|
|
109
109
|
export function getRight<E, A>(self: Either<E, A>): Maybe<A> {
|
|
110
|
-
return self.match(
|
|
111
|
-
(_e) => Nothing(),
|
|
112
|
-
(a) => Just(a),
|
|
113
|
-
);
|
|
110
|
+
return self.match({
|
|
111
|
+
Left: (_e) => Nothing(),
|
|
112
|
+
Right: (a) => Just(a),
|
|
113
|
+
});
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
/**
|
|
@@ -118,7 +118,7 @@ export function getRight<E, A>(self: Either<E, A>): Maybe<A> {
|
|
|
118
118
|
*/
|
|
119
119
|
export function getOrElse<E, B>(orElse: (e: E) => B) {
|
|
120
120
|
return <A>(self: Either<E, A>): A | B => {
|
|
121
|
-
return self.match(orElse, identity);
|
|
121
|
+
return self.match({ Left: orElse, Right: identity });
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
|
|
@@ -172,7 +172,7 @@ export function mapLeft<E1, E2>(f: (e: E1) => E2) {
|
|
|
172
172
|
* @tsplus getter fncts.Either value
|
|
173
173
|
*/
|
|
174
174
|
export function merge<E, A>(self: Either<E, A>): E | A {
|
|
175
|
-
return self.match(identity, identity);
|
|
175
|
+
return self.match({ Left: identity, Right: identity });
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
/**
|
|
@@ -201,10 +201,10 @@ export function _traverse<E, A>(self: Either<E, A>) {
|
|
|
201
201
|
<K, Q, W, X, I, S, R, E1, B>(
|
|
202
202
|
f: (a: A) => HKT.Kind<G, GC, K, Q, W, X, I, S, R, E1, B>,
|
|
203
203
|
): HKT.Kind<G, GC, K, Q, W, X, I, S, R, E1, Either<E, B>> =>
|
|
204
|
-
self.match(
|
|
205
|
-
(e) => G.pure(Left(e)),
|
|
206
|
-
(a) => f(a).pipe(G.map((b) => Right(b))),
|
|
207
|
-
);
|
|
204
|
+
self.match({
|
|
205
|
+
Left: (e) => G.pure(Left(e)),
|
|
206
|
+
Right: (a) => f(a).pipe(G.map((b) => Right(b))),
|
|
207
|
+
});
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
export const traverse_: P.Traversable<EitherF>["traverse"] = (A) => (f) => (self) => self.traverse(A)(f);
|
|
@@ -288,10 +288,10 @@ export function partition<E, A>(p: Predicate<A>, /** @tsplus auto */ M: P.Monoid
|
|
|
288
288
|
* @tsplus getter fncts.Either toMaybe
|
|
289
289
|
*/
|
|
290
290
|
export function toMaybe<E, A>(self: Either<E, A>): Maybe<A> {
|
|
291
|
-
return self.match(
|
|
292
|
-
() => Nothing(),
|
|
293
|
-
(a) => Just(a),
|
|
294
|
-
);
|
|
291
|
+
return self.match({
|
|
292
|
+
Left: () => Nothing(),
|
|
293
|
+
Right: (a) => Just(a),
|
|
294
|
+
});
|
|
295
295
|
}
|
|
296
296
|
|
|
297
297
|
// codegen:start { preset: barrel, include: api/*.ts }
|
|
@@ -3,14 +3,14 @@ import { EitherTag } from "./definition.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* @tsplus pipeable fncts.Either match
|
|
5
5
|
*/
|
|
6
|
-
export function match<E, A, B, C>(
|
|
6
|
+
export function match<E, A, B, C>(cases: { Left: (e: E) => B; Right: (a: A) => C }) {
|
|
7
7
|
return (self: Either<E, A>): B | C => {
|
|
8
8
|
self.concrete();
|
|
9
9
|
switch (self._tag) {
|
|
10
10
|
case EitherTag.Left:
|
|
11
|
-
return
|
|
11
|
+
return cases.Left(self.left);
|
|
12
12
|
case EitherTag.Right:
|
|
13
|
-
return
|
|
13
|
+
return cases.Right(self.right);
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
16
|
}
|
|
@@ -20,18 +20,18 @@ export function getEq<E, A>(EE: P.Eq<E>, EA: P.Eq<A>): P.Eq<Either<E, A>> {
|
|
|
20
20
|
return P.Eq({
|
|
21
21
|
equals: (y) => (x) =>
|
|
22
22
|
x === y ||
|
|
23
|
-
x.match(
|
|
24
|
-
(e1) =>
|
|
25
|
-
y.match(
|
|
26
|
-
(e2) => EE.equals(e2)(e1),
|
|
27
|
-
() => false,
|
|
28
|
-
),
|
|
29
|
-
(a1) =>
|
|
30
|
-
y.match(
|
|
31
|
-
() => false,
|
|
32
|
-
(a2) => EA.equals(a2)(a1),
|
|
33
|
-
),
|
|
34
|
-
),
|
|
23
|
+
x.match({
|
|
24
|
+
Left: (e1) =>
|
|
25
|
+
y.match({
|
|
26
|
+
Left: (e2) => EE.equals(e2)(e1),
|
|
27
|
+
Right: () => false,
|
|
28
|
+
}),
|
|
29
|
+
Right: (a1) =>
|
|
30
|
+
y.match({
|
|
31
|
+
Left: () => false,
|
|
32
|
+
Right: (a2) => EA.equals(a2)(a1),
|
|
33
|
+
}),
|
|
34
|
+
}),
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
|
package/_src/data/EitherT/api.ts
CHANGED
|
@@ -122,10 +122,10 @@ export function flatMap<F extends HKT, FC>(F: P.Monad<F, FC>) {
|
|
|
122
122
|
>) =>
|
|
123
123
|
F.flatMap(
|
|
124
124
|
(either) =>
|
|
125
|
-
either.match(
|
|
126
|
-
(e) => F.pure(Either.left(e)),
|
|
127
|
-
(a) => f(a),
|
|
128
|
-
) as HKT.Kind<
|
|
125
|
+
either.match({
|
|
126
|
+
Left: (e) => F.pure(Either.left(e)),
|
|
127
|
+
Right: (a) => f(a),
|
|
128
|
+
}) as HKT.Kind<
|
|
129
129
|
F,
|
|
130
130
|
FC,
|
|
131
131
|
HKT.Intro<F, "K", K, K1>,
|
|
@@ -225,9 +225,9 @@ export function orElse<F>(F: P.Monad<HKT.F1<F>>) {
|
|
|
225
225
|
that: Lazy<HKT.FK1<F, Either<E1, B>>>,
|
|
226
226
|
): ((self: HKT.FK1<F, Either<E, A>>) => HKT.FK1<F, Either<E | E1, A | B>>) =>
|
|
227
227
|
F.flatMap((either) =>
|
|
228
|
-
either.match(
|
|
229
|
-
() => that(),
|
|
230
|
-
() => F.pure(either),
|
|
231
|
-
),
|
|
228
|
+
either.match({
|
|
229
|
+
Left: () => that(),
|
|
230
|
+
Right: () => F.pure(either),
|
|
231
|
+
}),
|
|
232
232
|
);
|
|
233
233
|
}
|
|
@@ -18,7 +18,7 @@ export function fail<E = never, A = never>(e: E, __tsplusTrace?: string): Exit<E
|
|
|
18
18
|
* @tsplus static fncts.ExitOps fromEither
|
|
19
19
|
*/
|
|
20
20
|
export function fromEither<E = never, A = never>(e: Either<E, A>): Exit<E, A> {
|
|
21
|
-
return e.match(fail, succeed);
|
|
21
|
+
return e.match({ Left: fail, Right: succeed });
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const globalStoreId = Symbol.for("fncts.GlobalStore");
|
|
2
|
+
|
|
3
|
+
if (!(globalStoreId in globalThis)) {
|
|
4
|
+
(globalThis as any)[globalStoreId] = new Map();
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const globalStore = (globalThis as any)[globalStoreId] as Map<unknown, any>;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @since 1.0.0
|
|
11
|
+
*/
|
|
12
|
+
export const globalValue = <A>(id: unknown, compute: () => A): A => {
|
|
13
|
+
if (!globalStore.has(id)) {
|
|
14
|
+
globalStore.set(id, compute());
|
|
15
|
+
}
|
|
16
|
+
return globalStore.get(id)!;
|
|
17
|
+
};
|
package/_src/data/Maybe/api.ts
CHANGED
|
@@ -95,10 +95,10 @@ export function partitionMap<A, B, C>(f: (a: A) => Either<B, C>) {
|
|
|
95
95
|
return (self: Maybe<A>): readonly [Maybe<B>, Maybe<C>] => {
|
|
96
96
|
self.concrete();
|
|
97
97
|
if (self._tag === MaybeTag.Just) {
|
|
98
|
-
return f(self.value).match(
|
|
99
|
-
(b) => [Just(b), Nothing()],
|
|
100
|
-
(c) => [Nothing(), Just(c)],
|
|
101
|
-
);
|
|
98
|
+
return f(self.value).match({
|
|
99
|
+
Left: (b) => [Just(b), Nothing()],
|
|
100
|
+
Right: (c) => [Nothing(), Just(c)],
|
|
101
|
+
});
|
|
102
102
|
} else {
|
|
103
103
|
return [Nothing(), Nothing()];
|
|
104
104
|
}
|
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/Date.js";
|
|
9
10
|
export type {} from "./data/DatumEither.js";
|
|
10
11
|
export type {} from "./data/DecodeError.js";
|
|
11
12
|
export type {} from "./data/Decoder.js";
|
|
@@ -21,6 +22,7 @@ export type {} from "./data/ExecutionStrategy.js";
|
|
|
21
22
|
export type {} from "./data/Exit.js";
|
|
22
23
|
export type {} from "./data/FiberId.js";
|
|
23
24
|
export type {} from "./data/function.js";
|
|
25
|
+
export type {} from "./data/Global.js";
|
|
24
26
|
export type {} from "./data/Guard.js";
|
|
25
27
|
export type {} from "./data/Hash.js";
|
|
26
28
|
export type {} from "./data/Hashable.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Fold, FoldPartiallyApplied } from "@fncts/base/optics/Fold";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @tsplus pipeable global focus 4
|
|
5
|
+
*/
|
|
6
|
+
export function focus<S, A>(fold: Fold<S, A>) {
|
|
7
|
+
return (self: S): FoldPartiallyApplied<A> => {
|
|
8
|
+
return {
|
|
9
|
+
foldMap: (M) => (f) => fold.foldMap(M)(f)(self),
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import type { Monoid } from "@fncts/base/typeclass";
|
|
2
|
+
|
|
2
3
|
export interface foldMap<S, A> {
|
|
3
4
|
<M>(M: Monoid<M>): (f: (a: A) => M) => (s: S) => M;
|
|
4
5
|
}
|
|
5
6
|
|
|
7
|
+
export interface foldMapPartiallyApplied<A> {
|
|
8
|
+
<M>(M: Monoid<M>): (f: (a: A) => M) => M;
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
/**
|
|
7
12
|
* @tsplus type fncts.optics.Fold
|
|
8
13
|
*/
|
|
@@ -10,6 +15,10 @@ export interface Fold<S, A> {
|
|
|
10
15
|
readonly foldMap: foldMap<S, A>;
|
|
11
16
|
}
|
|
12
17
|
|
|
18
|
+
export interface FoldPartiallyApplied<A> {
|
|
19
|
+
readonly foldMap: foldMapPartiallyApplied<A>;
|
|
20
|
+
}
|
|
21
|
+
|
|
13
22
|
/**
|
|
14
23
|
* @tsplus type fncts.optics.FoldOps
|
|
15
24
|
*/
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import type { Fold } from "@fncts/base/optics/Fold";
|
|
1
|
+
import type { Fold, FoldPartiallyApplied } from "@fncts/base/optics/Fold";
|
|
2
2
|
|
|
3
3
|
export interface get<S, A> {
|
|
4
4
|
(s: S): A;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
+
export interface getPartiallyApplied<A> {
|
|
8
|
+
(): A;
|
|
9
|
+
}
|
|
10
|
+
|
|
7
11
|
/**
|
|
8
12
|
* @tsplus type fncts.optics.Getter
|
|
9
13
|
*/
|
|
@@ -11,6 +15,10 @@ export interface Getter<S, A> extends Fold<S, A> {
|
|
|
11
15
|
readonly get: get<S, A>;
|
|
12
16
|
}
|
|
13
17
|
|
|
18
|
+
export interface GetterPartiallyApplied<A> extends FoldPartiallyApplied<A> {
|
|
19
|
+
readonly get: getPartiallyApplied<A>;
|
|
20
|
+
}
|
|
21
|
+
|
|
14
22
|
/**
|
|
15
23
|
* @tsplus type fncts.optics.GetterOps
|
|
16
24
|
*/
|
package/_src/optics/Index/api.ts
CHANGED
|
@@ -2,7 +2,8 @@ import type { At } from "@fncts/base/optics/At";
|
|
|
2
2
|
import type { Iso } from "@fncts/base/optics/Iso";
|
|
3
3
|
|
|
4
4
|
import { Index } from "@fncts/base/optics/Index/definition";
|
|
5
|
-
import {
|
|
5
|
+
import { Optional } from "@fncts/base/optics/Optional/definition";
|
|
6
|
+
import { Prism } from "@fncts/base/optics/Prism/definition";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @tsplus static fncts.optics.IndexOps fromAt
|
|
@@ -17,3 +18,16 @@ export function fromAt<T, J, B>(at: At<T, J, Maybe<B>>): Index<T, J, B> {
|
|
|
17
18
|
export function fromIso<T, S>(iso: Iso<T, S>) {
|
|
18
19
|
return <I, A>(index: Index<S, I, A>): Index<T, I, A> => Index({ index: (i) => iso.compose(index.index(i)) });
|
|
19
20
|
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @tsplus static fncts.optics.IndexOps array
|
|
24
|
+
*/
|
|
25
|
+
export function array<A = never>(): Index<ReadonlyArray<A>, number, A> {
|
|
26
|
+
return Index({
|
|
27
|
+
index: (i) =>
|
|
28
|
+
Optional({
|
|
29
|
+
getOrModify: (s) => (i in s ? Either.right(s[i]!) : Either.left(s)),
|
|
30
|
+
set: (a) => (s) => s.updateAt(i, a),
|
|
31
|
+
}),
|
|
32
|
+
});
|
|
33
|
+
}
|
package/_src/optics/Iso/api.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import type { PIsoPartiallyApplied } from "@fncts/base/optics/Iso/definition";
|
|
2
|
+
import type { PLens } from "@fncts/base/optics/Lens";
|
|
3
|
+
import type { PPrism } from "@fncts/base/optics/Prism";
|
|
4
|
+
|
|
1
5
|
import { PIso } from "@fncts/base/optics/Iso/definition";
|
|
2
6
|
|
|
3
7
|
/**
|
|
@@ -11,3 +15,15 @@ export function compose<A, B, C, D>(that: PIso<A, B, C, D>) {
|
|
|
11
15
|
});
|
|
12
16
|
};
|
|
13
17
|
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @tsplus pipeable global focus
|
|
21
|
+
*/
|
|
22
|
+
export function focus<S, T, A, B>(iso: PIso<S, T, A, B>) {
|
|
23
|
+
return (self: S): PIsoPartiallyApplied<T, A, B> => {
|
|
24
|
+
return {
|
|
25
|
+
...self.focus(iso as PLens<S, T, A, B>),
|
|
26
|
+
...self.focus(iso as PPrism<S, T, A, B>),
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { get } from "@fncts/base/optics/Getter";
|
|
2
|
-
import type {
|
|
2
|
+
import type { PLensPartiallyApplied } from "@fncts/base/optics/Lens";
|
|
3
|
+
import type { PPrismPartiallyApplied, reverseGet } from "@fncts/base/optics/Prism";
|
|
3
4
|
|
|
4
5
|
import { PLens } from "@fncts/base/optics/Lens";
|
|
5
6
|
import { PPrism } from "@fncts/base/optics/Prism";
|
|
@@ -11,6 +12,10 @@ export interface PIso<S, T, A, B> extends PLens<S, T, A, B>, PPrism<S, T, A, B>
|
|
|
11
12
|
readonly reverse: () => PIso<B, A, T, S>;
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
export interface PIsoPartiallyApplied<T, A, B>
|
|
16
|
+
extends PLensPartiallyApplied<T, A, B>,
|
|
17
|
+
PPrismPartiallyApplied<T, A, B> {}
|
|
18
|
+
|
|
14
19
|
/**
|
|
15
20
|
* @tsplus type fncts.optics.PIsoOps
|
|
16
21
|
*/
|
package/_src/optics/Lens/api.ts
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PLensPartiallyApplied } from "@fncts/base/optics/Lens/definition";
|
|
2
|
+
import type { Optional, POptional } from "@fncts/base/optics/Optional";
|
|
3
|
+
import type { PTraversal } from "@fncts/base/optics/Traversal";
|
|
2
4
|
import type { AutoPath, Path } from "@fncts/typelevel/Object";
|
|
3
5
|
|
|
4
6
|
import { identity } from "@fncts/base/data/function";
|
|
5
7
|
import { Lens, PLens } from "@fncts/base/optics/Lens/definition";
|
|
6
8
|
import { Prism } from "@fncts/base/optics/Prism";
|
|
7
9
|
|
|
10
|
+
/**
|
|
11
|
+
* @tsplus pipeable global focus
|
|
12
|
+
*/
|
|
13
|
+
export function focus<S, T, A, B>(lens: PLens<S, T, A, B>) {
|
|
14
|
+
return (self: S): PLensPartiallyApplied<T, A, B> => {
|
|
15
|
+
return {
|
|
16
|
+
...self.focus(lens as POptional<S, T, A, B>),
|
|
17
|
+
get: () => lens.get(self),
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
8
22
|
/**
|
|
9
23
|
* @tsplus pipeable fncts.optics.PLens component
|
|
10
24
|
*/
|
|
@@ -114,16 +128,14 @@ function nestPath<A>(p: ReadonlyNonEmptyArray<string>, a: A): Record<string, unk
|
|
|
114
128
|
return out;
|
|
115
129
|
}
|
|
116
130
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
*/
|
|
120
|
-
export function path<A extends Record<string, unknown>, P extends Array<string>>(path: readonly [...AutoPath<A, P>]) {
|
|
121
|
-
return <S>(self: Lens<S, A>): Lens<S, Path<A, P>> => {
|
|
131
|
+
function anyPath(path: ReadonlyArray<string>) {
|
|
132
|
+
return (self: Lens<any, any>): Lens<any, any> => {
|
|
122
133
|
return Lens({
|
|
123
|
-
get: (s) =>
|
|
134
|
+
get: (s) =>
|
|
135
|
+
path.foldLeft<string, Record<string, unknown>>(self.get(s), (b, p) => b[p] as Record<string, unknown>),
|
|
124
136
|
set: (a) => (s) => {
|
|
125
137
|
const os = self.get(s);
|
|
126
|
-
const oa = path.foldLeft(os, (b, p) => b[p as string] as
|
|
138
|
+
const oa = path.foldLeft(os, (b, p) => b[p as string] as Record<string, unknown>);
|
|
127
139
|
if (a === oa) {
|
|
128
140
|
return s;
|
|
129
141
|
}
|
|
@@ -132,3 +144,19 @@ export function path<A extends Record<string, unknown>, P extends Array<string>>
|
|
|
132
144
|
});
|
|
133
145
|
};
|
|
134
146
|
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @tsplus pipeable fncts.optics.Lens path
|
|
150
|
+
*/
|
|
151
|
+
export function path<A extends Record<string, unknown>, P extends Array<string>>(path: readonly [...AutoPath<A, P>]) {
|
|
152
|
+
return <S>(self: Lens<S, A>): Lens<S, Path<A, P>> => {
|
|
153
|
+
return anyPath(path)(self);
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* @tsplus static fncts.optics.LensOps fromPath
|
|
159
|
+
*/
|
|
160
|
+
export function fromPath<S, P extends Array<string>>(path: readonly [...AutoPath<S, P>]): Lens<S, Path<S, P>> {
|
|
161
|
+
return anyPath(path)(Lens.id());
|
|
162
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { get } from "@fncts/base/optics/Getter";
|
|
1
|
+
import type { get, GetterPartiallyApplied } from "@fncts/base/optics/Getter";
|
|
2
|
+
import type { POptionalPartiallyApplied } from "@fncts/base/optics/Optional";
|
|
2
3
|
import type { set } from "@fncts/base/optics/Setter";
|
|
3
4
|
|
|
4
5
|
import { Getter } from "@fncts/base/optics/Getter";
|
|
@@ -9,6 +10,8 @@ import { POptional } from "@fncts/base/optics/Optional";
|
|
|
9
10
|
*/
|
|
10
11
|
export interface PLens<S, T, A, B> extends POptional<S, T, A, B>, Getter<S, A> {}
|
|
11
12
|
|
|
13
|
+
export interface PLensPartiallyApplied<T, A, B> extends POptionalPartiallyApplied<T, A, B>, GetterPartiallyApplied<A> {}
|
|
14
|
+
|
|
12
15
|
/**
|
|
13
16
|
* @tsplus type fncts.optics.PLensOps
|
|
14
17
|
*/
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { POptional, POptionalPartiallyApplied } from "@fncts/base/optics/Optional";
|
|
2
|
+
import type { PTraversal } from "@fncts/base/optics/Traversal";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @tsplus pipeable global focus 1
|
|
6
|
+
*/
|
|
7
|
+
export function focus<S, T, A, B>(optional: POptional<S, T, A, B>) {
|
|
8
|
+
return (self: S): POptionalPartiallyApplied<T, A, B> => {
|
|
9
|
+
return {
|
|
10
|
+
...self.focus(optional as PTraversal<S, T, A, B>),
|
|
11
|
+
getMaybe: () => optional.getMaybe(self),
|
|
12
|
+
modifyMaybe: (f) => optional.modifyMaybe(f)(self),
|
|
13
|
+
getOrModify: () => optional.getOrModify(self),
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Optional } from "@fncts/base/optics/Optional/definition";
|
|
2
|
+
|
|
3
|
+
import { Index } from "@fncts/base/optics/Index";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @tsplus static fncts.optics.OptionalOps index
|
|
7
|
+
*/
|
|
8
|
+
export function index<A>(index: number): Optional<ReadonlyArray<A>, A> {
|
|
9
|
+
return Index.array<A>().index(index);
|
|
10
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { set } from "@fncts/base/optics/Setter";
|
|
2
|
+
import type { PTraversalPartiallyApplied } from "@fncts/base/optics/Traversal";
|
|
2
3
|
|
|
3
4
|
import { pipe } from "@fncts/base/data/function";
|
|
4
5
|
import { PTraversal } from "@fncts/base/optics/Traversal";
|
|
@@ -12,6 +13,12 @@ export interface POptional<S, T, A, B> extends PTraversal<S, T, A, B> {
|
|
|
12
13
|
readonly modifyMaybe: modifyMaybe<S, T, A, B>;
|
|
13
14
|
}
|
|
14
15
|
|
|
16
|
+
export interface POptionalPartiallyApplied<T, A, B> extends PTraversalPartiallyApplied<T, A, B> {
|
|
17
|
+
readonly getMaybe: getMaybePartiallyApplied<A>;
|
|
18
|
+
readonly getOrModify: getOrModifyPartiallyApplied<T, A>;
|
|
19
|
+
readonly modifyMaybe: modifyMaybePartiallyApplied<T, A, B>;
|
|
20
|
+
}
|
|
21
|
+
|
|
15
22
|
export interface POptionalMin<S, T, A, B> {
|
|
16
23
|
readonly getOrModify: getOrModify<S, T, A>;
|
|
17
24
|
readonly set: set<S, T, B>;
|
|
@@ -35,10 +42,10 @@ export function makePOptional<S, T, A, B>(F: POptionalMin<S, T, A, B>): POptiona
|
|
|
35
42
|
modifyMaybe: (f) => (s) => getMaybe(s).map((a) => pipe(s, F.set(f(a)))),
|
|
36
43
|
...PTraversal<S, T, A, B>({
|
|
37
44
|
modifyA: (A) => (f) => (s) =>
|
|
38
|
-
F.getOrModify(s).match(
|
|
39
|
-
(t) => A.pure(t),
|
|
40
|
-
(a) => f(a).pipe(A.map((b) => s.pipe(F.set(b)))),
|
|
41
|
-
),
|
|
45
|
+
F.getOrModify(s).match({
|
|
46
|
+
Left: (t) => A.pure(t),
|
|
47
|
+
Right: (a) => f(a).pipe(A.map((b) => s.pipe(F.set(b)))),
|
|
48
|
+
}),
|
|
42
49
|
}),
|
|
43
50
|
};
|
|
44
51
|
}
|
|
@@ -81,3 +88,15 @@ export interface replaceMaybe_<S, T, B> {
|
|
|
81
88
|
export interface replaceMaybe<S, T, B> {
|
|
82
89
|
(b: B): (s: S) => Maybe<T>;
|
|
83
90
|
}
|
|
91
|
+
|
|
92
|
+
export interface getMaybePartiallyApplied<A> {
|
|
93
|
+
(): Maybe<A>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface getOrModifyPartiallyApplied<T, A> {
|
|
97
|
+
(): Either<T, A>;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface modifyMaybePartiallyApplied<T, A, B> {
|
|
101
|
+
(f: (a: A) => B): Maybe<T>;
|
|
102
|
+
}
|
package/_src/optics/Optional.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// codegen:start { preset: barrel, include: ./Optional/*.ts }
|
|
2
|
+
export * from "./Optional/api.js";
|
|
2
3
|
export * from "./Optional/definition.js";
|
|
3
4
|
// codegen:end
|
|
4
5
|
// codegen:start { preset: barrel, include: ./Optional/api/*.ts }
|
|
5
6
|
export * from "./Optional/api/compose.js";
|
|
7
|
+
export * from "./Optional/api/focus.js";
|
|
6
8
|
// codegen:end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { POptional } from "@fncts/base/optics/Optional";
|
|
2
|
+
import type { PPrism, PPrismPartiallyApplied } from "@fncts/base/optics/Prism";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @tsplus pipeable global focus
|
|
6
|
+
*/
|
|
7
|
+
export function focus<S, T, A, B>(prism: PPrism<S, T, A, B>) {
|
|
8
|
+
return (self: S): PPrismPartiallyApplied<T, A, B> => {
|
|
9
|
+
return {
|
|
10
|
+
...self.focus(prism as POptional<S, T, A, B>),
|
|
11
|
+
reverseGet: prism.reverseGet,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { getOrModify } from "@fncts/base/optics/Optional";
|
|
1
|
+
import type { getOrModify, POptionalPartiallyApplied } from "@fncts/base/optics/Optional";
|
|
2
2
|
|
|
3
3
|
import { identity } from "@fncts/base/data/function";
|
|
4
4
|
import { POptional } from "@fncts/base/optics/Optional";
|
|
@@ -10,6 +10,10 @@ export interface PPrism<S, T, A, B> extends POptional<S, T, A, B> {
|
|
|
10
10
|
readonly reverseGet: reverseGet<T, B>;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
export interface PPrismPartiallyApplied<T, A, B> extends POptionalPartiallyApplied<T, A, B> {
|
|
14
|
+
readonly reverseGet: reverseGet<T, B>;
|
|
15
|
+
}
|
|
16
|
+
|
|
13
17
|
/**
|
|
14
18
|
* @tsplus type fncts.optics.PPrismOps
|
|
15
19
|
*/
|
|
@@ -30,7 +34,7 @@ export function makePPrism<S, T, A, B>(F: PPrismMin<S, T, A, B>): PPrism<S, T, A
|
|
|
30
34
|
reverseGet: F.reverseGet,
|
|
31
35
|
...POptional({
|
|
32
36
|
getOrModify: F.getOrModify,
|
|
33
|
-
set: (b) => (s) => F.getOrModify(s).match(identity, () => F.reverseGet(b)),
|
|
37
|
+
set: (b) => (s) => F.getOrModify(s).match({ Left: identity, Right: () => F.reverseGet(b) }),
|
|
34
38
|
}),
|
|
35
39
|
};
|
|
36
40
|
}
|
package/_src/optics/Prism.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from "./Prism/definition.js";
|
|
|
3
3
|
// codegen:end
|
|
4
4
|
// codegen:start { preset: barrel, include: ./Prism/api/*.ts }
|
|
5
5
|
export * from "./Prism/api/compose.js";
|
|
6
|
+
export * from "./Prism/api/focus.js";
|
|
6
7
|
export * from "./Prism/api/fromNullable.js";
|
|
7
8
|
export * from "./Prism/api/just.js";
|
|
8
9
|
// codegen:end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PSetter, PSetterPartiallyApplied } from "@fncts/base/optics/Setter";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @tsplus pipeable global focus 3
|
|
5
|
+
*/
|
|
6
|
+
export function focus<S, T, A, B>(setter: PSetter<S, T, A, B>) {
|
|
7
|
+
return (self: S): PSetterPartiallyApplied<T, A, B> => {
|
|
8
|
+
return {
|
|
9
|
+
set: (b) => setter.set(b)(self),
|
|
10
|
+
modify: (f) => setter.modify(f)(self),
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -6,6 +6,11 @@ export interface PSetter<S, T, A, B> {
|
|
|
6
6
|
readonly set: set<S, T, B>;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
export interface PSetterPartiallyApplied<T, A, B> {
|
|
10
|
+
readonly modify: modifyPartiallyApplied<T, A, B>;
|
|
11
|
+
readonly set: setPartiallyApplied<T, B>;
|
|
12
|
+
}
|
|
13
|
+
|
|
9
14
|
/**
|
|
10
15
|
* @tsplus type fncts.optics.PSetterOps
|
|
11
16
|
*/
|
|
@@ -44,3 +49,11 @@ export interface modify<S, T, A, B> {
|
|
|
44
49
|
export interface set<S, T, B> {
|
|
45
50
|
(b: B): (s: S) => T;
|
|
46
51
|
}
|
|
52
|
+
|
|
53
|
+
export interface modifyPartiallyApplied<T, A, B> {
|
|
54
|
+
(f: (a: A) => B): T;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface setPartiallyApplied<T, B> {
|
|
58
|
+
(b: B): T;
|
|
59
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Fold } from "@fncts/base/optics/Fold";
|
|
2
|
+
import type { PSetter } from "@fncts/base/optics/Setter";
|
|
3
|
+
import type { PTraversal, PTraversalPartiallyApplied } from "@fncts/base/optics/Traversal";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @tsplus pipeable global focus 2
|
|
7
|
+
*/
|
|
8
|
+
export function focus<S, T, A, B>(traversal: PTraversal<S, T, A, B>) {
|
|
9
|
+
return (self: S): PTraversalPartiallyApplied<T, A, B> => {
|
|
10
|
+
return {
|
|
11
|
+
...self.focus(traversal as PSetter<S, T, A, B>),
|
|
12
|
+
...self.focus(traversal as Fold<S, A>),
|
|
13
|
+
modifyA: (F) => (f) => traversal.modifyA(F)(f)(self),
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { FoldPartiallyApplied } from "@fncts/base/optics/Fold";
|
|
2
|
+
import type { PSetterPartiallyApplied } from "@fncts/base/optics/Setter";
|
|
1
3
|
import type { Applicative, Monoid } from "@fncts/base/typeclass";
|
|
2
4
|
|
|
3
5
|
import { Fold } from "@fncts/base/optics/Fold";
|
|
@@ -14,6 +16,14 @@ export interface PTraversal<S, T, A, B> extends PSetter<S, T, A, B>, Fold<S, A>
|
|
|
14
16
|
) => (s: S) => HKT.Kind<F, FC, K, Q, W, X, I, _S, R, E, T>;
|
|
15
17
|
}
|
|
16
18
|
|
|
19
|
+
export interface PTraversalPartiallyApplied<T, A, B> extends PSetterPartiallyApplied<T, A, B>, FoldPartiallyApplied<A> {
|
|
20
|
+
modifyA: <F extends HKT, FC = HKT.None>(
|
|
21
|
+
F: Applicative<F, FC>,
|
|
22
|
+
) => <K, Q, W, X, I, _S, R, E>(
|
|
23
|
+
f: (a: A) => HKT.Kind<F, FC, K, Q, W, X, I, _S, R, E, B>,
|
|
24
|
+
) => HKT.Kind<F, FC, K, Q, W, X, I, _S, R, E, T>;
|
|
25
|
+
}
|
|
26
|
+
|
|
17
27
|
export interface PTraversalMin<S, T, A, B> {
|
|
18
28
|
modifyA: <F extends HKT, FC = HKT.None>(
|
|
19
29
|
F: Applicative<F, FC>,
|
package/_src/optics/Traversal.ts
CHANGED
|
@@ -3,5 +3,6 @@ export * from "./Traversal/definition.js";
|
|
|
3
3
|
// codegen:end
|
|
4
4
|
// codegen:start { preset: barrel, include: ./Traversal/api/*.ts }
|
|
5
5
|
export * from "./Traversal/api/compose.js";
|
|
6
|
+
export * from "./Traversal/api/focus.js";
|
|
6
7
|
export * from "./Traversal/api/fromTraversable.js";
|
|
7
8
|
// codegen:end
|