effect-lens 0.1.3 → 0.1.5
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/README.md +18 -18
- package/dist/Lens.d.ts +12 -12
- package/dist/Lens.js +3 -3
- package/dist/Lens.js.map +1 -1
- package/dist/Subscribable.d.ts +16 -2
- package/dist/Subscribable.js +13 -2
- package/dist/Subscribable.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -5
- package/dist/PropertyPath.d.ts +0 -23
- package/dist/PropertyPath.js +0 -30
- package/dist/PropertyPath.js.map +0 -1
package/README.md
CHANGED
|
@@ -36,13 +36,13 @@ Lens<
|
|
|
36
36
|
|
|
37
37
|
### Creating a Lens
|
|
38
38
|
|
|
39
|
-
#### From an
|
|
39
|
+
#### From an existing type
|
|
40
40
|
We provide a few helpers to create Lenses from some Effect types:
|
|
41
41
|
```typescript
|
|
42
42
|
// The ref is the data source
|
|
43
43
|
const ref = yield* SubscriptionRef.make([12, 87, 69])
|
|
44
44
|
|
|
45
|
-
// The lens acts as a proxy that allows reading, subscribing
|
|
45
|
+
// The lens acts as a proxy that allows reading, subscribing to and writing to that
|
|
46
46
|
// data source with a similar API to Effect's SubscriptionRef
|
|
47
47
|
const lens = Lens.fromSubscriptionRef(ref)
|
|
48
48
|
// ^ Lens.Lens<number[], never, never, never, never>
|
|
@@ -54,7 +54,7 @@ yield* Lens.update(lens, Array.replace(1, 1664))
|
|
|
54
54
|
|
|
55
55
|
Currently available:
|
|
56
56
|
- `fromSubscriptionRef`
|
|
57
|
-
- `fromSynchronizedRef` (note: since `SynchronizedRef` is not reactive (does not
|
|
57
|
+
- `fromSynchronizedRef` (note: since `SynchronizedRef` is not reactive (does not produce a stream of value changes), the resulting Lens' `changes` stream will only emit the current value of the lens when evaluated, and nothing else)
|
|
58
58
|
|
|
59
59
|
More to come!
|
|
60
60
|
|
|
@@ -110,7 +110,7 @@ Lens<{ readonly a: string, readonly b: number }, never, never, never, never>
|
|
|
110
110
|
Lens<string, never, never, never, never>
|
|
111
111
|
```
|
|
112
112
|
|
|
113
|
-
|
|
113
|
+
Focused Lenses work just the same as a Lens that points directly to a data source and can be read, subscribed to or written to.
|
|
114
114
|
|
|
115
115
|
Writing to them will properly update parent Lenses or data sources. Such updates can be performed in both a mutable or an immutable manner depending on your choice.
|
|
116
116
|
|
|
@@ -137,29 +137,29 @@ const ref = yield* SubscriptionRef.make<{
|
|
|
137
137
|
|
|
138
138
|
// \/ Lens<User, NoSuchElementException, NoSuchElementException, never, never>
|
|
139
139
|
const jeanDupontLens = ref.pipe(
|
|
140
|
-
Lens.fromSubscriptionRef,
|
|
141
|
-
Lens.
|
|
142
|
-
Lens.focusArrayAt(0),
|
|
140
|
+
Lens.fromSubscriptionRef, // Creates a lens that proxies the ref
|
|
141
|
+
Lens.focusObjectOn("users"), // Creates a focused lens that points to the users field
|
|
142
|
+
Lens.focusArrayAt(0), // Creates a focused lens that points to the first entry of the user array
|
|
143
143
|
)
|
|
144
|
-
// Reading or writing from this
|
|
144
|
+
// Reading or writing from this lens can fail with NoSuchElementException
|
|
145
145
|
// This is because of Lens.focusArrayAt(0), as reading and writing to an array is an unsafe operation
|
|
146
146
|
|
|
147
147
|
const jeanDupont = yield* Lens.get(jeanDupontLens)
|
|
148
148
|
|
|
149
149
|
yield* Lens.set(
|
|
150
150
|
// You can focus even further down
|
|
151
|
-
Lens.
|
|
151
|
+
Lens.focusObjectOn(jeanDupontLens, "age"),
|
|
152
152
|
yield* DateTime.make("03/25/1970"),
|
|
153
153
|
)
|
|
154
154
|
// Mutations with the parent state are performed immutably by default
|
|
155
|
-
// unless you use a specific mutable transform such as '
|
|
155
|
+
// unless you use a specific mutable transform such as 'focusObjectOnWritable'
|
|
156
156
|
```
|
|
157
157
|
|
|
158
158
|
Currently available:
|
|
159
159
|
| Name | Description | Parent state mutation behavior | Notes |
|
|
160
160
|
| - | - | - | - |
|
|
161
|
-
| `
|
|
162
|
-
| `
|
|
161
|
+
| `focusObjectOn` | Focuses to a field of an object. Replaces the parent object immutably when writing to the focused field | Immutable | |
|
|
162
|
+
| `focusObjectOnWritable` | Focuses to a writable field of an object. Mutates the parent object in place via the writable field | Mutable | Type-safe: will not allow you to mutate `readonly` fields |
|
|
163
163
|
| `focusArrayAt` | Focuses to an indexed entry of an array. Replaces the parent array immutably when writing to the focused index | Immutable | |
|
|
164
164
|
| `focusMutableArrayAt` | Focuses to an indexed entry of an array. Mutates the parent array in place at the focused index | Mutable | Type-safe: will not allow you to mutate `readonly` arrays |
|
|
165
165
|
| `focusTupleAt` | Focuses to an indexed entry of a readonly tuple. Replaces the parent tuple immutably when writing to the focused index | Immutable | |
|
|
@@ -211,12 +211,12 @@ const someFunctionThatShouldOnlyHaveReadonlyAccessToTheState = (
|
|
|
211
211
|
// Do whatever
|
|
212
212
|
const usersCountSub = Subscribable.map(usersSub, a => a.length)
|
|
213
213
|
const users = yield* usersSub.get
|
|
214
|
-
yield* Effect.forkScoped(Stream.runForEach(
|
|
214
|
+
yield* Effect.forkScoped(Stream.runForEach(usersSub.changes, ...))
|
|
215
215
|
})
|
|
216
216
|
|
|
217
217
|
const lens = ref.pipe(
|
|
218
218
|
Lens.fromSubscriptionRef,
|
|
219
|
-
Lens.
|
|
219
|
+
Lens.focusObjectOn("users"),
|
|
220
220
|
)
|
|
221
221
|
yield* someFunctionThatShouldOnlyHaveReadonlyAccessToTheState(lens)
|
|
222
222
|
```
|
|
@@ -226,19 +226,19 @@ This library re-exports Effect's `Subscribable` module and adds a few transforms
|
|
|
226
226
|
```typescript
|
|
227
227
|
import { Subscribable } from "effect-lens"
|
|
228
228
|
|
|
229
|
-
declare const sub:
|
|
229
|
+
declare const sub: Subscribable.Subscribable<readonly { name: string }[], never, never>
|
|
230
230
|
|
|
231
|
-
// \/
|
|
231
|
+
// \/ Subscribable.Subscribable<string, NoSuchElementException, never>
|
|
232
232
|
const nameSub = sub.pipe(
|
|
233
233
|
Subscribable.focusArrayAt(1),
|
|
234
|
-
Subscribable.
|
|
234
|
+
Subscribable.focusObjectOn("name"),
|
|
235
235
|
)
|
|
236
236
|
```
|
|
237
237
|
|
|
238
238
|
Currently available:
|
|
239
239
|
| Name | Description |
|
|
240
240
|
| - | - |
|
|
241
|
-
| `
|
|
241
|
+
| `focusObjectOn` | Focuses to the field of an object |
|
|
242
242
|
| `focusArrayAt` | Focuses to an indexed entry of an array |
|
|
243
243
|
| `focusTupleAt` | Focuses to an indexed entry of a tuple |
|
|
244
244
|
| `focusChunkAt` | Focuses to an indexed entry of a `Chunk` |
|
package/dist/Lens.d.ts
CHANGED
|
@@ -105,11 +105,11 @@ export declare const mapStream: {
|
|
|
105
105
|
/**
|
|
106
106
|
* Narrows the focus to a field of an object. Replaces the object in an immutable fashion when written to.
|
|
107
107
|
*/
|
|
108
|
-
export declare const
|
|
109
|
-
<A extends object,
|
|
110
|
-
<A extends object,
|
|
108
|
+
export declare const focusObjectOn: {
|
|
109
|
+
<A extends object, ER, EW, RR, RW, K extends keyof A>(self: Lens<A, ER, EW, RR, RW>, key: K): Lens<A[K], ER, EW, RR, RW>;
|
|
110
|
+
<A extends object, ER, EW, RR, RW, K extends keyof A>(key: K): (self: Lens<A, ER, EW, RR, RW>) => Lens<A[K], ER, EW, RR, RW>;
|
|
111
111
|
};
|
|
112
|
-
export declare namespace
|
|
112
|
+
export declare namespace focusObjectOnWritable {
|
|
113
113
|
type WritableKeys<T> = {
|
|
114
114
|
[K in keyof T]-?: IfEquals<{
|
|
115
115
|
[P in K]: T[K];
|
|
@@ -120,11 +120,11 @@ export declare namespace focusObjectMutableField {
|
|
|
120
120
|
type IfEquals<X, Y, A = X, B = never> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? A : B;
|
|
121
121
|
}
|
|
122
122
|
/**
|
|
123
|
-
* Narrows the focus to a
|
|
123
|
+
* Narrows the focus to a writable field of an object. Mutates the object in place when written to.
|
|
124
124
|
*/
|
|
125
|
-
export declare const
|
|
126
|
-
<A extends object,
|
|
127
|
-
<A extends object,
|
|
125
|
+
export declare const focusObjectOnWritable: {
|
|
126
|
+
<A extends object, ER, EW, RR, RW, K extends focusObjectOnWritable.WritableKeys<A>>(self: Lens<A, ER, EW, RR, RW>, key: K): Lens<A[K], ER, EW, RR, RW>;
|
|
127
|
+
<A extends object, ER, EW, RR, RW, K extends focusObjectOnWritable.WritableKeys<A>>(key: K): (self: Lens<A, ER, EW, RR, RW>) => Lens<A[K], ER, EW, RR, RW>;
|
|
128
128
|
};
|
|
129
129
|
/**
|
|
130
130
|
* Narrows the focus to an indexed element of an array. Replaces the array in an immutable fashion when written to.
|
|
@@ -144,15 +144,15 @@ export declare const focusMutableArrayAt: {
|
|
|
144
144
|
* Narrows the focus to an indexed element of a readonly tuple. Replaces the tuple in an immutable fashion when written to.
|
|
145
145
|
*/
|
|
146
146
|
export declare const focusTupleAt: {
|
|
147
|
-
<T extends readonly [any, ...any[]],
|
|
148
|
-
<T extends readonly [any, ...any[]],
|
|
147
|
+
<T extends readonly [any, ...any[]], ER, EW, RR, RW, I extends number>(self: Lens<T, ER, EW, RR, RW>, index: I): Lens<T[I], ER, EW, RR, RW>;
|
|
148
|
+
<T extends readonly [any, ...any[]], ER, EW, RR, RW, I extends number>(index: I): (self: Lens<T, ER, EW, RR, RW>) => Lens<T[I], ER, EW, RR, RW>;
|
|
149
149
|
};
|
|
150
150
|
/**
|
|
151
151
|
* Narrows the focus to an indexed element of a mutable tuple. Mutates the tuple in place when written to.
|
|
152
152
|
*/
|
|
153
153
|
export declare const focusMutableTupleAt: {
|
|
154
|
-
<T extends [any, ...any[]],
|
|
155
|
-
<T extends [any, ...any[]],
|
|
154
|
+
<T extends [any, ...any[]], ER, EW, RR, RW, I extends number>(self: Lens<T, ER, EW, RR, RW>, index: I): Lens<T[I], ER, EW, RR, RW>;
|
|
155
|
+
<T extends [any, ...any[]], ER, EW, RR, RW, I extends number>(index: I): (self: Lens<T, ER, EW, RR, RW>) => Lens<T[I], ER, EW, RR, RW>;
|
|
156
156
|
};
|
|
157
157
|
/**
|
|
158
158
|
* Narrows the focus to an indexed element of `Chunk`. Replaces the `Chunk` in an immutable fashion when written to.
|
package/dist/Lens.js
CHANGED
|
@@ -112,11 +112,11 @@ export const mapStream = Function.dual(2, (self, f) => make({
|
|
|
112
112
|
/**
|
|
113
113
|
* Narrows the focus to a field of an object. Replaces the object in an immutable fashion when written to.
|
|
114
114
|
*/
|
|
115
|
-
export const
|
|
115
|
+
export const focusObjectOn = Function.dual(2, (self, key) => map(self, a => a[key], (a, b) => Object.setPrototypeOf({ ...a, [key]: b }, Object.getPrototypeOf(a))));
|
|
116
116
|
/**
|
|
117
|
-
* Narrows the focus to a
|
|
117
|
+
* Narrows the focus to a writable field of an object. Mutates the object in place when written to.
|
|
118
118
|
*/
|
|
119
|
-
export const
|
|
119
|
+
export const focusObjectOnWritable = Function.dual(2, (self, key) => map(self, a => a[key], (a, b) => { a[key] = b; return a; }));
|
|
120
120
|
/**
|
|
121
121
|
* Narrows the focus to an indexed element of an array. Replaces the array in an immutable fashion when written to.
|
|
122
122
|
*/
|
package/dist/Lens.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Lens.js","sourceRoot":"","sources":["../src/Lens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAA8C,MAAM,QAAQ,CAAA;AAElJ,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AAGjD,MAAM,CAAC,MAAM,UAAU,GAAkB,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;AAmB3E;;GAEG;AACH,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"Lens.js","sourceRoot":"","sources":["../src/Lens.ts"],"names":[],"mappings":"AAAA,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AAO,CAAC,CAAC,IAAI,EAAE,IAAI,CAAU,CAAC,CAAA;AAChD,CAAC,CAAC,CACL,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAG3B,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAA0B,IAA6B,EAAE,CAAmC,EAAE,EAAE,CACjH,IAAI,CAAC,MAAM,CAAU,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,CACpC,CAAC,CAAC,CAAC,CAAC,EACJ,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,IAAI,CAAU,CAAC,CAChD,CAAC,CACL,CAAA"}
|
package/dist/Subscribable.d.ts
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
|
-
import { Chunk, Subscribable } from "effect";
|
|
1
|
+
import { Chunk, Effect, Option, Subscribable } from "effect";
|
|
2
2
|
import type { NoSuchElementException } from "effect/Cause";
|
|
3
3
|
export * from "effect/Subscribable";
|
|
4
|
+
/**
|
|
5
|
+
* Maps over an `Option` value in the `Subscribable`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const mapOption: {
|
|
8
|
+
<A, B, E, R>(self: Subscribable.Subscribable<Option.Option<A>, E, R>, f: (a: A) => B): Subscribable.Subscribable<Option.Option<B>, E, R>;
|
|
9
|
+
<A, B>(f: (a: A) => B): <E, R>(self: Subscribable.Subscribable<Option.Option<A>, E, R>) => Subscribable.Subscribable<Option.Option<B>, E, R>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Maps over an `Option` value in the `Subscribable` with an Effect.
|
|
13
|
+
*/
|
|
14
|
+
export declare const mapOptionEffect: {
|
|
15
|
+
<A, B, E, E2, R>(self: Subscribable.Subscribable<Option.Option<A>, E, R>, f: (a: A) => Effect.Effect<B, E2, R>): Subscribable.Subscribable<Option.Option<B>, E | E2, R>;
|
|
16
|
+
<A, B, E2>(f: (a: A) => Effect.Effect<B, E2>): <E, R>(self: Subscribable.Subscribable<Option.Option<A>, E, R>) => Subscribable.Subscribable<Option.Option<B>, E | E2, R>;
|
|
17
|
+
};
|
|
4
18
|
/**
|
|
5
19
|
* Narrows the focus to a field of an object.
|
|
6
20
|
*/
|
|
7
|
-
export declare const
|
|
21
|
+
export declare const focusObjectOn: {
|
|
8
22
|
<A extends object, K extends keyof A, E, R>(self: Subscribable.Subscribable<A, E, R>, key: K): Subscribable.Subscribable<A[K], E, R>;
|
|
9
23
|
<A extends object, K extends keyof A, E, R>(key: K): (self: Subscribable.Subscribable<A, E, R>) => Subscribable.Subscribable<A[K], E, R>;
|
|
10
24
|
};
|
package/dist/Subscribable.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import { Array, Chunk, Function, Subscribable } from "effect";
|
|
1
|
+
import { Array, Chunk, Effect, Function, Option, Subscribable } from "effect";
|
|
2
2
|
export * from "effect/Subscribable";
|
|
3
|
+
/**
|
|
4
|
+
* Maps over an `Option` value in the `Subscribable`.
|
|
5
|
+
*/
|
|
6
|
+
export const mapOption = Function.dual(2, (self, f) => Subscribable.map(self, Option.map(f)));
|
|
7
|
+
/**
|
|
8
|
+
* Maps over an `Option` value in the `Subscribable` with an Effect.
|
|
9
|
+
*/
|
|
10
|
+
export const mapOptionEffect = Function.dual(2, (self, f) => Subscribable.mapEffect(self, Option.match({
|
|
11
|
+
onSome: a => Effect.map(f(a), Option.some),
|
|
12
|
+
onNone: () => Effect.succeed(Option.none()),
|
|
13
|
+
})));
|
|
3
14
|
/**
|
|
4
15
|
* Narrows the focus to a field of an object.
|
|
5
16
|
*/
|
|
6
|
-
export const
|
|
17
|
+
export const focusObjectOn = Function.dual(2, (self, key) => Subscribable.map(self, a => a[key]));
|
|
7
18
|
/**
|
|
8
19
|
* Narrows the focus to an indexed element of an array.
|
|
9
20
|
*/
|
package/dist/Subscribable.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Subscribable.js","sourceRoot":"","sources":["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;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAQrB,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CACjB,IAAwC,EACxC,KAAa,EACsD,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAEzH;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAQrB,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CACjB,IAAwC,EACxC,KAAQ,EAC6B,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAE3F;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAQrB,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CACjB,IAAqD,EACrD,KAAa,EAC8C,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "effect-lens",
|
|
3
3
|
"description": "An effectful Lens type to easily manage nested state",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.5",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"./README.md",
|
|
@@ -21,10 +21,6 @@
|
|
|
21
21
|
"types": "./dist/Lens.d.ts",
|
|
22
22
|
"default": "./dist/Lens.js"
|
|
23
23
|
},
|
|
24
|
-
"./PropertyPath": {
|
|
25
|
-
"types": "./dist/PropertyPath.d.ts",
|
|
26
|
-
"default": "./dist/PropertyPath.js"
|
|
27
|
-
},
|
|
28
24
|
"./Subscribable": {
|
|
29
25
|
"types": "./dist/Subscribable.d.ts",
|
|
30
26
|
"default": "./dist/Subscribable.js"
|
package/dist/PropertyPath.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Equivalence, Option } from "effect";
|
|
2
|
-
export type PropertyPath = readonly PropertyKey[];
|
|
3
|
-
type Prev = readonly [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
4
|
-
export type Paths<T, D extends number = 5, Seen = never> = readonly [] | (D extends never ? readonly [] : T extends Seen ? readonly [] : T extends readonly any[] ? {
|
|
5
|
-
[K in keyof T as K extends number ? K : never]: readonly [K] | readonly [K, ...Paths<T[K], Prev[D], Seen | T>];
|
|
6
|
-
} extends infer O ? O[keyof O] : never : T extends object ? {
|
|
7
|
-
[K in keyof T as K extends string | number | symbol ? K : never]-?: NonNullable<T[K]> extends infer V ? readonly [K] | readonly [K, ...Paths<V, Prev[D], Seen>] : never;
|
|
8
|
-
} extends infer O ? O[keyof O] : never : never);
|
|
9
|
-
export type ValueFromPath<T, P extends readonly any[]> = P extends readonly [infer Head, ...infer Tail] ? Head extends keyof T ? ValueFromPath<T[Head], Tail> : T extends readonly any[] ? Head extends number ? ValueFromPath<T[number], Tail> : never : never : T;
|
|
10
|
-
export declare const equivalence: Equivalence.Equivalence<PropertyPath>;
|
|
11
|
-
export declare const unsafeGet: {
|
|
12
|
-
<T, const P extends Paths<T>>(path: P): (self: T) => ValueFromPath<T, P>;
|
|
13
|
-
<T, const P extends Paths<T>>(self: T, path: P): ValueFromPath<T, P>;
|
|
14
|
-
};
|
|
15
|
-
export declare const get: {
|
|
16
|
-
<T, const P extends Paths<T>>(path: P): (self: T) => Option.Option<ValueFromPath<T, P>>;
|
|
17
|
-
<T, const P extends Paths<T>>(self: T, path: P): Option.Option<ValueFromPath<T, P>>;
|
|
18
|
-
};
|
|
19
|
-
export declare const immutableSet: {
|
|
20
|
-
<T, const P extends Paths<T>>(path: P, value: ValueFromPath<T, P>): (self: T) => Option.Option<T>;
|
|
21
|
-
<T, const P extends Paths<T>>(self: T, path: P, value: ValueFromPath<T, P>): Option.Option<T>;
|
|
22
|
-
};
|
|
23
|
-
export {};
|
package/dist/PropertyPath.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Array, Equivalence, Function, Option, Predicate } from "effect";
|
|
2
|
-
export const equivalence = Equivalence.array(Equivalence.strict());
|
|
3
|
-
export const unsafeGet = Function.dual(2, (self, path) => path.reduce((acc, key) => acc?.[key], self));
|
|
4
|
-
export const get = Function.dual(2, (self, path) => path.reduce((acc, key) => Option.isSome(acc)
|
|
5
|
-
? Predicate.hasProperty(acc.value, key)
|
|
6
|
-
? Option.some(acc.value[key])
|
|
7
|
-
: Option.none()
|
|
8
|
-
: acc, Option.some(self)));
|
|
9
|
-
export const immutableSet = Function.dual(3, (self, path, value) => {
|
|
10
|
-
const key = Array.head(path);
|
|
11
|
-
if (Option.isNone(key))
|
|
12
|
-
return Option.some(value);
|
|
13
|
-
if (!Predicate.hasProperty(self, key.value))
|
|
14
|
-
return Option.none();
|
|
15
|
-
const child = immutableSet(self[key.value], Option.getOrThrow(Array.tail(path)), value);
|
|
16
|
-
if (Option.isNone(child))
|
|
17
|
-
return child;
|
|
18
|
-
if (Array.isArray(self))
|
|
19
|
-
return typeof key.value === "number"
|
|
20
|
-
? Option.some([
|
|
21
|
-
...self.slice(0, key.value),
|
|
22
|
-
child.value,
|
|
23
|
-
...self.slice(key.value + 1),
|
|
24
|
-
])
|
|
25
|
-
: Option.none();
|
|
26
|
-
if (typeof self === "object")
|
|
27
|
-
return Option.some(Object.assign(Object.create(Object.getPrototypeOf(self)), { ...self, [key.value]: child.value }));
|
|
28
|
-
return Option.none();
|
|
29
|
-
});
|
|
30
|
-
//# sourceMappingURL=PropertyPath.js.map
|
package/dist/PropertyPath.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PropertyPath.js","sourceRoot":"","sources":["../src/PropertyPath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAyCxE,MAAM,CAAC,MAAM,WAAW,GAA0C,WAAW,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAA;AAEzG,MAAM,CAAC,MAAM,SAAS,GAGlB,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAA8B,IAAO,EAAE,IAAO,EAAuB,EAAE,CACxF,IAAI,CAAC,MAAM,CAAC,CAAC,GAAQ,EAAE,GAAQ,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CACxD,CAAA;AAED,MAAM,CAAC,MAAM,GAAG,GAGZ,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAA8B,IAAO,EAAE,IAAO,EAAsC,EAAE,CACvG,IAAI,CAAC,MAAM,CACP,CAAC,GAAuB,EAAE,GAAQ,EAAsB,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC;IACzE,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC;QACnC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC7B,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE;IACnB,CAAC,CAAC,GAAG,EAET,MAAM,CAAC,IAAI,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