@fncts/base 0.0.31 → 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.
Files changed (233) hide show
  1. package/_cjs/collection/compat/Array/api.cjs +53 -0
  2. package/_cjs/collection/compat/Array/api.cjs.map +1 -1
  3. package/_cjs/collection/immutable/Conc/api.cjs +4 -1
  4. package/_cjs/collection/immutable/Conc/api.cjs.map +1 -1
  5. package/_cjs/collection/immutable/Dictionary/api.cjs +54 -8
  6. package/_cjs/collection/immutable/Dictionary/api.cjs.map +1 -1
  7. package/_cjs/collection/immutable/HashMap/api.cjs +7 -4
  8. package/_cjs/collection/immutable/HashMap/api.cjs.map +1 -1
  9. package/_cjs/collection/immutable/HashSet/api.cjs +7 -4
  10. package/_cjs/collection/immutable/HashSet/api.cjs.map +1 -1
  11. package/_cjs/collection/immutable/ImmutableArray/api.cjs +9 -6
  12. package/_cjs/collection/immutable/ImmutableArray/api.cjs.map +1 -1
  13. package/_cjs/collection/internal.cjs +6 -0
  14. package/_cjs/collection/internal.cjs.map +1 -0
  15. package/_cjs/collection/mutable/ArrayDeque.cjs +214 -0
  16. package/_cjs/collection/mutable/ArrayDeque.cjs.map +1 -0
  17. package/_cjs/collection/mutable/Queue.cjs +21 -0
  18. package/_cjs/collection/mutable/Queue.cjs.map +1 -0
  19. package/_cjs/control/InterruptiblePromise.cjs +23 -0
  20. package/_cjs/control/InterruptiblePromise.cjs.map +1 -0
  21. package/_cjs/control/Pure/api.cjs +20 -8
  22. package/_cjs/control/Pure/api.cjs.map +1 -1
  23. package/_cjs/data/Cause/api.cjs +8 -2
  24. package/_cjs/data/Cause/api.cjs.map +1 -1
  25. package/_cjs/data/Datum/api.cjs +8 -2
  26. package/_cjs/data/Datum/api.cjs.map +1 -1
  27. package/_cjs/data/DatumEither/api.cjs +8 -2
  28. package/_cjs/data/DatumEither/api.cjs.map +1 -1
  29. package/_cjs/data/Either/api.cjs +24 -6
  30. package/_cjs/data/Either/api.cjs.map +1 -1
  31. package/_cjs/data/Either/destructors.cjs +3 -3
  32. package/_cjs/data/Either/destructors.cjs.map +1 -1
  33. package/_cjs/data/Either/instances.cjs +10 -1
  34. package/_cjs/data/Either/instances.cjs.map +1 -1
  35. package/_cjs/data/EitherT/api.cjs +8 -2
  36. package/_cjs/data/EitherT/api.cjs.map +1 -1
  37. package/_cjs/data/Exit/constructors.cjs +4 -1
  38. package/_cjs/data/Exit/constructors.cjs.map +1 -1
  39. package/_cjs/data/Global.cjs +22 -0
  40. package/_cjs/data/Global.cjs.map +1 -0
  41. package/_cjs/data/Maybe/api.cjs +4 -1
  42. package/_cjs/data/Maybe/api.cjs.map +1 -1
  43. package/_cjs/optics/Fold/api/focus.cjs +17 -0
  44. package/_cjs/optics/Fold/api/focus.cjs.map +1 -0
  45. package/_cjs/optics/Fold/definition.cjs.map +1 -1
  46. package/_cjs/optics/Getter/definition.cjs.map +1 -1
  47. package/_cjs/optics/Index/api.cjs +16 -0
  48. package/_cjs/optics/Index/api.cjs.map +1 -1
  49. package/_cjs/optics/Iso/api.cjs +14 -0
  50. package/_cjs/optics/Iso/api.cjs.map +1 -1
  51. package/_cjs/optics/Iso/definition.cjs.map +1 -1
  52. package/_cjs/optics/Lens/api.cjs +50 -24
  53. package/_cjs/optics/Lens/api.cjs.map +1 -1
  54. package/_cjs/optics/Lens/definition.cjs +1 -1
  55. package/_cjs/optics/Lens/definition.cjs.map +1 -1
  56. package/_cjs/optics/Optional/api/focus.cjs +23 -0
  57. package/_cjs/optics/Optional/api/focus.cjs.map +1 -0
  58. package/_cjs/optics/Optional/api.cjs +16 -0
  59. package/_cjs/optics/Optional/api.cjs.map +1 -0
  60. package/_cjs/optics/Optional/definition.cjs +4 -1
  61. package/_cjs/optics/Optional/definition.cjs.map +1 -1
  62. package/_cjs/optics/Optional.cjs +22 -0
  63. package/_cjs/optics/Optional.cjs.map +1 -1
  64. package/_cjs/optics/Prism/api/focus.cjs +21 -0
  65. package/_cjs/optics/Prism/api/focus.cjs.map +1 -0
  66. package/_cjs/optics/Prism/definition.cjs +4 -1
  67. package/_cjs/optics/Prism/definition.cjs.map +1 -1
  68. package/_cjs/optics/Prism.cjs +11 -0
  69. package/_cjs/optics/Prism.cjs.map +1 -1
  70. package/_cjs/optics/Setter/api/focus.cjs +18 -0
  71. package/_cjs/optics/Setter/api/focus.cjs.map +1 -0
  72. package/_cjs/optics/Setter/definition.cjs.map +1 -1
  73. package/_cjs/optics/Traversal/api/focus.cjs +23 -0
  74. package/_cjs/optics/Traversal/api/focus.cjs.map +1 -0
  75. package/_cjs/optics/Traversal/definition.cjs.map +1 -1
  76. package/_cjs/optics/Traversal.cjs +11 -0
  77. package/_cjs/optics/Traversal.cjs.map +1 -1
  78. package/_cjs/typeclass/MonadExcept.cjs +4 -1
  79. package/_cjs/typeclass/MonadExcept.cjs.map +1 -1
  80. package/_mjs/collection/compat/Array/api.mjs +48 -0
  81. package/_mjs/collection/compat/Array/api.mjs.map +1 -1
  82. package/_mjs/collection/immutable/Conc/api.mjs +4 -1
  83. package/_mjs/collection/immutable/Conc/api.mjs.map +1 -1
  84. package/_mjs/collection/immutable/Dictionary/api.mjs +47 -5
  85. package/_mjs/collection/immutable/Dictionary/api.mjs.map +1 -1
  86. package/_mjs/collection/immutable/HashMap/api.mjs +7 -4
  87. package/_mjs/collection/immutable/HashMap/api.mjs.map +1 -1
  88. package/_mjs/collection/immutable/HashSet/api.mjs +7 -4
  89. package/_mjs/collection/immutable/HashSet/api.mjs.map +1 -1
  90. package/_mjs/collection/immutable/ImmutableArray/api.mjs +9 -6
  91. package/_mjs/collection/immutable/ImmutableArray/api.mjs.map +1 -1
  92. package/_mjs/collection/internal.mjs +2 -0
  93. package/_mjs/collection/internal.mjs.map +1 -0
  94. package/_mjs/collection/mutable/ArrayDeque.mjs +205 -0
  95. package/_mjs/collection/mutable/ArrayDeque.mjs.map +1 -0
  96. package/_mjs/collection/mutable/Queue.mjs +14 -0
  97. package/_mjs/collection/mutable/Queue.mjs.map +1 -0
  98. package/_mjs/control/InterruptiblePromise.mjs +15 -0
  99. package/_mjs/control/InterruptiblePromise.mjs.map +1 -0
  100. package/_mjs/control/Pure/api.mjs +20 -8
  101. package/_mjs/control/Pure/api.mjs.map +1 -1
  102. package/_mjs/data/Cause/api.mjs +8 -2
  103. package/_mjs/data/Cause/api.mjs.map +1 -1
  104. package/_mjs/data/Datum/api.mjs +8 -2
  105. package/_mjs/data/Datum/api.mjs.map +1 -1
  106. package/_mjs/data/DatumEither/api.mjs +8 -2
  107. package/_mjs/data/DatumEither/api.mjs.map +1 -1
  108. package/_mjs/data/Either/api.mjs +24 -6
  109. package/_mjs/data/Either/api.mjs.map +1 -1
  110. package/_mjs/data/Either/destructors.mjs +3 -3
  111. package/_mjs/data/Either/destructors.mjs.map +1 -1
  112. package/_mjs/data/Either/instances.mjs +10 -1
  113. package/_mjs/data/Either/instances.mjs.map +1 -1
  114. package/_mjs/data/EitherT/api.mjs +8 -2
  115. package/_mjs/data/EitherT/api.mjs.map +1 -1
  116. package/_mjs/data/Exit/constructors.mjs +4 -1
  117. package/_mjs/data/Exit/constructors.mjs.map +1 -1
  118. package/_mjs/data/Global.mjs +15 -0
  119. package/_mjs/data/Global.mjs.map +1 -0
  120. package/_mjs/data/Maybe/api.mjs +4 -1
  121. package/_mjs/data/Maybe/api.mjs.map +1 -1
  122. package/_mjs/optics/Fold/api/focus.mjs +11 -0
  123. package/_mjs/optics/Fold/api/focus.mjs.map +1 -0
  124. package/_mjs/optics/Fold/definition.mjs.map +1 -1
  125. package/_mjs/optics/Getter/definition.mjs.map +1 -1
  126. package/_mjs/optics/Index/api.mjs +16 -0
  127. package/_mjs/optics/Index/api.mjs.map +1 -1
  128. package/_mjs/optics/Iso/api.mjs +13 -0
  129. package/_mjs/optics/Iso/api.mjs.map +1 -1
  130. package/_mjs/optics/Iso/definition.mjs.map +1 -1
  131. package/_mjs/optics/Lens/api.mjs +46 -22
  132. package/_mjs/optics/Lens/api.mjs.map +1 -1
  133. package/_mjs/optics/Lens/definition.mjs +1 -1
  134. package/_mjs/optics/Lens/definition.mjs.map +1 -1
  135. package/_mjs/optics/Optional/api/focus.mjs +15 -0
  136. package/_mjs/optics/Optional/api/focus.mjs.map +1 -0
  137. package/_mjs/optics/Optional/api.mjs +8 -0
  138. package/_mjs/optics/Optional/api.mjs.map +1 -0
  139. package/_mjs/optics/Optional/definition.mjs +4 -1
  140. package/_mjs/optics/Optional/definition.mjs.map +1 -1
  141. package/_mjs/optics/Optional.mjs +2 -0
  142. package/_mjs/optics/Optional.mjs.map +1 -1
  143. package/_mjs/optics/Prism/api/focus.mjs +13 -0
  144. package/_mjs/optics/Prism/api/focus.mjs.map +1 -0
  145. package/_mjs/optics/Prism/definition.mjs +4 -1
  146. package/_mjs/optics/Prism/definition.mjs.map +1 -1
  147. package/_mjs/optics/Prism.mjs +1 -0
  148. package/_mjs/optics/Prism.mjs.map +1 -1
  149. package/_mjs/optics/Setter/api/focus.mjs +12 -0
  150. package/_mjs/optics/Setter/api/focus.mjs.map +1 -0
  151. package/_mjs/optics/Setter/definition.mjs.map +1 -1
  152. package/_mjs/optics/Traversal/api/focus.mjs +15 -0
  153. package/_mjs/optics/Traversal/api/focus.mjs.map +1 -0
  154. package/_mjs/optics/Traversal/definition.mjs.map +1 -1
  155. package/_mjs/optics/Traversal.mjs +1 -0
  156. package/_mjs/optics/Traversal.mjs.map +1 -1
  157. package/_mjs/typeclass/MonadExcept.mjs +4 -1
  158. package/_mjs/typeclass/MonadExcept.mjs.map +1 -1
  159. package/_src/collection/compat/Array/api.ts +51 -0
  160. package/_src/collection/immutable/Conc/api.ts +4 -4
  161. package/_src/collection/immutable/Dictionary/api.ts +40 -0
  162. package/_src/collection/immutable/HashMap/api.ts +4 -4
  163. package/_src/collection/immutable/HashSet/api.ts +4 -4
  164. package/_src/collection/immutable/ImmutableArray/api.ts +4 -4
  165. package/_src/collection/internal.ts +0 -0
  166. package/_src/collection/mutable/ArrayDeque.ts +231 -0
  167. package/_src/collection/mutable/Queue.ts +14 -0
  168. package/_src/collection/mutable.ts +2 -0
  169. package/_src/control/InterruptiblePromise.ts +23 -0
  170. package/_src/control/Pure/api.ts +7 -4
  171. package/_src/data/Cause/api.ts +8 -8
  172. package/_src/data/Datum/api.ts +8 -8
  173. package/_src/data/DatumEither/api.ts +8 -8
  174. package/_src/data/Either/api.ts +18 -18
  175. package/_src/data/Either/destructors.ts +3 -3
  176. package/_src/data/Either/instances.ts +12 -12
  177. package/_src/data/EitherT/api.ts +8 -8
  178. package/_src/data/Exit/constructors.ts +1 -1
  179. package/_src/data/Global.ts +17 -0
  180. package/_src/data/Maybe/api.ts +4 -4
  181. package/_src/data.ts +1 -0
  182. package/_src/optics/Fold/api/focus.ts +12 -0
  183. package/_src/optics/Fold/definition.ts +9 -0
  184. package/_src/optics/Getter/definition.ts +9 -1
  185. package/_src/optics/Index/api.ts +15 -1
  186. package/_src/optics/Iso/api.ts +16 -0
  187. package/_src/optics/Iso/definition.ts +6 -1
  188. package/_src/optics/Lens/api.ts +36 -8
  189. package/_src/optics/Lens/definition.ts +4 -1
  190. package/_src/optics/Optional/api/focus.ts +16 -0
  191. package/_src/optics/Optional/api.ts +10 -0
  192. package/_src/optics/Optional/definition.ts +23 -4
  193. package/_src/optics/Optional.ts +2 -0
  194. package/_src/optics/Prism/api/focus.ts +14 -0
  195. package/_src/optics/Prism/definition.ts +6 -2
  196. package/_src/optics/Prism.ts +1 -0
  197. package/_src/optics/Setter/api/focus.ts +13 -0
  198. package/_src/optics/Setter/definition.ts +13 -0
  199. package/_src/optics/Traversal/api/focus.ts +16 -0
  200. package/_src/optics/Traversal/definition.ts +10 -0
  201. package/_src/optics/Traversal.ts +1 -0
  202. package/_src/typeclass/MonadExcept.ts +1 -1
  203. package/collection/compat/Array/api.d.ts +19 -0
  204. package/collection/immutable/Dictionary/api.d.ts +21 -0
  205. package/collection/internal.d.ts +1 -0
  206. package/collection/mutable/ArrayDeque.d.ts +41 -0
  207. package/collection/mutable/Queue.d.ts +9 -0
  208. package/collection/mutable.d.ts +2 -0
  209. package/control/InterruptiblePromise.d.ts +12 -0
  210. package/data/Either/destructors.d.ts +4 -1
  211. package/data/Global.d.ts +4 -0
  212. package/data.d.ts +1 -0
  213. package/optics/Fold/api/focus.d.ts +6 -0
  214. package/optics/Fold/definition.d.ts +6 -0
  215. package/optics/Getter/definition.d.ts +7 -1
  216. package/optics/Index/api.d.ts +5 -0
  217. package/optics/Iso/api.d.ts +6 -0
  218. package/optics/Iso/definition.d.ts +4 -1
  219. package/optics/Lens/api.d.ts +11 -0
  220. package/optics/Lens/definition.d.ts +4 -1
  221. package/optics/Optional/api/focus.d.ts +6 -0
  222. package/optics/Optional/api.d.ts +6 -0
  223. package/optics/Optional/definition.d.ts +15 -0
  224. package/optics/Optional.d.ts +2 -0
  225. package/optics/Prism/api/focus.d.ts +6 -0
  226. package/optics/Prism/definition.d.ts +4 -1
  227. package/optics/Prism.d.ts +1 -0
  228. package/optics/Setter/api/focus.d.ts +6 -0
  229. package/optics/Setter/definition.d.ts +10 -0
  230. package/optics/Traversal/api/focus.d.ts +6 -0
  231. package/optics/Traversal/definition.d.ts +5 -0
  232. package/optics/Traversal.d.ts +1 -0
  233. package/package.json +1 -1
