1 | import { Foldable, Foldable1, Foldable2, Foldable3 } from 'fp-ts/lib/Foldable'
|
2 | import { Predicate, Refinement } from 'fp-ts/lib/function'
|
3 | import { HKT, Kind, Kind2, Kind3, URIS, URIS2, URIS3 } from 'fp-ts/lib/HKT'
|
4 | import { Monoid } from 'fp-ts/lib/Monoid'
|
5 | import { Option } from 'fp-ts/lib/Option'
|
6 | import { Traversable, Traversable1, Traversable2, Traversable3 } from 'fp-ts/lib/Traversable'
|
7 | import * as at from './At'
|
8 | import * as iso from './Iso'
|
9 | import * as index from './Ix'
|
10 | import * as lens from './Lens'
|
11 | import * as optional from './Optional'
|
12 | import * as prism from './Prism'
|
13 | import * as traversal from './Traversal'
|
14 | export {
|
15 | |
16 |
|
17 |
|
18 | at,
|
19 | |
20 |
|
21 |
|
22 | iso,
|
23 | |
24 |
|
25 |
|
26 | index,
|
27 | |
28 |
|
29 |
|
30 | lens,
|
31 | |
32 |
|
33 |
|
34 | prism,
|
35 | |
36 |
|
37 |
|
38 | optional,
|
39 | |
40 |
|
41 |
|
42 | traversal
|
43 | }
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | export declare class Iso<S, A> {
|
53 | readonly get: (s: S) => A
|
54 | readonly reverseGet: (a: A) => S
|
55 | |
56 |
|
57 |
|
58 | readonly _tag: 'Iso'
|
59 | |
60 |
|
61 |
|
62 | readonly unwrap: (s: S) => A
|
63 | |
64 |
|
65 |
|
66 | readonly to: (s: S) => A
|
67 | |
68 |
|
69 |
|
70 | readonly wrap: (a: A) => S
|
71 | |
72 |
|
73 |
|
74 | readonly from: (a: A) => S
|
75 | constructor(get: (s: S) => A, reverseGet: (a: A) => S)
|
76 | /**
|
77 | * reverse the `Iso`: the source becomes the target and the target becomes the source
|
78 | * @since 1.0.0
|
79 | */
|
80 | reverse(): Iso<A, S>
|
81 | /**
|
82 | * @since 1.0.0
|
83 | */
|
84 | modify(f: (a: A) => A): (s: S) => S
|
85 | /**
|
86 | * view an `Iso` as a `Lens`
|
87 | *
|
88 | * @since 1.0.0
|
89 | */
|
90 | asLens(): Lens<S, A>
|
91 | /**
|
92 | * view an `Iso` as a `Prism`
|
93 | *
|
94 | * @since 1.0.0
|
95 | */
|
96 | asPrism(): Prism<S, A>
|
97 | /**
|
98 | * view an `Iso` as a `Optional`
|
99 | *
|
100 | * @since 1.0.0
|
101 | */
|
102 | asOptional(): Optional<S, A>
|
103 | /**
|
104 | * view an `Iso` as a `Traversal`
|
105 | *
|
106 | * @since 1.0.0
|
107 | */
|
108 | asTraversal(): Traversal<S, A>
|
109 | /**
|
110 | * view an `Iso` as a `Fold`
|
111 | *
|
112 | * @since 1.0.0
|
113 | */
|
114 | asFold(): Fold<S, A>
|
115 | /**
|
116 | * view an `Iso` as a `Getter`
|
117 | *
|
118 | * @since 1.0.0
|
119 | */
|
120 | asGetter(): Getter<S, A>
|
121 | /**
|
122 | * view an `Iso` as a `Setter`
|
123 | *
|
124 | * @since 1.0.0
|
125 | */
|
126 | asSetter(): Setter<S, A>
|
127 | /**
|
128 | * compose an `Iso` with an `Iso`
|
129 | *
|
130 | * @since 1.0.0
|
131 | */
|
132 | compose<B>(ab: Iso<A, B>): Iso<S, B>
|
133 | /**
|
134 | * Alias of `compose`
|
135 | *
|
136 | * @since 1.0.0
|
137 | */
|
138 | composeIso<B>(ab: Iso<A, B>): Iso<S, B>
|
139 | /**
|
140 | * compose an `Iso` with a `Lens `
|
141 | *
|
142 | * @since 1.0.0
|
143 | */
|
144 | composeLens<B>(ab: Lens<A, B>): Lens<S, B>
|
145 | /**
|
146 | * compose an `Iso` with a `Prism`
|
147 | *
|
148 | * @since 1.0.0
|
149 | */
|
150 | composePrism<B>(ab: Prism<A, B>): Prism<S, B>
|
151 | /**
|
152 | * compose an `Iso` with an `Optional`
|
153 | *
|
154 | * @since 1.0.0
|
155 | */
|
156 | composeOptional<B>(ab: Optional<A, B>): Optional<S, B>
|
157 | /**
|
158 | * compose an `Iso` with a `Traversal`
|
159 | *
|
160 | * @since 1.0.0
|
161 | */
|
162 | composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B>
|
163 | /**
|
164 | * compose an `Iso` with a `Fold`
|
165 | *
|
166 | * @since 1.0.0
|
167 | */
|
168 | composeFold<B>(ab: Fold<A, B>): Fold<S, B>
|
169 | /**
|
170 | * compose an `Iso` with a `Getter`
|
171 | *
|
172 | * @since 1.0.0
|
173 | */
|
174 | composeGetter<B>(ab: Getter<A, B>): Getter<S, B>
|
175 | /**
|
176 | * compose an `Iso` with a `Setter`
|
177 | *
|
178 | * @since 1.0.0
|
179 | */
|
180 | composeSetter<B>(ab: Setter<A, B>): Setter<S, B>
|
181 | }
|
182 | /**
|
183 | * @since 1.3.0
|
184 | */
|
185 | export interface LensFromPath<S> {
|
186 | <
|
187 | K1 extends keyof S,
|
188 | K2 extends keyof S[K1],
|
189 | K3 extends keyof S[K1][K2],
|
190 | K4 extends keyof S[K1][K2][K3],
|
191 | K5 extends keyof S[K1][K2][K3][K4]
|
192 | >(
|
193 | path: [K1, K2, K3, K4, K5]
|
194 | ): Lens<S, S[K1][K2][K3][K4][K5]>
|
195 | <K1 extends keyof S, K2 extends keyof S[K1], K3 extends keyof S[K1][K2], K4 extends keyof S[K1][K2][K3]>(
|
196 | path: [K1, K2, K3, K4]
|
197 | ): Lens<S, S[K1][K2][K3][K4]>
|
198 | <K1 extends keyof S, K2 extends keyof S[K1], K3 extends keyof S[K1][K2]>(path: [K1, K2, K3]): Lens<S, S[K1][K2][K3]>
|
199 | <K1 extends keyof S, K2 extends keyof S[K1]>(path: [K1, K2]): Lens<S, S[K1][K2]>
|
200 | <K1 extends keyof S>(path: [K1]): Lens<S, S[K1]>
|
201 | }
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 | export declare class Lens<S, A> {
|
212 | readonly get: (s: S) => A
|
213 | readonly set: (a: A) => (s: S) => S
|
214 | |
215 |
|
216 |
|
217 | readonly _tag: 'Lens'
|
218 | constructor(get: (s: S) => A, set: (a: A) => (s: S) => S)
|
219 | /**
|
220 | * @example
|
221 | * import { Lens } from 'monocle-ts'
|
222 | *
|
223 | * type Person = {
|
224 | * name: string
|
225 | * age: number
|
226 | * address: {
|
227 | * city: string
|
228 | * }
|
229 | * }
|
230 | *
|
231 | * const city = Lens.fromPath<Person>()(['address', 'city'])
|
232 | *
|
233 | * const person: Person = { name: 'Giulio', age: 43, address: { city: 'Milan' } }
|
234 | *
|
235 | * assert.strictEqual(city.get(person), 'Milan')
|
236 | * assert.deepStrictEqual(city.set('London')(person), { name: 'Giulio', age: 43, address: { city: 'London' } })
|
237 | *
|
238 | * @since 1.0.0
|
239 | */
|
240 | static fromPath<S>(): LensFromPath<S>
|
241 | |
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 | static fromProp<S>(): <P extends keyof S>(prop: P) => Lens<S, S[P]>
|
262 | |
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 | static fromProps<S>(): <P extends keyof S>(
|
284 | props: Array<P>
|
285 | ) => Lens<
|
286 | S,
|
287 | {
|
288 | [K in P]: S[K]
|
289 | }
|
290 | >
|
291 | |
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 | static fromNullableProp<S>(): <A extends S[K], K extends keyof S>(k: K, defaultValue: A) => Lens<S, NonNullable<S[K]>>
|
318 | |
319 |
|
320 |
|
321 | modify(f: (a: A) => A): (s: S) => S
|
322 | |
323 |
|
324 |
|
325 |
|
326 |
|
327 | asOptional(): Optional<S, A>
|
328 | |
329 |
|
330 |
|
331 |
|
332 |
|
333 | asTraversal(): Traversal<S, A>
|
334 | |
335 |
|
336 |
|
337 |
|
338 |
|
339 | asSetter(): Setter<S, A>
|
340 | |
341 |
|
342 |
|
343 |
|
344 |
|
345 | asGetter(): Getter<S, A>
|
346 | |
347 |
|
348 |
|
349 |
|
350 |
|
351 | asFold(): Fold<S, A>
|
352 | |
353 |
|
354 |
|
355 |
|
356 |
|
357 | compose<B>(ab: Lens<A, B>): Lens<S, B>
|
358 | |
359 |
|
360 |
|
361 |
|
362 |
|
363 | composeLens<B>(ab: Lens<A, B>): Lens<S, B>
|
364 | |
365 |
|
366 |
|
367 |
|
368 |
|
369 | composeGetter<B>(ab: Getter<A, B>): Getter<S, B>
|
370 | |
371 |
|
372 |
|
373 |
|
374 |
|
375 | composeFold<B>(ab: Fold<A, B>): Fold<S, B>
|
376 | |
377 |
|
378 |
|
379 |
|
380 |
|
381 | composeOptional<B>(ab: Optional<A, B>): Optional<S, B>
|
382 | |
383 |
|
384 |
|
385 |
|
386 |
|
387 | composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B>
|
388 | |
389 |
|
390 |
|
391 |
|
392 |
|
393 | composeSetter<B>(ab: Setter<A, B>): Setter<S, B>
|
394 | |
395 |
|
396 |
|
397 |
|
398 |
|
399 | composeIso<B>(ab: Iso<A, B>): Lens<S, B>
|
400 | |
401 |
|
402 |
|
403 |
|
404 |
|
405 | composePrism<B>(ab: Prism<A, B>): Optional<S, B>
|
406 | }
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 | export declare class Prism<S, A> {
|
416 | readonly getOption: (s: S) => Option<A>
|
417 | readonly reverseGet: (a: A) => S
|
418 | |
419 |
|
420 |
|
421 | readonly _tag: 'Prism'
|
422 | constructor(getOption: (s: S) => Option<A>, reverseGet: (a: A) => S)
|
423 | /**
|
424 | * @since 1.0.0
|
425 | */
|
426 | static fromPredicate<S, A extends S>(refinement: Refinement<S, A>): Prism<S, A>
|
427 | static fromPredicate<A>(predicate: Predicate<A>): Prism<A, A>
|
428 | /**
|
429 | * @since 1.0.0
|
430 | */
|
431 | static some<A>(): Prism<Option<A>, A>
|
432 | /**
|
433 | * @since 1.0.0
|
434 | */
|
435 | modify(f: (a: A) => A): (s: S) => S
|
436 | /**
|
437 | * @since 1.0.0
|
438 | */
|
439 | modifyOption(f: (a: A) => A): (s: S) => Option<S>
|
440 | /**
|
441 | * set the target of a `Prism` with a value
|
442 | *
|
443 | * @since 1.0.0
|
444 | */
|
445 | set(a: A): (s: S) => S
|
446 | /**
|
447 | * view a `Prism` as a `Optional`
|
448 | *
|
449 | * @since 1.0.0
|
450 | */
|
451 | asOptional(): Optional<S, A>
|
452 | /**
|
453 | * view a `Prism` as a `Traversal`
|
454 | *
|
455 | * @since 1.0.0
|
456 | */
|
457 | asTraversal(): Traversal<S, A>
|
458 | /**
|
459 | * view a `Prism` as a `Setter`
|
460 | *
|
461 | * @since 1.0.0
|
462 | */
|
463 | asSetter(): Setter<S, A>
|
464 | /**
|
465 | * view a `Prism` as a `Fold`
|
466 | *
|
467 | * @since 1.0.0
|
468 | */
|
469 | asFold(): Fold<S, A>
|
470 | /**
|
471 | * compose a `Prism` with a `Prism`
|
472 | *
|
473 | * @since 1.0.0
|
474 | */
|
475 | compose<B>(ab: Prism<A, B>): Prism<S, B>
|
476 | /**
|
477 | * Alias of `compose`
|
478 | *
|
479 | * @since 1.0.0
|
480 | */
|
481 | composePrism<B>(ab: Prism<A, B>): Prism<S, B>
|
482 | /**
|
483 | * compose a `Prism` with a `Optional`
|
484 | *
|
485 | * @since 1.0.0
|
486 | */
|
487 | composeOptional<B>(ab: Optional<A, B>): Optional<S, B>
|
488 | /**
|
489 | * compose a `Prism` with a `Traversal`
|
490 | *
|
491 | * @since 1.0.0
|
492 | */
|
493 | composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B>
|
494 | /**
|
495 | * compose a `Prism` with a `Fold`
|
496 | *
|
497 | * @since 1.0.0
|
498 | */
|
499 | composeFold<B>(ab: Fold<A, B>): Fold<S, B>
|
500 | /**
|
501 | * compose a `Prism` with a `Setter`
|
502 | *
|
503 | * @since 1.0.0
|
504 | */
|
505 | composeSetter<B>(ab: Setter<A, B>): Setter<S, B>
|
506 | /**
|
507 | * compose a `Prism` with a `Iso`
|
508 | *
|
509 | * @since 1.0.0
|
510 | */
|
511 | composeIso<B>(ab: Iso<A, B>): Prism<S, B>
|
512 | /**
|
513 | * compose a `Prism` with a `Lens`
|
514 | *
|
515 | * @since 1.0.0
|
516 | */
|
517 | composeLens<B>(ab: Lens<A, B>): Optional<S, B>
|
518 | /**
|
519 | * compose a `Prism` with a `Getter`
|
520 | *
|
521 | * @since 1.0.0
|
522 | */
|
523 | composeGetter<B>(ab: Getter<A, B>): Fold<S, B>
|
524 | }
|
525 | declare type OptionPropertyNames<S> = {
|
526 | [K in keyof S]-?: S[K] extends Option<any> ? K : never
|
527 | }[keyof S]
|
528 | declare type OptionPropertyType<S, K extends OptionPropertyNames<S>> = S[K] extends Option<infer A> ? A : never
|
529 |
|
530 |
|
531 |
|
532 | export interface OptionalFromPath<S> {
|
533 | <
|
534 | K1 extends keyof S,
|
535 | K2 extends keyof NonNullable<S[K1]>,
|
536 | K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>,
|
537 | K4 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>,
|
538 | K5 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>
|
539 | >(
|
540 | path: [K1, K2, K3, K4, K5]
|
541 | ): Optional<S, NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>[K5]>>
|
542 | <
|
543 | K1 extends keyof S,
|
544 | K2 extends keyof NonNullable<S[K1]>,
|
545 | K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>,
|
546 | K4 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>
|
547 | >(
|
548 | path: [K1, K2, K3, K4]
|
549 | ): Optional<S, NonNullable<NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>>
|
550 | <K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>, K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>>(
|
551 | path: [K1, K2, K3]
|
552 | ): Optional<S, NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>>
|
553 | <K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>>(path: [K1, K2]): Optional<
|
554 | S,
|
555 | NonNullable<NonNullable<S[K1]>[K2]>
|
556 | >
|
557 | <K1 extends keyof S>(path: [K1]): Optional<S, NonNullable<S[K1]>>
|
558 | }
|
559 |
|
560 |
|
561 |
|
562 |
|
563 |
|
564 |
|
565 |
|
566 |
|
567 |
|
568 | export declare class Optional<S, A> {
|
569 | readonly getOption: (s: S) => Option<A>
|
570 | readonly set: (a: A) => (s: S) => S
|
571 | |
572 |
|
573 |
|
574 | readonly _tag: 'Optional'
|
575 | constructor(getOption: (s: S) => Option<A>, set: (a: A) => (s: S) => S)
|
576 | /**
|
577 | * Returns an `Optional` from a nullable (`A | null | undefined`) prop
|
578 | *
|
579 | * @example
|
580 | * import { Optional } from 'monocle-ts'
|
581 | *
|
582 | * interface Phone {
|
583 | * number: string
|
584 | * }
|
585 | * interface Employment {
|
586 | * phone?: Phone
|
587 | * }
|
588 | * interface Info {
|
589 | * employment?: Employment
|
590 | * }
|
591 | * interface Response {
|
592 | * info?: Info
|
593 | * }
|
594 | *
|
595 | * const numberFromResponse = Optional.fromPath<Response>()(['info', 'employment', 'phone', 'number'])
|
596 | *
|
597 | * const response1: Response = {
|
598 | * info: {
|
599 | * employment: {
|
600 | * phone: {
|
601 | * number: '555-1234'
|
602 | * }
|
603 | * }
|
604 | * }
|
605 | * }
|
606 | * const response2: Response = {
|
607 | * info: {
|
608 | * employment: {}
|
609 | * }
|
610 | * }
|
611 | *
|
612 | * numberFromResponse.getOption(response1)
|
613 | * numberFromResponse.getOption(response2)
|
614 | *
|
615 | * @since 2.1.0
|
616 | */
|
617 | static fromPath<S>(): OptionalFromPath<S>
|
618 | |
619 |
|
620 |
|
621 |
|
622 |
|
623 |
|
624 |
|
625 |
|
626 |
|
627 |
|
628 |
|
629 |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 |
|
635 |
|
636 |
|
637 |
|
638 | static fromNullableProp<S>(): <K extends keyof S>(k: K) => Optional<S, NonNullable<S[K]>>
|
639 | |
640 |
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 |
|
653 |
|
654 |
|
655 |
|
656 |
|
657 |
|
658 | static fromOptionProp<S>(): <P extends OptionPropertyNames<S>>(prop: P) => Optional<S, OptionPropertyType<S, P>>
|
659 | |
660 |
|
661 |
|
662 | modify(f: (a: A) => A): (s: S) => S
|
663 | |
664 |
|
665 |
|
666 | modifyOption(f: (a: A) => A): (s: S) => Option<S>
|
667 | |
668 |
|
669 |
|
670 |
|
671 |
|
672 | asTraversal(): Traversal<S, A>
|
673 | |
674 |
|
675 |
|
676 |
|
677 |
|
678 | asFold(): Fold<S, A>
|
679 | |
680 |
|
681 |
|
682 |
|
683 |
|
684 | asSetter(): Setter<S, A>
|
685 | |
686 |
|
687 |
|
688 |
|
689 |
|
690 | compose<B>(ab: Optional<A, B>): Optional<S, B>
|
691 | |
692 |
|
693 |
|
694 |
|
695 |
|
696 | composeOptional<B>(ab: Optional<A, B>): Optional<S, B>
|
697 | |
698 |
|
699 |
|
700 |
|
701 |
|
702 | composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B>
|
703 | |
704 |
|
705 |
|
706 |
|
707 |
|
708 | composeFold<B>(ab: Fold<A, B>): Fold<S, B>
|
709 | |
710 |
|
711 |
|
712 |
|
713 |
|
714 | composeSetter<B>(ab: Setter<A, B>): Setter<S, B>
|
715 | |
716 |
|
717 |
|
718 |
|
719 |
|
720 | composeLens<B>(ab: Lens<A, B>): Optional<S, B>
|
721 | |
722 |
|
723 |
|
724 |
|
725 |
|
726 | composePrism<B>(ab: Prism<A, B>): Optional<S, B>
|
727 | |
728 |
|
729 |
|
730 |
|
731 |
|
732 | composeIso<B>(ab: Iso<A, B>): Optional<S, B>
|
733 | |
734 |
|
735 |
|
736 |
|
737 |
|
738 | composeGetter<B>(ab: Getter<A, B>): Fold<S, B>
|
739 | }
|
740 |
|
741 |
|
742 |
|
743 | export declare type ModifyF<S, A> = traversal.ModifyF<S, A>
|
744 |
|
745 |
|
746 |
|
747 |
|
748 | export declare class Traversal<S, A> {
|
749 | readonly modifyF: ModifyF<S, A>
|
750 | |
751 |
|
752 |
|
753 | readonly _tag: 'Traversal'
|
754 | constructor(modifyF: ModifyF<S, A>)
|
755 | /**
|
756 | * @since 1.0.0
|
757 | */
|
758 | modify(f: (a: A) => A): (s: S) => S
|
759 | /**
|
760 | * @since 1.0.0
|
761 | */
|
762 | set(a: A): (s: S) => S
|
763 | /**
|
764 | * focus the items matched by a `traversal` to those that match a predicate
|
765 | *
|
766 | * @example
|
767 | * import { fromTraversable, Lens } from 'monocle-ts'
|
768 | * import { Traversable } from 'fp-ts/Array'
|
769 | *
|
770 | * interface Person {
|
771 | * name: string;
|
772 | * cool: boolean;
|
773 | * }
|
774 | *
|
775 | * const peopleTraversal = fromTraversable(Traversable)<Person>()
|
776 | * const coolLens = Lens.fromProp<Person>()('cool')
|
777 | * const people = [{name: 'bill', cool: false}, {name: 'jill', cool: true}]
|
778 | *
|
779 | * const actual = peopleTraversal.filter(p => p.name === 'bill').composeLens(coolLens)
|
780 | * .set(true)(people)
|
781 | *
|
782 | * assert.deepStrictEqual(actual, [{name: 'bill', cool: true}, {name: 'jill', cool: true}])
|
783 | *
|
784 | * @since 1.0.0
|
785 | */
|
786 | filter<B extends A>(refinement: Refinement<A, B>): Traversal<S, B>
|
787 | filter(predicate: Predicate<A>): Traversal<S, A>
|
788 | |
789 |
|
790 |
|
791 |
|
792 |
|
793 | asFold(): Fold<S, A>
|
794 | |
795 |
|
796 |
|
797 |
|
798 |
|
799 | asSetter(): Setter<S, A>
|
800 | |
801 |
|
802 |
|
803 |
|
804 |
|
805 | compose<B>(ab: Traversal<A, B>): Traversal<S, B>
|
806 | |
807 |
|
808 |
|
809 |
|
810 |
|
811 | composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B>
|
812 | |
813 |
|
814 |
|
815 |
|
816 |
|
817 | composeFold<B>(ab: Fold<A, B>): Fold<S, B>
|
818 | |
819 |
|
820 |
|
821 |
|
822 |
|
823 | composeSetter<B>(ab: Setter<A, B>): Setter<S, B>
|
824 | |
825 |
|
826 |
|
827 |
|
828 |
|
829 | composeOptional<B>(ab: Optional<A, B>): Traversal<S, B>
|
830 | |
831 |
|
832 |
|
833 |
|
834 |
|
835 | composeLens<B>(ab: Lens<A, B>): Traversal<S, B>
|
836 | |
837 |
|
838 |
|
839 |
|
840 |
|
841 | composePrism<B>(ab: Prism<A, B>): Traversal<S, B>
|
842 | |
843 |
|
844 |
|
845 |
|
846 |
|
847 | composeIso<B>(ab: Iso<A, B>): Traversal<S, B>
|
848 | |
849 |
|
850 |
|
851 |
|
852 |
|
853 | composeGetter<B>(ab: Getter<A, B>): Fold<S, B>
|
854 | }
|
855 |
|
856 |
|
857 |
|
858 |
|
859 | export declare class At<S, I, A> {
|
860 | readonly at: (i: I) => Lens<S, A>
|
861 | |
862 |
|
863 |
|
864 | readonly _tag: 'At'
|
865 | constructor(at: (i: I) => Lens<S, A>)
|
866 | /**
|
867 | * lift an instance of `At` using an `Iso`
|
868 | *
|
869 | * @since 1.2.0
|
870 | */
|
871 | fromIso<T>(iso: Iso<T, S>): At<T, I, A>
|
872 | }
|
873 | /**
|
874 | * @category constructor
|
875 | * @since 1.2.0
|
876 | */
|
877 | export declare class Index<S, I, A> {
|
878 | readonly index: (i: I) => Optional<S, A>
|
879 | /**
|
880 | * @since 1.0.0
|
881 | */
|
882 | readonly _tag: 'Index'
|
883 | constructor(index: (i: I) => Optional<S, A>)
|
884 | /**
|
885 | * @since 1.2.0
|
886 | */
|
887 | static fromAt<T, J, B>(at: At<T, J, Option<B>>): Index<T, J, B>
|
888 | /**
|
889 | * lift an instance of `Index` using an `Iso`
|
890 | *
|
891 | * @since 1.2.0
|
892 | */
|
893 | fromIso<T>(iso: Iso<T, S>): Index<T, I, A>
|
894 | }
|
895 | /**
|
896 | * @category constructor
|
897 | * @since 1.0.0
|
898 | */
|
899 | export declare class Getter<S, A> {
|
900 | readonly get: (s: S) => A
|
901 | /**
|
902 | * @since 1.0.0
|
903 | */
|
904 | readonly _tag: 'Getter'
|
905 | constructor(get: (s: S) => A)
|
906 | /**
|
907 | * view a `Getter` as a `Fold`
|
908 | *
|
909 | * @since 1.0.0
|
910 | */
|
911 | asFold(): Fold<S, A>
|
912 | /**
|
913 | * compose a `Getter` with a `Getter`
|
914 | *
|
915 | * @since 1.0.0
|
916 | */
|
917 | compose<B>(ab: Getter<A, B>): Getter<S, B>
|
918 | /**
|
919 | * Alias of `compose`
|
920 | *
|
921 | * @since 1.0.0
|
922 | */
|
923 | composeGetter<B>(ab: Getter<A, B>): Getter<S, B>
|
924 | /**
|
925 | * compose a `Getter` with a `Fold`
|
926 | *
|
927 | * @since 1.0.0
|
928 | */
|
929 | composeFold<B>(ab: Fold<A, B>): Fold<S, B>
|
930 | /**
|
931 | * compose a `Getter` with a `Lens`
|
932 | *
|
933 | * @since 1.0.0
|
934 | */
|
935 | composeLens<B>(ab: Lens<A, B>): Getter<S, B>
|
936 | /**
|
937 | * compose a `Getter` with a `Iso`
|
938 | *
|
939 | * @since 1.0.0
|
940 | */
|
941 | composeIso<B>(ab: Iso<A, B>): Getter<S, B>
|
942 | /**
|
943 | * compose a `Getter` with a `Optional`
|
944 | *
|
945 | * @since 1.0.0
|
946 | */
|
947 | composeTraversal<B>(ab: Traversal<A, B>): Fold<S, B>
|
948 | /**
|
949 | * compose a `Getter` with a `Optional`
|
950 | *
|
951 | * @since 1.0.0
|
952 | */
|
953 | composeOptional<B>(ab: Optional<A, B>): Fold<S, B>
|
954 | /**
|
955 | * compose a `Getter` with a `Prism`
|
956 | *
|
957 | * @since 1.0.0
|
958 | */
|
959 | composePrism<B>(ab: Prism<A, B>): Fold<S, B>
|
960 | }
|
961 | /**
|
962 | * @category constructor
|
963 | * @since 1.0.0
|
964 | */
|
965 | export declare class Fold<S, A> {
|
966 | readonly foldMap: <M>(M: Monoid<M>) => (f: (a: A) => M) => (s: S) => M
|
967 | /**
|
968 | * @since 1.0.0
|
969 | */
|
970 | readonly _tag: 'Fold'
|
971 | /**
|
972 | * get all the targets of a `Fold`
|
973 | *
|
974 | * @since 1.0.0
|
975 | */
|
976 | readonly getAll: (s: S) => Array<A>
|
977 | /**
|
978 | * check if at least one target satisfies the predicate
|
979 | *
|
980 | * @since 1.0.0
|
981 | */
|
982 | readonly exist: (p: Predicate<A>) => Predicate<S>
|
983 | /**
|
984 | * check if all targets satisfy the predicate
|
985 | *
|
986 | * @since 1.0.0
|
987 | */
|
988 | readonly all: (p: Predicate<A>) => Predicate<S>
|
989 | private readonly foldMapFirst
|
990 | constructor(foldMap: <M>(M: Monoid<M>) => (f: (a: A) => M) => (s: S) => M)
|
991 | /**
|
992 | * compose a `Fold` with a `Fold`
|
993 | *
|
994 | * @since 1.0.0
|
995 | */
|
996 | compose<B>(ab: Fold<A, B>): Fold<S, B>
|
997 | /**
|
998 | * Alias of `compose`
|
999 | *
|
1000 | * @since 1.0.0
|
1001 | */
|
1002 | composeFold<B>(ab: Fold<A, B>): Fold<S, B>
|
1003 | /**
|
1004 | * compose a `Fold` with a `Getter`
|
1005 | *
|
1006 | * @since 1.0.0
|
1007 | */
|
1008 | composeGetter<B>(ab: Getter<A, B>): Fold<S, B>
|
1009 | /**
|
1010 | * compose a `Fold` with a `Traversal`
|
1011 | *
|
1012 | * @since 1.0.0
|
1013 | */
|
1014 | composeTraversal<B>(ab: Traversal<A, B>): Fold<S, B>
|
1015 | /**
|
1016 | * compose a `Fold` with a `Optional`
|
1017 | *
|
1018 | * @since 1.0.0
|
1019 | */
|
1020 | composeOptional<B>(ab: Optional<A, B>): Fold<S, B>
|
1021 | /**
|
1022 | * compose a `Fold` with a `Lens`
|
1023 | *
|
1024 | * @since 1.0.0
|
1025 | */
|
1026 | composeLens<B>(ab: Lens<A, B>): Fold<S, B>
|
1027 | /**
|
1028 | * compose a `Fold` with a `Prism`
|
1029 | *
|
1030 | * @since 1.0.0
|
1031 | */
|
1032 | composePrism<B>(ab: Prism<A, B>): Fold<S, B>
|
1033 | /**
|
1034 | * compose a `Fold` with a `Iso`
|
1035 | *
|
1036 | * @since 1.0.0
|
1037 | */
|
1038 | composeIso<B>(ab: Iso<A, B>): Fold<S, B>
|
1039 | /**
|
1040 | * find the first target of a `Fold` matching the predicate
|
1041 | *
|
1042 | * @since 1.0.0
|
1043 | */
|
1044 | find<B extends A>(p: Refinement<A, B>): (s: S) => Option<B>
|
1045 | find(p: Predicate<A>): (s: S) => Option<A>
|
1046 | /**
|
1047 | * get the first target of a `Fold`
|
1048 | *
|
1049 | * @since 1.0.0
|
1050 | */
|
1051 | headOption(s: S): Option<A>
|
1052 | }
|
1053 | /**
|
1054 | * @category constructor
|
1055 | * @since 1.0.0
|
1056 | */
|
1057 | export declare class Setter<S, A> {
|
1058 | readonly modify: (f: (a: A) => A) => (s: S) => S
|
1059 | /**
|
1060 | * @since 1.0.0
|
1061 | */
|
1062 | readonly _tag: 'Setter'
|
1063 | constructor(modify: (f: (a: A) => A) => (s: S) => S)
|
1064 | /**
|
1065 | * @since 1.0.0
|
1066 | */
|
1067 | set(a: A): (s: S) => S
|
1068 | /**
|
1069 | * compose a `Setter` with a `Setter`
|
1070 | *
|
1071 | * @since 1.0.0
|
1072 | */
|
1073 | compose<B>(ab: Setter<A, B>): Setter<S, B>
|
1074 | /**
|
1075 | * Alias of `compose`
|
1076 | *
|
1077 | * @since 1.0.0
|
1078 | */
|
1079 | composeSetter<B>(ab: Setter<A, B>): Setter<S, B>
|
1080 | /**
|
1081 | * compose a `Setter` with a `Traversal`
|
1082 | *
|
1083 | * @since 1.0.0
|
1084 | */
|
1085 | composeTraversal<B>(ab: Traversal<A, B>): Setter<S, B>
|
1086 | /**
|
1087 | * compose a `Setter` with a `Optional`
|
1088 | *
|
1089 | * @since 1.0.0
|
1090 | */
|
1091 | composeOptional<B>(ab: Optional<A, B>): Setter<S, B>
|
1092 | /**
|
1093 | * compose a `Setter` with a `Lens`
|
1094 | *
|
1095 | * @since 1.0.0
|
1096 | */
|
1097 | composeLens<B>(ab: Lens<A, B>): Setter<S, B>
|
1098 | /**
|
1099 | * compose a `Setter` with a `Prism`
|
1100 | *
|
1101 | * @since 1.0.0
|
1102 | */
|
1103 | composePrism<B>(ab: Prism<A, B>): Setter<S, B>
|
1104 | /**
|
1105 | * compose a `Setter` with a `Iso`
|
1106 | *
|
1107 | * @since 1.0.0
|
1108 | */
|
1109 | composeIso<B>(ab: Iso<A, B>): Setter<S, B>
|
1110 | }
|
1111 | /**
|
1112 | * Create a `Traversal` from a `Traversable`
|
1113 | *
|
1114 | * @example
|
1115 | * import { Lens, fromTraversable } from 'monocle-ts'
|
1116 | * import { Traversable } from 'fp-ts/Array'
|
1117 | *
|
1118 | * interface Tweet {
|
1119 | * text: string
|
1120 | * }
|
1121 | *
|
1122 | * interface Tweets {
|
1123 | * tweets: Tweet[]
|
1124 | * }
|
1125 | *
|
1126 | * const tweetsLens = Lens.fromProp<Tweets>()('tweets')
|
1127 | * const tweetTextLens = Lens.fromProp<Tweet>()('text')
|
1128 | * const tweetTraversal = fromTraversable(Traversable)<Tweet>()
|
1129 | * const composedTraversal = tweetsLens.composeTraversal(tweetTraversal).composeLens(tweetTextLens)
|
1130 | *
|
1131 | * const tweet1: Tweet = { text: 'hello world' }
|
1132 | * const tweet2: Tweet = { text: 'foobar' }
|
1133 | * const model: Tweets = { tweets: [tweet1, tweet2] }
|
1134 | *
|
1135 | * const actual = composedTraversal.modify(text =>
|
1136 | * text
|
1137 | * .split('')
|
1138 | * .reverse()
|
1139 | * .join('')
|
1140 | * )(model)
|
1141 | *
|
1142 | * assert.deepStrictEqual(actual, { tweets: [ { text: 'dlrow olleh' }, { text: 'raboof' } ] })
|
1143 | *
|
1144 | * @category constructor
|
1145 | * @since 1.0.0
|
1146 | */
|
1147 | export declare function fromTraversable<T extends URIS3>(
|
1148 | T: Traversable3<T>
|
1149 | ): <U, L, A>() => Traversal<Kind3<T, U, L, A>, A>
|
1150 | export declare function fromTraversable<T extends URIS2>(T: Traversable2<T>): <L, A>() => Traversal<Kind2<T, L, A>, A>
|
1151 | export declare function fromTraversable<T extends URIS>(T: Traversable1<T>): <A>() => Traversal<Kind<T, A>, A>
|
1152 | export declare function fromTraversable<T>(T: Traversable<T>): <A>() => Traversal<HKT<T, A>, A>
|
1153 | /**
|
1154 | * Create a `Fold` from a `Foldable`
|
1155 | *
|
1156 | * @category constructor
|
1157 | * @since 1.0.0
|
1158 | */
|
1159 | export declare function fromFoldable<F extends URIS3>(F: Foldable3<F>): <U, L, A>() => Fold<Kind3<F, U, L, A>, A>
|
1160 | export declare function fromFoldable<F extends URIS2>(F: Foldable2<F>): <L, A>() => Fold<Kind2<F, L, A>, A>
|
1161 | export declare function fromFoldable<F extends URIS>(F: Foldable1<F>): <A>() => Fold<Kind<F, A>, A>
|
1162 | export declare function fromFoldable<F>(F: Foldable<F>): <A>() => Fold<HKT<F, A>, A>
|