/** * **This module is experimental** * * Experimental features are published in order to get early feedback from the community. * * A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice. * * A `Traversal` is the generalisation of an `Optional` to several targets. In other word, a `Traversal` allows to focus * from a type `S` into `0` to `n` values of type `A`. * * The most common example of a `Traversal` would be to focus into all elements inside of a container (e.g. * `ReadonlyArray`, `Option`). To do this we will use the relation between the typeclass `Traversable` and `Traversal`. * * @since 2.3.0 */ import { Applicative, Applicative1, Applicative2, Applicative2C, Applicative3 } from 'fp-ts/es6/Applicative' import { Category2 } from 'fp-ts/es6/Category' import { Either } from 'fp-ts/es6/Either' import { Predicate, Refinement } from 'fp-ts/es6/function' import { HKT, Kind, Kind2, Kind3, URIS, URIS2, URIS3 } from 'fp-ts/es6/HKT' import { Monoid } from 'fp-ts/es6/Monoid' import { Option } from 'fp-ts/es6/Option' import { ReadonlyNonEmptyArray } from 'fp-ts/es6/ReadonlyNonEmptyArray' import { ReadonlyRecord } from 'fp-ts/es6/ReadonlyRecord' import { Semigroupoid2 } from 'fp-ts/es6/Semigroupoid' import { Traversable, Traversable1, Traversable2, Traversable3 } from 'fp-ts/es6/Traversable' import { Iso } from './Iso' import { Lens } from './Lens' import { Optional } from './Optional' import { Prism } from './Prism' /** * @category model * @since 2.3.0 */ export interface ModifyF { (F: Applicative3): (f: (a: A) => Kind3) => (s: S) => Kind3 (F: Applicative2): (f: (a: A) => Kind2) => (s: S) => Kind2 (F: Applicative2C): (f: (a: A) => Kind2) => (s: S) => Kind2 (F: Applicative1): (f: (a: A) => Kind) => (s: S) => Kind (F: Applicative): (f: (a: A) => HKT) => (s: S) => HKT } /** * @category model * @since 2.3.0 */ export interface Traversal { readonly modifyF: ModifyF } /** * @category constructors * @since 2.3.8 */ export declare const traversal: (modifyF: Traversal['modifyF']) => Traversal /** * @category constructors * @since 2.3.0 */ export declare const id: () => Traversal /** * Create a `Traversal` from a `Traversable`. * * @category constructor * @since 2.3.0 */ export declare const fromTraversable: { (T: Traversable3): () => Traversal, A> (T: Traversable2): () => Traversal, A> (T: Traversable1): () => Traversal, A> (T: Traversable): () => Traversal, A> } /** * Compose a `Traversal` with a `Traversal`. * * @category compositions * @since 2.3.0 */ export declare const compose: (ab: Traversal) => (sa: Traversal) => Traversal /** * Alias of `compose`. * * @category compositions * @since 2.3.8 */ export declare const composeTraversal: (ab: Traversal) => (sa: Traversal) => Traversal /** * Compose a `Traversal` with a `Iso`. * * @category compositions * @since 2.3.8 */ export declare const composeIso: (ab: Iso) => (sa: Traversal) => Traversal /** * Compose a `Traversal` with a `Lens`. * * @category compositions * @since 2.3.8 */ export declare const composeLens: (ab: Lens) => (sa: Traversal) => Traversal /** * Compose a `Traversal` with a `Prism`. * * @category compositions * @since 2.3.8 */ export declare const composePrism: (ab: Prism) => (sa: Traversal) => Traversal /** * Compose a `Traversal` with a `Optional`. * * @category compositions * @since 2.3.8 */ export declare const composeOptional: (ab: Optional) => (sa: Traversal) => Traversal /** * @category combinators * @since 2.3.0 */ export declare const modify: (f: (a: A) => B) => (sa: Traversal) => (s: S) => S /** * @category combinators * @since 2.3.0 */ export declare const set: (a: A) => (sa: Traversal) => (s: S) => S /** * Return a `Traversal` from a `Traversal` focused on a nullable value. * * @category combinators * @since 2.3.0 */ export declare const fromNullable: (sa: Traversal) => Traversal> /** * @category combinators * @since 2.3.0 */ export declare function filter( refinement: Refinement ): (sa: Traversal) => Traversal export declare function filter(predicate: Predicate): (sa: Traversal) => Traversal /** * Return a `Traversal` from a `Traversal` and a prop. * * @category combinators * @since 2.3.0 */ export declare const prop: (prop: P) => (sa: Traversal) => Traversal /** * Return a `Traversal` from a `Traversal` and a list of props. * * @category combinators * @since 2.3.0 */ export declare const props: ( props_0: P, props_1: P, ...props_2: P[] ) => (sa: Traversal) => Traversal /** * Return a `Traversal` from a `Traversal` focused on a component of a tuple. * * @category combinators * @since 2.3.0 */ export declare const component: ( prop: P ) => (sa: Traversal) => Traversal /** * Return a `Traversal` from a `Traversal` focused on an index of a `ReadonlyArray`. * * @category combinators * @since 2.3.0 */ export declare const index: (i: number) => (sa: Traversal) => Traversal /** * @category combinators * @since 2.3.8 */ export declare const indexNonEmpty: (i: number) => (sa: Traversal>) => Traversal /** * Return a `Traversal` from a `Traversal` focused on a key of a `ReadonlyRecord`. * * @category combinators * @since 2.3.0 */ export declare const key: (key: string) => (sa: Traversal>>) => Traversal /** * Return a `Traversal` from a `Traversal` focused on a required key of a `ReadonlyRecord`. * * @category combinators * @since 2.3.0 */ export declare const atKey: ( key: string ) => (sa: Traversal>>) => Traversal> /** * Return a `Traversal` from a `Traversal` focused on the `Some` of a `Option` type. * * @category combinators * @since 2.3.0 */ export declare const some: (soa: Traversal>) => Traversal /** * Return a `Traversal` from a `Traversal` focused on the `Right` of a `Either` type. * * @category combinators * @since 2.3.0 */ export declare const right: (sea: Traversal>) => Traversal /** * Return a `Traversal` from a `Traversal` focused on the `Left` of a `Either` type. * * @category combinators * @since 2.3.0 */ export declare const left: (sea: Traversal>) => Traversal /** * Return a `Traversal` from a `Traversal` focused on a `Traversable`. * * @category combinators * @since 2.3.0 */ export declare const traverse: ( T: Traversable1 ) => (sta: Traversal>) => Traversal /** * @category combinators * @since 2.3.8 */ export declare function findFirst( refinement: Refinement ): (sa: Traversal>) => Traversal export declare function findFirst( predicate: Predicate ): (sa: Traversal>) => Traversal /** * @category combinators * @since 2.3.8 */ export declare function findFirstNonEmpty( refinement: Refinement ): (sa: Traversal>) => Traversal export declare function findFirstNonEmpty( predicate: Predicate ): (sa: Traversal>) => Traversal /** * Map each target to a `Monoid` and combine the results. * * @category combinators * @since 2.3.0 */ export declare const foldMap: (M: Monoid) => (f: (a: A) => M) => (sa: Traversal) => (s: S) => M /** * Map each target to a `Monoid` and combine the results. * * @category combinators * @since 2.3.0 */ export declare const fold: (M: Monoid) => (sa: Traversal) => (s: S) => A /** * Get all the targets of a `Traversal`. * * @category combinators * @since 2.3.0 */ export declare const getAll: (s: S) => (sa: Traversal) => readonly A[] /** * @category instances * @since 2.3.0 */ export declare const URI = 'monocle-ts/Traversal' /** * @category instances * @since 2.3.0 */ export declare type URI = typeof URI declare module 'fp-ts/es6/HKT' { interface URItoKind2 { readonly [URI]: Traversal } } /** * @category instances * @since 2.3.8 */ export declare const Semigroupoid: Semigroupoid2 /** * @category instances * @since 2.3.0 */ export declare const Category: Category2