@@ -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>(left: (e: E) => B, right: (a: A) => 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 left(self.left);
11
+ return cases.Left(self.left);
12
12
  case EitherTag.Right:
13
- return right(self.right);
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
 
@@ -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
+ };
@@ -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
@@ -22,6 +22,7 @@ export type {} from "./data/ExecutionStrategy.js";
22
22
  export type {} from "./data/Exit.js";
23
23
  export type {} from "./data/FiberId.js";
24
24
  export type {} from "./data/function.js";
25
+ export type {} from "./data/Global.js";
25
26
  export type {} from "./data/Guard.js";
26
27
  export type {} from "./data/Hash.js";
27
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
  */
@@ -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 { Prism } from "@fncts/base/optics/Prism";
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
+ }
@@ -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 { reverseGet } from "@fncts/base/optics/Prism";
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
  */
@@ -1,10 +1,24 @@
1
- import type { Optional } from "@fncts/base/optics/Optional";
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
- * @tsplus pipeable fncts.optics.Lens path
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) => path.foldLeft<string, Record<string, unknown>>(self.get(s), (b, p) => b[p] as A) as Path<A, P>,
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 A);
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
+ }
@@ -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
  }
@@ -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>,
@@ -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
@@ -24,5 +24,5 @@ export function absolve<F extends HKT, FC = HKT.None>(
24
24
  export function absolve<F>(
25
25
  F: MonadExcept<HKT.F<F>>,
26
26
  ): <E, A, E1>(fa: HKT.FK2<F, E, Either<E1, A>>) => HKT.FK2<F, HKT.Mix<HKT.F<F>, "E", [E, E1]>, A> {
27
- return F.flatMap((r) => r.match(F.fail, F.pure));
27
+ return F.flatMap((r) => r.match({ Left: F.fail, Right: F.pure }));
28
28
  }
@@ -1,3 +1,4 @@
1
+ import { Maybe } from "@fncts/base/data/Maybe/definition";
1
2
  import { ReadonlyNonEmptyArray } from "@fncts/base/collection/immutable/ImmutableNonEmptyArray/definition";
2
3
  import type { Eq } from "@fncts/base/typeclass";
3
4
  /**
@@ -6,6 +7,18 @@ import type { Eq } from "@fncts/base/typeclass";
6
7
  * @tsplus location "@fncts/base/collection/compat/Array/api"
7
8
  */
8
9
  export declare function elem<A>(self: ReadonlyArray<A>): (eq: Eq<A>) => (a: A) => boolean;
10
+ /**
11
+ * @tsplus pipeable fncts.Array filterMap
12
+ * @tsplus pipeable fncts.ReadonlyArray filterMap
13
+ * @tsplus location "@fncts/base/collection/compat/Array/api"
14
+ */
15
+ export declare function filterMap<A, B>(f: (a: A) => Maybe<B>): (self: ReadonlyArray<A>) => ReadonlyArray<B>;
16
+ /**
17
+ * @tsplus pipeable fncts.Array filterMap
18
+ * @tsplus pipeable fncts.ReadonlyArray filterMap
19
+ * @tsplus location "@fncts/base/collection/compat/Array/api"
20
+ */
21
+ export declare function filterMapUndefined<A, B>(f: (a: A) => B | undefined): (self: ReadonlyArray<A>) => ReadonlyArray<B>;
9
22
  /**
10
23
  * @tsplus fluent fncts.Array isEmpty
11
24
  * @tsplus fluent fncts.ReadonlyArray isEmpty
@@ -30,3 +43,9 @@ export declare function foldLeft<A, B>(b: B, f: (b: B, a: A) => B): (self: Reado
30
43
  * @tsplus location "@fncts/base/collection/compat/Array/api"
31
44
  */
32
45
  export declare function foldLeftWithIndex<A, B>(b: B, f: (i: number, b: B, a: A) => B): (self: ReadonlyArray<A>) => B;
46
+ /**
47
+ * @tsplus pipeable fncts.Array updateAt
48
+ * @tsplus pipeable fncts.ReadonlyArray updateAt
49
+ * @tsplus location "@fncts/base/collection/compat/Array/api"
50
+ */
51
+ export declare function updateAt<A>(i: number, a: A): (self: ReadonlyArray<A>) => ReadonlyArray<A>;
@@ -15,6 +15,21 @@ export declare function foldLeftWithIndex<A, B>(b: B, f: (k: string, b: B, a: A)
15
15
  * @tsplus location "@fncts/base/collection/immutable/Dictionary/api"
16
16
  */
17
17
  export declare function get(key: string): <A>(self: import("./definition").Dictionary<A>) => import("../../../data/Maybe").Maybe<A>;
18
+ /**
19
+ * @tsplus pipeable fncts.Dictionary set
20
+ * @tsplus location "@fncts/base/collection/immutable/Dictionary/api"
21
+ */
22
+ export declare function set<A>(key: string, value: A): (self: Dictionary<A>) => Dictionary<A>;
23
+ /**
24
+ * @tsplus pipeable fncts.Dictionary remove
25
+ * @tsplus location "@fncts/base/collection/immutable/Dictionary/api"
26
+ */
27
+ export declare function remove(key: string): <A>(self: import("./definition").Dictionary<A>) => import("./definition").Dictionary<A>;
28
+ /**
29
+ * @tsplus pipeable fncts.Dictionary update
30
+ * @tsplus location "@fncts/base/collection/immutable/Dictionary/api"
31
+ */
32
+ export declare function update<A>(key: string, f: (a: Maybe<A>) => Maybe<A>): (self: Dictionary<A>) => Dictionary<A>;
18
33
  /**
19
34
  * @tsplus getter fncts.Dictionary keys
20
35
  * @tsplus location "@fncts/base/collection/immutable/Dictionary/api"
@@ -30,6 +45,12 @@ export declare function map<A, B>(f: (a: A) => B): (self: Dictionary<A>) => Dict
30
45
  * @tsplus location "@fncts/base/collection/immutable/Dictionary/api"
31
46
  */
32
47
  export declare function mapWithIndex<A, B>(f: (k: string, a: A) => B): (self: Dictionary<A>) => Dictionary<B>;
48
+ /**
49
+ * @tsplus static fncts.DictionaryOps __call
50
+ * @tsplus macro identity
51
+ * @tsplus location "@fncts/base/collection/immutable/Dictionary/api"
52
+ */
53
+ export declare function fromRecord<A>(self: Record<string, A>): Dictionary<A>;
33
54
  /**
34
55
  * @tsplus getter fncts.Dictionary toRecord
35
56
  * @tsplus macro identity