@fncts/base 0.0.18 → 0.0.20

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 (69) hide show
  1. package/_cjs/collection/compat/Record/instances.cjs +1 -1
  2. package/_cjs/collection/weak/IterableWeakMap.cjs +7 -1
  3. package/_cjs/collection/weak/IterableWeakMap.cjs.map +1 -1
  4. package/_cjs/data/Branded/definition.cjs +10 -9
  5. package/_cjs/data/Branded/definition.cjs.map +1 -1
  6. package/_cjs/data/Decoder/api.cjs.map +1 -1
  7. package/_cjs/data/Decoder/definition.cjs +1 -0
  8. package/_cjs/data/Decoder/definition.cjs.map +1 -1
  9. package/_cjs/data/Environment/definition.cjs.map +1 -1
  10. package/_cjs/data/{Patch/api.cjs → EnvironmentPatch.cjs} +124 -32
  11. package/_cjs/data/EnvironmentPatch.cjs.map +1 -0
  12. package/_mjs/collection/compat/Record/instances.mjs +1 -1
  13. package/_mjs/collection/weak/IterableWeakMap.mjs +3 -1
  14. package/_mjs/collection/weak/IterableWeakMap.mjs.map +1 -1
  15. package/_mjs/data/Branded/definition.mjs +7 -6
  16. package/_mjs/data/Branded/definition.mjs.map +1 -1
  17. package/_mjs/data/Decoder/api.mjs.map +1 -1
  18. package/_mjs/data/Decoder/definition.mjs +1 -0
  19. package/_mjs/data/Decoder/definition.mjs.map +1 -1
  20. package/_mjs/data/Environment/definition.mjs.map +1 -1
  21. package/_mjs/data/EnvironmentPatch.mjs +184 -0
  22. package/_mjs/data/EnvironmentPatch.mjs.map +1 -0
  23. package/_src/collection/weak/IterableWeakMap.ts +1 -1
  24. package/_src/data/Branded/definition.ts +27 -24
  25. package/_src/data/Branded/derivations.ts +10 -10
  26. package/_src/data/Decoder/api.ts +1 -1
  27. package/_src/data/Decoder/definition.ts +2 -2
  28. package/_src/data/Environment/definition.ts +6 -0
  29. package/_src/data/EnvironmentPatch.ts +136 -0
  30. package/_src/data.ts +1 -1
  31. package/_src/global.ts +5 -1
  32. package/collection/compat/Array/derivations.d.ts +1 -1
  33. package/collection/compat/Record/instances.d.ts +1 -1
  34. package/collection/immutable/Conc/derivations.d.ts +1 -1
  35. package/collection/immutable/ImmutableArray/derivations.d.ts +1 -1
  36. package/collection/immutable/ImmutableNonEmptyArray/derivations.d.ts +1 -1
  37. package/collection/weak/IterableWeakMap.d.ts +1 -1
  38. package/data/Branded/definition.d.ts +25 -22
  39. package/data/Branded/derivations.d.ts +7 -7
  40. package/data/Decoder/api.d.ts +1 -1
  41. package/data/Decoder/definition.d.ts +2 -2
  42. package/data/Either/instances.d.ts +1 -1
  43. package/data/Environment/definition.d.ts +4 -0
  44. package/data/EnvironmentPatch.d.ts +73 -0
  45. package/data/Maybe/instances.d.ts +1 -1
  46. package/data/These/instances.d.ts +1 -1
  47. package/data.d.ts +1 -1
  48. package/global.d.ts +5 -1
  49. package/json/EitherJson.d.ts +1 -1
  50. package/json/MaybeJson.d.ts +1 -1
  51. package/json/TheseJson.d.ts +1 -1
  52. package/package.json +2 -2
  53. package/_cjs/data/Patch/api.cjs.map +0 -1
  54. package/_cjs/data/Patch/definition.cjs +0 -88
  55. package/_cjs/data/Patch/definition.cjs.map +0 -1
  56. package/_cjs/data/Patch.cjs +0 -32
  57. package/_cjs/data/Patch.cjs.map +0 -1
  58. package/_mjs/data/Patch/api.mjs +0 -112
  59. package/_mjs/data/Patch/api.mjs.map +0 -1
  60. package/_mjs/data/Patch/definition.mjs +0 -61
  61. package/_mjs/data/Patch/definition.mjs.map +0 -1
  62. package/_mjs/data/Patch.mjs +0 -4
  63. package/_mjs/data/Patch.mjs.map +0 -1
  64. package/_src/data/Patch/api.ts +0 -75
  65. package/_src/data/Patch/definition.ts +0 -58
  66. package/_src/data/Patch.ts +0 -4
  67. package/data/Patch/api.d.ts +0 -24
  68. package/data/Patch/definition.d.ts +0 -44
  69. package/data/Patch.d.ts +0 -2
