@@ -27,7 +27,11 @@ type ModifiableLensLike<S, A> =
27
27
28
28
type SettableLensLike<S, A> = ModifiableLensLike<S, A> | O.Setter<S, any, A>;
29
29
30
- type LensLike<S, A> = SettableLensLike<S, A> | O.Getter<S, A>;
30
+ type LensLike<S, A> =
31
+ | SettableLensLike<S, A>
32
+ | O.Getter<S, A>
33
+ | O.AffineFold<S, A>
34
+ | O.Fold<S, A>;
31
35
32
36
// Pattern 1: Promise
33
37
@@ -58,6 +62,16 @@ export function focusAtom<S, A, R>(
58
62
callback: (optic: O.OpticFor_<S>) => O.Getter<S, A>,
59
63
): Atom<Promise<A>>;
60
64
65
+ export function focusAtom<S, A, R>(
66
+ baseAtom: WritableAtom<Promise<S>, [Promise<S>], R>,
67
+ callback: (optic: O.OpticFor_<S>) => O.AffineFold<S, A>,
68
+ ): Atom<Promise<A | undefined>>;
69
+
70
+ export function focusAtom<S, A, R>(
71
+ baseAtom: WritableAtom<Promise<S>, [Promise<S>], R>,
72
+ callback: (optic: O.OpticFor_<S>) => O.Fold<S, A>,
73
+ ): Atom<Promise<A[]>>;
74
+
61
75
// Pattern 2: Promise with undefined type
62
76
63
77
export function focusAtom<S, A, R>(
@@ -87,6 +101,16 @@ export function focusAtom<S, A, R>(
87
101
callback: (optic: O.OpticFor_<S | undefined>) => O.Getter<S, A>,
88
102
): Atom<Promise<A>>;
89
103
104
+ export function focusAtom<S, A, R>(
105
+ baseAtom: WritableAtom<Promise<S | undefined>, [Promise<S>], R>,
106
+ callback: (optic: O.OpticFor_<S | undefined>) => O.AffineFold<S, A>,
107
+ ): Atom<Promise<A | undefined>>;
108
+
109
+ export function focusAtom<S, A, R>(
110
+ baseAtom: WritableAtom<Promise<S | undefined>, [Promise<S>], R>,
111
+ callback: (optic: O.OpticFor_<S | undefined>) => O.Fold<S, A>,
112
+ ): Atom<Promise<A[]>>;
113
+
90
114
// Pattern 3: Default
91
115
92
116
export function focusAtom<S, A, R>(
@@ -116,6 +140,16 @@ export function focusAtom<S, A, R>(
116
140
callback: (optic: O.OpticFor_<S>) => O.Getter<S, A>,
117
141
): Atom<A>;
118
142
143
+ export function focusAtom<S, A, R>(
144
+ baseAtom: WritableAtom<S, [NonFunction<S>], R>,
145
+ callback: (optic: O.OpticFor_<S>) => O.AffineFold<S, A>,
146
+ ): Atom<A | undefined>;
147
+
148
+ export function focusAtom<S, A, R>(
149
+ baseAtom: WritableAtom<S, [NonFunction<S>], R>,
150
+ callback: (optic: O.OpticFor_<S>) => O.Fold<S, A>,
151
+ ): Atom<A[]>;
152
+
119
153
// Pattern 4: Default with undefined type
120
154
121
155
export function focusAtom<S, A, R>(
@@ -145,6 +179,16 @@ export function focusAtom<S, A, R>(
145
179
callback: (optic: O.OpticFor_<S | undefined>) => O.Getter<S, A>,
146
180
): Atom<A>;
147
181
182
+ export function focusAtom<S, A, R>(
183
+ baseAtom: WritableAtom<S | undefined, [NonFunction<S>], R>,
184
+ callback: (optic: O.OpticFor_<S | undefined>) => O.AffineFold<S, A>,
185
+ ): Atom<A | undefined>;
186
+
187
+ export function focusAtom<S, A, R>(
188
+ baseAtom: WritableAtom<S | undefined, [NonFunction<S>], R>,
189
+ callback: (optic: O.OpticFor_<S | undefined>) => O.Fold<S, A>,
190
+ ): Atom<A[]>;
191
+
148
192
// Implementation
149
193
150
194
export function focusAtom<S, A, R>(
@@ -182,11 +226,11 @@ export function focusAtom<S, A, R>(
182
226
}
183
227
184
228
const getValueUsingOptic = <S, A>(focus: LensLike<S, A>, bigValue: S) => {
185
- if (focus._tag === 'Traversal') {
229
+ if (focus._tag === 'Traversal' || focus._tag === 'Fold' ) {
186
230
const values = O.collect(focus)(bigValue);
187
231
return values;
188
232
}
189
- if (focus._tag === 'Prism') {
233
+ if (focus._tag === 'Prism' || focus._tag === 'AffineFold' ) {
190
234
const value = O.preview(focus)(bigValue);
191
235
return value;
192
236
}
0 commit comments