UNPKG

26.6 kBTypeScriptView Raw
1import { Foldable, Foldable1, Foldable2, Foldable3 } from 'fp-ts/lib/Foldable'
2import { Predicate, Refinement } from 'fp-ts/lib/function'
3import { HKT, Kind, Kind2, Kind3, URIS, URIS2, URIS3 } from 'fp-ts/lib/HKT'
4import { Monoid } from 'fp-ts/lib/Monoid'
5import { Option } from 'fp-ts/lib/Option'
6import { Traversable, Traversable1, Traversable2, Traversable3 } from 'fp-ts/lib/Traversable'
7import * as at from './At'
8import * as iso from './Iso'
9import * as index from './Ix'
10import * as lens from './Lens'
11import * as optional from './Optional'
12import * as prism from './Prism'
13import * as traversal from './Traversal'
14export {
15 /**
16 * @since 2.3.0
17 */
18 at,
19 /**
20 * @since 2.3.0
21 */
22 iso,
23 /**
24 * @since 2.3.0
25 */
26 index,
27 /**
28 * @since 2.3.0
29 */
30 lens,
31 /**
32 * @since 2.3.0
33 */
34 prism,
35 /**
36 * @since 2.3.0
37 */
38 optional,
39 /**
40 * @since 2.3.0
41 */
42 traversal
43}
44/**
45 * Laws:
46 * 1. `reverseGet(get(s)) = s`
47 * 2. `get(reversetGet(a)) = a`
48 *
49 * @category constructor
50 * @since 1.0.0
51 */
52export declare class Iso<S, A> {
53 readonly get: (s: S) => A
54 readonly reverseGet: (a: A) => S
55 /**
56 * @since 1.0.0
57 */
58 readonly _tag: 'Iso'
59 /**
60 * @since 1.0.0
61 */
62 readonly unwrap: (s: S) => A
63 /**
64 * @since 1.0.0
65 */
66 readonly to: (s: S) => A
67 /**
68 * @since 1.0.0
69 */
70 readonly wrap: (a: A) => S
71 /**
72 * @since 1.0.0
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 */
185export 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 * Laws:
204 * 1. `get(set(a)(s)) = a`
205 * 2. `set(get(s))(s) = s`
206 * 3. `set(a)(set(a)(s)) = set(a)(s)`
207 *
208 * @category constructor
209 * @since 1.0.0
210 */
211export declare class Lens<S, A> {
212 readonly get: (s: S) => A
213 readonly set: (a: A) => (s: S) => S
214 /**
215 * @since 1.0.0
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 * Returns a `Lens` from a type and a prop
243 *
244 * @example
245 * import { Lens } from 'monocle-ts'
246 *
247 * type Person = {
248 * name: string
249 * age: number
250 * }
251 *
252 * const age = Lens.fromProp<Person>()('age')
253 *
254 * const person: Person = { name: 'Giulio', age: 43 }
255 *
256 * assert.strictEqual(age.get(person), 43)
257 * assert.deepStrictEqual(age.set(44)(person), { name: 'Giulio', age: 44 })
258 *
259 * @since 1.0.0
260 */
261 static fromProp<S>(): <P extends keyof S>(prop: P) => Lens<S, S[P]>
262 /**
263 * Returns a `Lens` from a type and an array of props
264 *
265 * @example
266 * import { Lens } from 'monocle-ts'
267 *
268 * interface Person {
269 * name: string
270 * age: number
271 * rememberMe: boolean
272 * }
273 *
274 * const lens = Lens.fromProps<Person>()(['name', 'age'])
275 *
276 * const person: Person = { name: 'Giulio', age: 44, rememberMe: true }
277 *
278 * assert.deepStrictEqual(lens.get(person), { name: 'Giulio', age: 44 })
279 * assert.deepStrictEqual(lens.set({ name: 'Guido', age: 47 })(person), { name: 'Guido', age: 47, rememberMe: true })
280 *
281 * @since 1.0.0
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 * Returns a `Lens` from a nullable (`A | null | undefined`) prop
293 *
294 * @example
295 * import { Lens } from 'monocle-ts'
296 *
297 * interface Outer {
298 * inner?: Inner
299 * }
300 *
301 * interface Inner {
302 * value: number
303 * foo: string
304 * }
305 *
306 * const inner = Lens.fromNullableProp<Outer>()('inner', { value: 0, foo: 'foo' })
307 * const value = Lens.fromProp<Inner>()('value')
308 * const lens = inner.compose(value)
309 *
310 * assert.deepStrictEqual(lens.set(1)({}), { inner: { value: 1, foo: 'foo' } })
311 * assert.strictEqual(lens.get({}), 0)
312 * assert.deepStrictEqual(lens.set(1)({ inner: { value: 1, foo: 'bar' } }), { inner: { value: 1, foo: 'bar' } })
313 * assert.strictEqual(lens.get({ inner: { value: 1, foo: 'bar' } }), 1)
314 *
315 * @since 1.0.0
316 */
317 static fromNullableProp<S>(): <A extends S[K], K extends keyof S>(k: K, defaultValue: A) => Lens<S, NonNullable<S[K]>>
318 /**
319 * @since 1.0.0
320 */
321 modify(f: (a: A) => A): (s: S) => S
322 /**
323 * view a `Lens` as a Optional
324 *
325 * @since 1.0.0
326 */
327 asOptional(): Optional<S, A>
328 /**
329 * view a `Lens` as a `Traversal`
330 *
331 * @since 1.0.0
332 */
333 asTraversal(): Traversal<S, A>
334 /**
335 * view a `Lens` as a `Setter`
336 *
337 * @since 1.0.0
338 */
339 asSetter(): Setter<S, A>
340 /**
341 * view a `Lens` as a `Getter`
342 *
343 * @since 1.0.0
344 */
345 asGetter(): Getter<S, A>
346 /**
347 * view a `Lens` as a `Fold`
348 *
349 * @since 1.0.0
350 */
351 asFold(): Fold<S, A>
352 /**
353 * compose a `Lens` with a `Lens`
354 *
355 * @since 1.0.0
356 */
357 compose<B>(ab: Lens<A, B>): Lens<S, B>
358 /**
359 * Alias of `compose`
360 *
361 * @since 1.0.0
362 */
363 composeLens<B>(ab: Lens<A, B>): Lens<S, B>
364 /**
365 * compose a `Lens` with a `Getter`
366 *
367 * @since 1.0.0
368 */
369 composeGetter<B>(ab: Getter<A, B>): Getter<S, B>
370 /**
371 * compose a `Lens` with a `Fold`
372 *
373 * @since 1.0.0
374 */
375 composeFold<B>(ab: Fold<A, B>): Fold<S, B>
376 /**
377 * compose a `Lens` with an `Optional`
378 *
379 * @since 1.0.0
380 */
381 composeOptional<B>(ab: Optional<A, B>): Optional<S, B>
382 /**
383 * compose a `Lens` with an `Traversal`
384 *
385 * @since 1.0.0
386 */
387 composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B>
388 /**
389 * compose a `Lens` with an `Setter`
390 *
391 * @since 1.0.0
392 */
393 composeSetter<B>(ab: Setter<A, B>): Setter<S, B>
394 /**
395 * compose a `Lens` with an `Iso`
396 *
397 * @since 1.0.0
398 */
399 composeIso<B>(ab: Iso<A, B>): Lens<S, B>
400 /**
401 * compose a `Lens` with a `Prism`
402 *
403 * @since 1.0.0
404 */
405 composePrism<B>(ab: Prism<A, B>): Optional<S, B>
406}
407/**
408 * Laws:
409 * 1. `pipe(getOption(s), fold(() => s, reverseGet)) = s`
410 * 2. `getOption(reverseGet(a)) = some(a)`
411 *
412 * @category constructor
413 * @since 1.0.0
414 */
415export declare class Prism<S, A> {
416 readonly getOption: (s: S) => Option<A>
417 readonly reverseGet: (a: A) => S
418 /**
419 * @since 1.0.0
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}
525declare type OptionPropertyNames<S> = {
526 [K in keyof S]-?: S[K] extends Option<any> ? K : never
527}[keyof S]
528declare type OptionPropertyType<S, K extends OptionPropertyNames<S>> = S[K] extends Option<infer A> ? A : never
529/**
530 * @since 2.1.0
531 */
532export 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 * Laws:
561 * 1. `pipe(getOption(s), fold(() => s, a => set(a)(s))) = s`
562 * 2. `getOption(set(a)(s)) = pipe(getOption(s), map(_ => a))`
563 * 3. `set(a)(set(a)(s)) = set(a)(s)`
564 *
565 * @category constructor
566 * @since 1.0.0
567 */
568export declare class Optional<S, A> {
569 readonly getOption: (s: S) => Option<A>
570 readonly set: (a: A) => (s: S) => S
571 /**
572 * @since 1.0.0
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) // some('555-1234')
613 * numberFromResponse.getOption(response2) // none
614 *
615 * @since 2.1.0
616 */
617 static fromPath<S>(): OptionalFromPath<S>
618 /**
619 * @example
620 * import { Optional } from 'monocle-ts'
621 *
622 * interface S {
623 * a: number | undefined | null
624 * }
625 *
626 * const optional = Optional.fromNullableProp<S>()('a')
627 *
628 * const s1: S = { a: undefined }
629 * const s2: S = { a: null }
630 * const s3: S = { a: 1 }
631 *
632 * assert.deepStrictEqual(optional.set(2)(s1), s1)
633 * assert.deepStrictEqual(optional.set(2)(s2), s2)
634 * assert.deepStrictEqual(optional.set(2)(s3), { a: 2 })
635 *
636 * @since 1.0.0
637 */
638 static fromNullableProp<S>(): <K extends keyof S>(k: K) => Optional<S, NonNullable<S[K]>>
639 /**
640 * Returns an `Optional` from an option (`Option<A>`) prop
641 *
642 * @example
643 * import { Optional } from 'monocle-ts'
644 * import * as O from 'fp-ts/Option'
645 *
646 * interface S {
647 * a: O.Option<number>
648 * }
649 *
650 * const optional = Optional.fromOptionProp<S>()('a')
651 * const s1: S = { a: O.none }
652 * const s2: S = { a: O.some(1) }
653 * assert.deepStrictEqual(optional.set(2)(s1), s1)
654 * assert.deepStrictEqual(optional.set(2)(s2), { a: O.some(2) })
655 *
656 * @since 1.0.0
657 */
658 static fromOptionProp<S>(): <P extends OptionPropertyNames<S>>(prop: P) => Optional<S, OptionPropertyType<S, P>>
659 /**
660 * @since 1.0.0
661 */
662 modify(f: (a: A) => A): (s: S) => S
663 /**
664 * @since 1.0.0
665 */
666 modifyOption(f: (a: A) => A): (s: S) => Option<S>
667 /**
668 * view a `Optional` as a `Traversal`
669 *
670 * @since 1.0.0
671 */
672 asTraversal(): Traversal<S, A>
673 /**
674 * view an `Optional` as a `Fold`
675 *
676 * @since 1.0.0
677 */
678 asFold(): Fold<S, A>
679 /**
680 * view an `Optional` as a `Setter`
681 *
682 * @since 1.0.0
683 */
684 asSetter(): Setter<S, A>
685 /**
686 * compose a `Optional` with a `Optional`
687 *
688 * @since 1.0.0
689 */
690 compose<B>(ab: Optional<A, B>): Optional<S, B>
691 /**
692 * Alias of `compose`
693 *
694 * @since 1.0.0
695 */
696 composeOptional<B>(ab: Optional<A, B>): Optional<S, B>
697 /**
698 * compose an `Optional` with a `Traversal`
699 *
700 * @since 1.0.0
701 */
702 composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B>
703 /**
704 * compose an `Optional` with a `Fold`
705 *
706 * @since 1.0.0
707 */
708 composeFold<B>(ab: Fold<A, B>): Fold<S, B>
709 /**
710 * compose an `Optional` with a `Setter`
711 *
712 * @since 1.0.0
713 */
714 composeSetter<B>(ab: Setter<A, B>): Setter<S, B>
715 /**
716 * compose an `Optional` with a `Lens`
717 *
718 * @since 1.0.0
719 */
720 composeLens<B>(ab: Lens<A, B>): Optional<S, B>
721 /**
722 * compose an `Optional` with a `Prism`
723 *
724 * @since 1.0.0
725 */
726 composePrism<B>(ab: Prism<A, B>): Optional<S, B>
727 /**
728 * compose an `Optional` with a `Iso`
729 *
730 * @since 1.0.0
731 */
732 composeIso<B>(ab: Iso<A, B>): Optional<S, B>
733 /**
734 * compose an `Optional` with a `Getter`
735 *
736 * @since 1.0.0
737 */
738 composeGetter<B>(ab: Getter<A, B>): Fold<S, B>
739}
740/**
741 * @since 1.0.0
742 */
743export declare type ModifyF<S, A> = traversal.ModifyF<S, A>
744/**
745 * @category constructor
746 * @since 1.0.0
747 */
748export declare class Traversal<S, A> {
749 readonly modifyF: ModifyF<S, A>
750 /**
751 * @since 1.0.0
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 * view a `Traversal` as a `Fold`
790 *
791 * @since 1.0.0
792 */
793 asFold(): Fold<S, A>
794 /**
795 * view a `Traversal` as a `Setter`
796 *
797 * @since 1.0.0
798 */
799 asSetter(): Setter<S, A>
800 /**
801 * compose a `Traversal` with a `Traversal`
802 *
803 * @since 1.0.0
804 */
805 compose<B>(ab: Traversal<A, B>): Traversal<S, B>
806 /**
807 * Alias of `compose`
808 *
809 * @since 1.0.0
810 */
811 composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B>
812 /**
813 * compose a `Traversal` with a `Fold`
814 *
815 * @since 1.0.0
816 */
817 composeFold<B>(ab: Fold<A, B>): Fold<S, B>
818 /**
819 * compose a `Traversal` with a `Setter`
820 *
821 * @since 1.0.0
822 */
823 composeSetter<B>(ab: Setter<A, B>): Setter<S, B>
824 /**
825 * compose a `Traversal` with a `Optional`
826 *
827 * @since 1.0.0
828 */
829 composeOptional<B>(ab: Optional<A, B>): Traversal<S, B>
830 /**
831 * compose a `Traversal` with a `Lens`
832 *
833 * @since 1.0.0
834 */
835 composeLens<B>(ab: Lens<A, B>): Traversal<S, B>
836 /**
837 * compose a `Traversal` with a `Prism`
838 *
839 * @since 1.0.0
840 */
841 composePrism<B>(ab: Prism<A, B>): Traversal<S, B>
842 /**
843 * compose a `Traversal` with a `Iso`
844 *
845 * @since 1.0.0
846 */
847 composeIso<B>(ab: Iso<A, B>): Traversal<S, B>
848 /**
849 * compose a `Traversal` with a `Getter`
850 *
851 * @since 1.0.0
852 */
853 composeGetter<B>(ab: Getter<A, B>): Fold<S, B>
854}
855/**
856 * @category constructor
857 * @since 1.2.0
858 */
859export declare class At<S, I, A> {
860 readonly at: (i: I) => Lens<S, A>
861 /**
862 * @since 1.0.0
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 */
877export 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 */
899export 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 */
965export 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 */
1057export 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 */
1147export declare function fromTraversable<T extends URIS3>(
1148 T: Traversable3<T>
1149): <U, L, A>() => Traversal<Kind3<T, U, L, A>, A>
1150export declare function fromTraversable<T extends URIS2>(T: Traversable2<T>): <L, A>() => Traversal<Kind2<T, L, A>, A>
1151export declare function fromTraversable<T extends URIS>(T: Traversable1<T>): <A>() => Traversal<Kind<T, A>, A>
1152export 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 */
1159export declare function fromFoldable<F extends URIS3>(F: Foldable3<F>): <U, L, A>() => Fold<Kind3<F, U, L, A>, A>
1160export declare function fromFoldable<F extends URIS2>(F: Foldable2<F>): <L, A>() => Fold<Kind2<F, L, A>, A>
1161export declare function fromFoldable<F extends URIS>(F: Foldable1<F>): <A>() => Fold<Kind<F, A>, A>
1162export declare function fromFoldable<F>(F: Foldable<F>): <A>() => Fold<HKT<F, A>, A>