@@ -0,0 +1,184 @@
1
+ import * as tsplus_module_1 from "@fncts/base/collection/immutable/List/definition";
2
+ import * as tsplus_module_2 from "@fncts/base/data/Environment/api";
3
+ import * as tsplus_module_3 from "@fncts/base/collection/immutable/List/constructors";
4
+ import * as tsplus_module_4 from "@fncts/base/collection/immutable/HashMap/api";
5
+ import * as tsplus_module_5 from "@fncts/base/data/Maybe/destructors";
6
+ import * as tsplus_module_6 from "@fncts/base/collection/compat/Array/api";
7
+ export const combine = combine_1;
8
+ export const empty = empty_1;
9
+ export const EnvironmentPatchTypeId = /*#__PURE__*/Symbol.for("fncts.Environment.Patch");
10
+ /**
11
+ * @tsplus type fncts.Environment.Patch
12
+ * @tsplus companion fncts.Environment.PatchOps
13
+ */
14
+
15
+ export class EnvironmentPatch {
16
+ constructor() {
17
+ this._typeId = EnvironmentPatchTypeId;
18
+ }
19
+
20
+ }
21
+ export class AddService extends EnvironmentPatch {
22
+ constructor(service, tag) {
23
+ super();
24
+ this.service = service;
25
+ this.tag = tag;
26
+ this._tag = 0
27
+ /* EnvironmentPatchTag.AddService */
28
+ ;
29
+ }
30
+
31
+ }
32
+ export class Combine extends EnvironmentPatch {
33
+ constructor(first, second) {
34
+ super();
35
+ this.first = first;
36
+ this.second = second;
37
+ this._tag = 3
38
+ /* EnvironmentPatchTag.Combine */
39
+ ;
40
+ }
41
+
42
+ }
43
+ export class Empty extends EnvironmentPatch {
44
+ constructor() {
45
+ super(...arguments);
46
+ this._tag = 4
47
+ /* EnvironmentPatchTag.Empty */
48
+ ;
49
+ }
50
+
51
+ }
52
+ export class RemoveService extends EnvironmentPatch {
53
+ constructor(tag) {
54
+ super();
55
+ this.tag = tag;
56
+ this._tag = 1
57
+ /* EnvironmentPatchTag.RemoveService */
58
+ ;
59
+ }
60
+
61
+ }
62
+ export class UpdateService extends EnvironmentPatch {
63
+ constructor(update, tag) {
64
+ super();
65
+ this.update = update;
66
+ this.tag = tag;
67
+ this._tag = 2
68
+ /* EnvironmentPatchTag.UpdateService */
69
+ ;
70
+ }
71
+
72
+ }
73
+ /**
74
+ * @tsplus macro remove
75
+ */
76
+
77
+ export function concrete(_) {//
78
+ }
79
+ /**
80
+ * @tsplus tailRec
81
+ */
82
+
83
+ function applyLoop(environment, patches) {
84
+ var environment_1 = environment,
85
+ patches_1 = patches;
86
+ var environment_2 = environment,
87
+ patches_2 = patches;
88
+
89
+ while (1) {
90
+ if (tsplus_module_1.isEmpty(patches_1)) {
91
+ return environment_1;
92
+ }
93
+
94
+ const head = patches_1.head;
95
+ const tail = patches_1.tail;
96
+ void 0;
97
+
98
+ switch (head._tag) {
99
+ case 0
100
+ /* EnvironmentPatchTag.AddService */
101
+ :
102
+ environment_2 = tsplus_module_2.add(environment_1, head.service, head.tag);
103
+ patches_2 = tail;
104
+ environment_1 = environment_2;
105
+ patches_1 = patches_2;
106
+ continue;
107
+
108
+ case 3
109
+ /* EnvironmentPatchTag.Combine */
110
+ :
111
+ environment_2 = environment_1;
112
+ patches_2 = tsplus_module_3.cons(head.first, tsplus_module_3.cons(head.second, tail));
113
+ environment_1 = environment_2;
114
+ patches_1 = patches_2;
115
+ continue;
116
+
117
+ case 4
118
+ /* EnvironmentPatchTag.Empty */
119
+ :
120
+ environment_2 = environment_1;
121
+ patches_2 = tail;
122
+ environment_1 = environment_2;
123
+ patches_1 = patches_2;
124
+ continue;
125
+
126
+ case 1
127
+ /* EnvironmentPatchTag.RemoveService */
128
+ :
129
+ environment_2 = environment_1;
130
+ patches_2 = tail;
131
+ environment_1 = environment_2;
132
+ patches_1 = patches_2;
133
+ continue;
134
+
135
+ case 2
136
+ /* EnvironmentPatchTag.UpdateService */
137
+ :
138
+ environment_2 = tsplus_module_2.update(environment_1, head.update, head.tag);
139
+ patches_2 = tail;
140
+ environment_1 = environment_2;
141
+ patches_1 = patches_2;
142
+ continue;
143
+ }
144
+ }
145
+ }
146
+ /**
147
+ * @tsplus fluent fncts.Environment.Patch __call
148
+ */
149
+
150
+
151
+ export function apply(patch, environment) {
152
+ return applyLoop(environment, tsplus_module_3.cons(patch));
153
+ }
154
+ /**
155
+ * @tsplus fluent fncts.Environment.Patch combine
156
+ */
157
+
158
+ function combine_1(self, that) {
159
+ return new Combine(self, that);
160
+ }
161
+ /**
162
+ * @tsplus static fncts.Environment.PatchOps diff
163
+ */
164
+
165
+
166
+ export function diff(oldValue, newValue) {
167
+ const sorted = tsplus_module_4.toArray(newValue.map);
168
+ const [missingServices, patch] = tsplus_module_6.foldLeft(sorted, [tsplus_module_4.beginMutation(oldValue.map), empty_1()], ([map, patch], [tag, newService]) => tsplus_module_5.match_(tsplus_module_4.get_(map, tag), () => [tsplus_module_4.remove_(map, tag), combine_1(patch, new AddService(newService, tag))], oldService => {
169
+ if (oldService === newService) {
170
+ return [tsplus_module_4.remove_(map, tag), patch];
171
+ } else {
172
+ return [tsplus_module_4.remove_(map, tag), combine_1(patch, new UpdateService(_ => newService, tag))];
173
+ }
174
+ }));
175
+ return tsplus_module_4.foldLeftWithIndex_(missingServices, patch, (tag, patch) => combine_1(patch, new RemoveService(tag)));
176
+ }
177
+ /**
178
+ * @tsplus static fncts.Environment.PatchOps empty
179
+ */
180
+
181
+ function empty_1() {
182
+ return new Empty();
183
+ }
184
+ //# sourceMappingURL=EnvironmentPatch.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EnvironmentPatch.mjs","mappings":";;;;;;aAqGgBA,OAAO;aAgCPC,KAAK;AA7HrB,OAAO,MAAMC,sBAAsB,gBAAGC,MAAM,CAACC,GAAP,CAAW,yBAAX,CAA/B;AAGP;;;;;AAIA,OAAM,MAAgBC,gBAAhB,CAAgC;EAAtCC;IACW,eAAkCJ,sBAAlC;EAGV;;AAJqC;AAMtC,OAAM,MAAOK,UAAP,SAAwCF,gBAAxC,CAAiF;EAErFC,YAAqBE,OAArB,EAAgDC,GAAhD,EAAiE;IAC/D;IADmB;IAA2B;IADvC,YAAI;IAAA;IAAJ;EAGR;;AAJoF;AAOvF,OAAM,MAAOC,OAAP,SAAsCL,gBAAtC,CAAgE;EAEpEC,YAAqBK,KAArB,EAAgEC,MAAhE,EAAmG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constructor","AddService","service","tag","Combine","first","second","Empty","RemoveService","UpdateService","update","concrete","_","applyLoop","environment","patches","patches_1","patches_2","tsplus_module_1","head","tail","_tag","tsplus_module_2","tsplus_module_3","apply","patch","self","that","diff","oldValue","newValue","sorted","map","missingServices","tsplus_module_6","empty_1","newService","tsplus_module_5","tsplus_module_4","combine_1","oldService"],"sourceRoot":"","sources":["../../_src/data/EnvironmentPatch.ts"],"sourcesContent":[null]}
@@ -12,7 +12,7 @@ export class IterableWeakMap<K extends object, V> implements Iterable<readonly [
12
12
  set.delete(ref);
13
13
  }
14
14
 
15
- constructor(iterable: Iterable<readonly [K, V]>) {
15
+ constructor(iterable: Iterable<readonly [K, V]> = Iterable.empty()) {
16
16
  for (const [key, value] of iterable) {
17
17
  this.set(key, value);
18
18
  }
@@ -1,51 +1,54 @@
1
1
  import type { Union } from "@fncts/typelevel";
2
2
 
3
- type Brand_<A, K extends string> = Brand<A, K>;
3
+ declare const validSym: unique symbol;
4
4
 
5
- export declare namespace Branded {
6
- const Symbol: unique symbol;
7
- export type Symbol = typeof Symbol;
5
+ export declare namespace Brand {
6
+ export type valid = typeof validSym;
8
7
 
9
- export interface Brand<A, K extends string> {
10
- readonly [Branded.Symbol]: {
8
+ /**
9
+ * @tsplus derive nominal
10
+ */
11
+ export interface Valid<in out A, in out K extends string> {
12
+ [validSym]: {
11
13
  [_ in K]: A;
12
14
  };
13
15
  }
14
16
 
15
- export type Type<A extends Brand_<any, any>> = [A] extends [Brand_<infer A, infer K>] ? Validated<A, K> : never;
17
+ export type Type<A extends Validation<any, any>> = A extends Validation<infer A, infer K> ? Validated<A, K> : never;
16
18
 
17
- export type Validated<A, K extends string> = A & Brand<A, K>;
19
+ export type Validated<A, K extends string> = A & Brand.Valid<A, K>;
18
20
 
19
- export type IsValidated<P extends Brand<any, any>> = {
20
- [K in keyof P[Branded.Symbol]]: P extends P[Branded.Symbol][K] ? 0 : 1;
21
- }[keyof P[Branded.Symbol]] extends 0
21
+ export type IsValidated<P extends Valid<any, any>> = {
22
+ [K in keyof P[Brand.valid]]: P extends P[Brand.valid][K] ? 0 : 1;
23
+ }[keyof P[Brand.valid]] extends 0
22
24
  ? unknown
23
25
  : never;
24
26
 
25
- export type Unbrand<P extends Brand<any, any>> = P extends infer Q & Brands<P> ? Q : P;
27
+ export type Unbranded<P> = P extends infer Q & Brands<P> ? Q : P;
26
28
 
27
- export type Brands<P extends Brand<any, any>> = Union.IntersectionOf<
29
+ export type Brands<P> = P extends Valid<any, any> ? Union.IntersectionOf<
28
30
  {
29
- [K in keyof P[Branded.Symbol]]: P extends P[Branded.Symbol][K]
31
+ [K in keyof P[Brand.valid]]: P extends P[Brand.valid][K]
30
32
  ? K extends string
31
- ? Brand<P[Branded.Symbol][K], K>
33
+ ? Valid<P[Brand.valid][K], K>
32
34
  : never
33
35
  : never;
34
- }[keyof P[Branded.Symbol]]
35
- >;
36
+ }[keyof P[Brand.valid]]
37
+ > : unknown;
36
38
  }
37
39
 
38
40
  /**
39
- * @tsplus type fncts.Brand
40
- * @tsplus companion fncts.BrandOps
41
+ * @tsplus type fncts.Validation
42
+ * @tsplus companion fncts.ValidationOps
43
+ * @tsplus derive nominal
41
44
  */
42
- export class Brand<A, K extends string> {
43
- constructor(readonly validate: Refinement<A, A & Branded.Brand<A, K>>) {}
45
+ export class Validation<in out A, in out K extends string> {
46
+ constructor(readonly validate: Refinement<A, A & Brand.Valid<A, K>>) {}
44
47
  }
45
48
 
46
49
  /**
47
- * @tsplus static fncts.BrandOps __call
50
+ * @tsplus static fncts.ValidationOps __call
48
51
  */
49
- export function makeBrand<A, K extends string>(p: Predicate<A>): Brand<A, K> {
50
- return new Brand(p as Refinement<A, A & Branded.Brand<A, K>>);
52
+ export function makeValidation<A, K extends string>(p: Predicate<A>): Validation<A, K> {
53
+ return new Validation(p as Refinement<A, A & Brand.Valid<A, K>>);
51
54
  }
@@ -1,4 +1,4 @@
1
- import type { Brand, Branded } from "@fncts/base/data/Branded/definition";
1
+ import type { Validation, Brand } from "@fncts/base/data/Branded/definition";
2
2
  import type { Check } from "@fncts/typelevel/Check";
3
3
 
4
4
  import { BrandedError, CompoundError } from "@fncts/base/data/DecodeError";
@@ -7,29 +7,29 @@ import { Decoder } from "@fncts/base/data/Decoder/definition";
7
7
  /**
8
8
  * @tsplus derive fncts.Guard<_> 10
9
9
  */
10
- export function deriveGuard<A extends Branded.Brand<any, any>>(
11
- ...[base, brands]: Check<Branded.IsValidated<A>> extends Check.True
10
+ export function deriveGuard<A extends Brand.Valid<any, any>>(
11
+ ...[base, brands]: Check<Brand.IsValidated<A>> extends Check.True
12
12
  ? [
13
- base: Guard<Branded.Unbrand<A>>,
13
+ base: Guard<Brand.Unbranded<A>>,
14
14
  brands: {
15
- [K in keyof A[Branded.Symbol] & string]: Brand<A[Branded.Symbol][K], K>;
15
+ [K in keyof A[Brand.valid] & string]: Validation<A[Brand.valid][K], K>;
16
16
  },
17
17
  ]
18
18
  : never
19
19
  ): Guard<A> {
20
- const validations = Object.values(brands) as ReadonlyArray<Brand<A, any>>;
20
+ const validations = Object.values(brands) as ReadonlyArray<Validation<A, any>>;
21
21
  return Guard((u): u is A => base.is(u) && validations.every((brand) => brand.validate(u)));
22
22
  }
23
23
 
24
24
  /**
25
25
  * @tsplus derive fncts.Decoder<_> 10
26
26
  */
27
- export function deriveDecoder<A extends Branded.Brand<any, any>>(
28
- ...[base, brands]: Check<Branded.IsValidated<A>> extends Check.True
27
+ export function deriveDecoder<A extends Brand.Valid<any, any>>(
28
+ ...[base, brands]: Check<Brand.IsValidated<A>> extends Check.True
29
29
  ? [
30
- base: Decoder<Branded.Unbrand<A>>,
30
+ base: Decoder<Brand.Unbranded<A>>,
31
31
  brands: {
32
- [K in keyof A[Branded.Symbol] & string]: Brand<A[Branded.Symbol][K], K>;
32
+ [K in (keyof A[Brand.valid]) & string]: Validation<A[Brand.valid][K], K>;
33
33
  },
34
34
  ]
35
35
  : never
@@ -17,7 +17,7 @@ import { Decoder } from "@fncts/base/data/Decoder/definition";
17
17
  /**
18
18
  * @tsplus fluent fncts.Decoder __call
19
19
  */
20
- export function decode<I, E, A>(self: Decoder<A>, input: unknown): These<DecodeError, A> {
20
+ export function decode<A>(self: Decoder<A>, input: unknown): These<DecodeError, A> {
21
21
  return self.decode(input);
22
22
  }
23
23
 
@@ -13,10 +13,10 @@ export interface DecoderF extends HKT {
13
13
  /**
14
14
  * @tsplus type fncts.Decoder
15
15
  * @tsplus companion fncts.DecoderOps
16
+ * @tsplus derive nominal
16
17
  */
17
- export class Decoder<A> {
18
+ export class Decoder<in out A> {
18
19
  readonly _typeId: DecoderTypeId = DecoderTypeId;
19
- readonly _A!: () => A;
20
20
  constructor(readonly decode: (input: unknown) => These<DecodeError, A>, readonly label: string) {}
21
21
  }
22
22
 
@@ -1,3 +1,5 @@
1
+ import type { EnvironmentPatch } from "@fncts/base/data/EnvironmentPatch";
2
+
1
3
  /**
2
4
  * @tsplus static fncts.prelude.builtin.SymbolOps env
3
5
  */
@@ -26,6 +28,10 @@ export class Environment<R> implements Hashable, Equatable {
26
28
  }
27
29
  }
28
30
 
31
+ export declare namespace Environment {
32
+ type Patch<In, Out> = EnvironmentPatch<In, Out>;
33
+ }
34
+
29
35
  export function isEnvironment(u: unknown): u is Environment<unknown> {
30
36
  return hasTypeId(u, EnvSymbol);
31
37
  }
@@ -0,0 +1,136 @@
1
+ export const enum EnvironmentPatchTag {
2
+ AddService,
3
+ RemoveService,
4
+ UpdateService,
5
+ Combine,
6
+ Empty,
7
+ }
8
+
9
+ export const EnvironmentPatchTypeId = Symbol.for("fncts.Environment.Patch");
10
+ export type EnvironmentPatchTypeId = typeof EnvironmentPatchTypeId;
11
+
12
+ /**
13
+ * @tsplus type fncts.Environment.Patch
14
+ * @tsplus companion fncts.Environment.PatchOps
15
+ */
16
+ export abstract class EnvironmentPatch<In, Out> {
17
+ readonly _typeId: EnvironmentPatchTypeId = EnvironmentPatchTypeId;
18
+ readonly _R!: (_: In) => void;
19
+ readonly _A!: () => Out;
20
+ }
21
+
22
+ export class AddService<Env, Service> extends EnvironmentPatch<Env, Env & Has<Service>> {
23
+ readonly _tag = EnvironmentPatchTag.AddService;
24
+ constructor(readonly service: Service, readonly tag: Tag<Service>) {
25
+ super();
26
+ }
27
+ }
28
+
29
+ export class Combine<In, Out, Out2> extends EnvironmentPatch<In, Out2> {
30
+ readonly _tag = EnvironmentPatchTag.Combine;
31
+ constructor(readonly first: EnvironmentPatch<In, Out>, readonly second: EnvironmentPatch<Out, Out2>) {
32
+ super();
33
+ }
34
+ }
35
+
36
+ export class Empty<Env> extends EnvironmentPatch<Env, Env> {
37
+ readonly _tag = EnvironmentPatchTag.Empty;
38
+ }
39
+
40
+ export class RemoveService<Env, Service> extends EnvironmentPatch<Env & Has<Service>, Env> {
41
+ readonly _tag = EnvironmentPatchTag.RemoveService;
42
+ constructor(readonly tag: Tag<Service>) {
43
+ super();
44
+ }
45
+ }
46
+
47
+ export class UpdateService<Env, Service> extends EnvironmentPatch<Env & Has<Service>, Env & Has<Service>> {
48
+ readonly _tag = EnvironmentPatchTag.UpdateService;
49
+ constructor(readonly update: (_: Service) => Service, readonly tag: Tag<Service>) {
50
+ super();
51
+ }
52
+ }
53
+
54
+ export type Concrete =
55
+ | AddService<any, any>
56
+ | Combine<any, any, any>
57
+ | Empty<any>
58
+ | RemoveService<any, any>
59
+ | UpdateService<any, any>;
60
+
61
+ /**
62
+ * @tsplus macro remove
63
+ */
64
+ export function concrete(_: EnvironmentPatch<any, any>): asserts _ is Concrete {
65
+ //
66
+ }
67
+
68
+ /**
69
+ * @tsplus tailRec
70
+ */
71
+ function applyLoop(environment: Environment<any>, patches: List<EnvironmentPatch<any, any>>): Environment<any> {
72
+ if (patches.isEmpty()) {
73
+ return environment;
74
+ }
75
+ const head = patches.head;
76
+ const tail = patches.tail;
77
+ concrete(head);
78
+ switch (head._tag) {
79
+ case EnvironmentPatchTag.AddService:
80
+ return applyLoop(environment.add(head.service, head.tag), tail);
81
+ case EnvironmentPatchTag.Combine:
82
+ return applyLoop(environment, Cons(head.first, Cons(head.second, tail)));
83
+ case EnvironmentPatchTag.Empty:
84
+ return applyLoop(environment, tail);
85
+ case EnvironmentPatchTag.RemoveService:
86
+ return applyLoop(environment, tail);
87
+ case EnvironmentPatchTag.UpdateService:
88
+ return applyLoop(environment.update(head.update, head.tag), tail);
89
+ }
90
+ }
91
+
92
+ /**
93
+ * @tsplus fluent fncts.Environment.Patch __call
94
+ */
95
+ export function apply<In, Out>(patch: EnvironmentPatch<In, Out>, environment: Environment<In>): Environment<Out> {
96
+ return applyLoop(environment, Cons(patch));
97
+ }
98
+
99
+ /**
100
+ * @tsplus fluent fncts.Environment.Patch combine
101
+ */
102
+ export function combine<In, Out, Out2>(
103
+ self: EnvironmentPatch<In, Out>,
104
+ that: EnvironmentPatch<Out, Out2>,
105
+ ): EnvironmentPatch<In, Out2> {
106
+ return new Combine(self, that);
107
+ }
108
+
109
+ /**
110
+ * @tsplus static fncts.Environment.PatchOps diff
111
+ */
112
+ export function diff<In, Out>(oldValue: Environment<In>, newValue: Environment<Out>): EnvironmentPatch<In, Out> {
113
+ const sorted = newValue.map.toArray;
114
+ const [missingServices, patch] = sorted.foldLeft(
115
+ [oldValue.map.beginMutation, EnvironmentPatch.empty() as EnvironmentPatch<any, any>],
116
+ ([map, patch], [tag, newService]) =>
117
+ map.get(tag).match(
118
+ () => [map.remove(tag), patch.combine(new AddService(newService, tag))],
119
+ (oldService) => {
120
+ if (oldService === newService) {
121
+ return [map.remove(tag), patch];
122
+ } else {
123
+ return [map.remove(tag), patch.combine(new UpdateService((_: any) => newService, tag))];
124
+ }
125
+ },
126
+ ),
127
+ );
128
+ return missingServices.foldLeftWithIndex(patch, (tag, patch) => patch.combine(new RemoveService(tag)));
129
+ }
130
+
131
+ /**
132
+ * @tsplus static fncts.Environment.PatchOps empty
133
+ */
134
+ export function empty<A>(): EnvironmentPatch<A, A> {
135
+ return new Empty();
136
+ }
package/_src/data.ts CHANGED
@@ -11,6 +11,7 @@ export type {} from "./data/Decoder.js";
11
11
  export type {} from "./data/Duration.js";
12
12
  export type {} from "./data/Either.js";
13
13
  export type {} from "./data/Environment.js";
14
+ export type {} from "./data/EnvironmentPatch.js";
14
15
  export type {} from "./data/exceptions.js";
15
16
  export type {} from "./data/ExecutionStrategy.js";
16
17
  export type {} from "./data/Exit.js";
@@ -23,7 +24,6 @@ export type {} from "./data/Maybe.js";
23
24
  export type {} from "./data/Newtype.js";
24
25
  export type {} from "./data/number.js";
25
26
  export type {} from "./data/object.js";
26
- export type {} from "./data/Patch.js";
27
27
  export type {} from "./data/Predicate.js";
28
28
  export type {} from "./data/Refinement.js";
29
29
  export type {} from "./data/string.js";
package/_src/global.ts CHANGED
@@ -110,7 +110,7 @@ import { DatumEither } from "@fncts/base/data/DatumEither/definition";
110
110
  /**
111
111
  * @tsplus global
112
112
  */
113
- import { Decoder } from "@fncts/base/data/Decoder";
113
+ import { Decoder } from "@fncts/base/data/Decoder/definition";
114
114
  /**
115
115
  * @tsplus global
116
116
  */
@@ -123,6 +123,10 @@ import { Either } from "@fncts/base/data/Either/definition";
123
123
  * @tsplus global
124
124
  */
125
125
  import { Environment } from "@fncts/base/data/Environment/definition";
126
+ /**
127
+ * @tsplus global
128
+ */
129
+ import { EnvironmentPatch } from "@fncts/base/data/EnvironmentPatch";
126
130
  /**
127
131
  * @tsplus global
128
132
  */
@@ -1,5 +1,5 @@
1
1
  import { Guard } from "@fncts/base/typeclass/Guard";
2
- import { Decoder } from "@fncts/base/data/Decoder";
2
+ import { Decoder } from "@fncts/base/data/Decoder/definition";
3
3
  import { These } from "@fncts/base/data/These";
4
4
  import type { Check } from "@fncts/typelevel/Check";
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import { Guard } from "@fncts/base/typeclass/Guard";
2
- import { Decoder } from "@fncts/base/data/Decoder";
2
+ import { Decoder } from "@fncts/base/data/Decoder/definition";
3
3
  import type { Check } from "@fncts/typelevel/Check";
4
4
  /**
5
5
  * @tsplus derive fncts.Guard<_> 15
@@ -1,6 +1,6 @@
1
1
  import { Conc } from "@fncts/base/collection/immutable/Conc";
2
2
  import { Guard } from "@fncts/base/typeclass/Guard";
3
- import { Decoder } from "@fncts/base/data/Decoder";
3
+ import { Decoder } from "@fncts/base/data/Decoder/definition";
4
4
  import type { Check } from "@fncts/typelevel/Check";
5
5
  /**
6
6
  * @tsplus derive fncts.Guard[fncts.Conc]<_> 10
@@ -1,6 +1,6 @@
1
1
  import { ImmutableArray } from "@fncts/base/collection/immutable/ImmutableArray/definition";
2
2
  import { Guard } from "@fncts/base/typeclass/Guard";
3
- import { Decoder } from "@fncts/base/data/Decoder";
3
+ import { Decoder } from "@fncts/base/data/Decoder/definition";
4
4
  import type { Check } from "@fncts/typelevel/Check";
5
5
  /**
6
6
  * @tsplus derive fncts.Guard[fncts.ImmutableArray]<_> 10
@@ -1,6 +1,6 @@
1
1
  import { ImmutableNonEmptyArray } from "@fncts/base/collection/immutable/ImmutableNonEmptyArray/definition";
2
2
  import { Guard } from "@fncts/base/typeclass/Guard";
3
- import { Decoder } from "@fncts/base/data/Decoder";
3
+ import { Decoder } from "@fncts/base/data/Decoder/definition";
4
4
  import type { Check } from "@fncts/typelevel/Check";
5
5
  /**
6
6
  * @tsplus derive fncts.Guard[fncts.ImmutableNonEmptyArray]<_> 10
@@ -6,7 +6,7 @@ export declare class IterableWeakMap<K extends object, V> implements Iterable<re
6
6
  private refSet;
7
7
  private finalizationGroup;
8
8
  private static cleanup;
9
- constructor(iterable: Iterable<readonly [K, V]>);
9
+ constructor(iterable?: Iterable<readonly [K, V]>);
10
10
  set(this: this, key: K, value: V): this;
11
11
  get(this: this, key: K): V | undefined;
12
12
  delete(this: this, key: K): boolean;
@@ -1,36 +1,39 @@
1
1
  import { Refinement } from "@fncts/base/data/Refinement/definition";
2
2
  import { Predicate } from "@fncts/base/data/Predicate/definition";
3
3
  import type { Union } from "@fncts/typelevel";
4
- type Brand_<A, K extends string> = Brand<A, K>;
5
- export declare namespace Branded {
6
- const Symbol: unique symbol;
7
- type Symbol = typeof Symbol;
8
- interface Brand<A, K extends string> {
9
- readonly [Branded.Symbol]: {
4
+ declare const validSym: unique symbol;
5
+ export declare namespace Brand {
6
+ type valid = typeof validSym;
7
+ /**
8
+ * @tsplus derive nominal
9
+ */
10
+ interface Valid<in out A, in out K extends string> {
11
+ [validSym]: {
10
12
  [_ in K]: A;
11
13
  };
12
14
  }
13
- type Type<A extends Brand_<any, any>> = [A] extends [Brand_<infer A, infer K>] ? Validated<A, K> : never;
14
- type Validated<A, K extends string> = A & Brand<A, K>;
15
- type IsValidated<P extends Brand<any, any>> = {
16
- [K in keyof P[Branded.Symbol]]: P extends P[Branded.Symbol][K] ? 0 : 1;
17
- }[keyof P[Branded.Symbol]] extends 0 ? unknown : never;
18
- type Unbrand<P extends Brand<any, any>> = P extends infer Q & Brands<P> ? Q : P;
19
- type Brands<P extends Brand<any, any>> = Union.IntersectionOf<{
20
- [K in keyof P[Branded.Symbol]]: P extends P[Branded.Symbol][K] ? K extends string ? Brand<P[Branded.Symbol][K], K> : never : never;
21
- }[keyof P[Branded.Symbol]]>;
15
+ type Type<A extends Validation<any, any>> = A extends Validation<infer A, infer K> ? Validated<A, K> : never;
16
+ type Validated<A, K extends string> = A & Brand.Valid<A, K>;
17
+ type IsValidated<P extends Valid<any, any>> = {
18
+ [K in keyof P[Brand.valid]]: P extends P[Brand.valid][K] ? 0 : 1;
19
+ }[keyof P[Brand.valid]] extends 0 ? unknown : never;
20
+ type Unbranded<P> = P extends infer Q & Brands<P> ? Q : P;
21
+ type Brands<P> = P extends Valid<any, any> ? Union.IntersectionOf<{
22
+ [K in keyof P[Brand.valid]]: P extends P[Brand.valid][K] ? K extends string ? Valid<P[Brand.valid][K], K> : never : never;
23
+ }[keyof P[Brand.valid]]> : unknown;
22
24
  }
23
25
  /**
24
- * @tsplus type fncts.Brand
25
- * @tsplus companion fncts.BrandOps
26
+ * @tsplus type fncts.Validation
27
+ * @tsplus companion fncts.ValidationOps
28
+ * @tsplus derive nominal
26
29
  */
27
- export declare class Brand<A, K extends string> {
28
- readonly validate: Refinement<A, A & Branded.Brand<A, K>>;
29
- constructor(validate: Refinement<A, A & Branded.Brand<A, K>>);
30
+ export declare class Validation<in out A, in out K extends string> {
31
+ readonly validate: Refinement<A, A & Brand.Valid<A, K>>;
32
+ constructor(validate: Refinement<A, A & Brand.Valid<A, K>>);
30
33
  }
31
34
  /**
32
- * @tsplus static fncts.BrandOps __call
35
+ * @tsplus static fncts.ValidationOps __call
33
36
  * @tsplus location "@fncts/base/data/Branded/definition"
34
37
  */
35
- export declare function makeBrand<A, K extends string>(p: Predicate<A>): Brand<A, K>;
38
+ export declare function makeValidation<A, K extends string>(p: Predicate<A>): Validation<A, K>;
36
39
  export {};