/** * **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. * * An `Optional` is an optic used to zoom inside a product. Unlike the `Lens`, the element that the `Optional` focuses * on may not exist. * * `Optional`s have two type parameters generally called `S` and `A`: `Optional` where `S` represents the product * and `A` an optional element inside of `S`. * * Laws: * * 1. `pipe(getOption(s), fold(() => s, a => set(a)(s))) = s` * 2. `getOption(set(a)(s)) = pipe(getOption(s), map(_ => a))` * 3. `set(a)(set(a)(s)) = set(a)(s)` * * @since 2.3.0 */ import { Applicative, Applicative1, Applicative2, 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 { Invariant2 } from 'fp-ts/es6/Invariant' import * as O 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 { Traversable1 } from 'fp-ts/es6/Traversable' import { Iso } from './Iso' import { Lens } from './Lens' import { Prism } from './Prism' import { Traversal } from './Traversal' import Option = O.Option /** * @category model * @since 2.3.0 */ export interface Optional { readonly getOption: (s: S) => Option readonly set: (a: A) => (s: S) => S } /** * @category constructors * @since 2.3.8 */ export declare const optional: ( getOption: Optional['getOption'], set: Optional['set'] ) => Optional /** * @category constructors * @since 2.3.0 */ export declare const id: () => Optional /** * View a `Optional` as a `Traversal`. * * @category converters * @since 2.3.0 */ export declare const asTraversal: (sa: Optional) => Traversal /** * Compose a `Optional` with a `Optional`. * * @category compositions * @since 2.3.0 */ export declare const compose: (ab: Optional) => (sa: Optional) => Optional /** * Alias of `compose`. * * @category compositions * @since 2.3.8 */ export declare const composeOptional: (ab: Optional) => (sa: Optional) => Optional /** * Compose a `Optional` with a `Iso`. * * @category compositions * @since 2.3.8 */ export declare const composeIso: (ab: Iso) => (sa: Optional) => Optional /** * Compose a `Optional` with a `Lens`. * * @category compositions * @since 2.3.7 */ export declare const composeLens: (ab: Lens) => (sa: Optional) => Optional /** * Compose a `Optional` with a `Prism`. * * @category compositions * @since 2.3.7 */ export declare const composePrism: (ab: Prism) => (sa: Optional) => Optional /** * Compose a `Optional` with an `Traversal`. * * @category compositions * @since 2.3.8 */ export declare const composeTraversal: (ab: Traversal) => (sa: Optional) => Traversal /** * @category combinators * @since 2.3.0 */ export declare const modifyOption: ( f: (a: A) => B ) => (optional: Optional) => (s: S) => Option /** * @category combinators * @since 2.3.7 */ export declare const setOption: (a: A) => (optional: Optional) => (s: S) => O.Option /** * @category combinators * @since 2.3.0 */ export declare const modify: (f: (a: A) => B) => (optional: Optional) => (s: S) => S /** * @category combinators * @since 2.3.5 */ export declare function modifyF( F: Applicative3 ): (f: (a: A) => Kind3) => (sa: Optional) => (s: S) => Kind3 export declare function modifyF( F: Applicative2 ): (f: (a: A) => Kind2) => (sa: Optional) => (s: S) => Kind2 export declare function modifyF( F: Applicative1 ): (f: (a: A) => Kind) => (sa: Optional) => (s: S) => Kind export declare function modifyF( F: Applicative ): (f: (a: A) => HKT) => (sa: Optional) => (s: S) => HKT /** * Return an `Optional` from a `Optional` focused on a nullable value. * * @category combinators * @since 2.3.3 */ export declare const fromNullable: (sa: Optional) => Optional> /** * @category combinators * @since 2.3.0 */ export declare function filter(refinement: Refinement): (sa: Optional) => Optional export declare function filter(predicate: Predicate): (sa: Optional) => Optional /** * Return a `Optional` from a `Optional` and a prop. * * @category combinators * @since 2.3.0 */ export declare const prop: (prop: P) => (sa: Optional) => Optional /** * Return a `Optional` from a `Optional` 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: Optional) => Optional /** * Return a `Optional` from a `Optional` focused on a component of a tuple. * * @category combinators * @since 2.3.0 */ export declare const component: ( prop: P ) => (sa: Optional) => Optional /** * Return a `Optional` from a `Optional` focused on an index of a `ReadonlyArray`. * * @category combinators * @since 2.3.0 */ export declare const index: (i: number) => (sa: Optional>) => Optional /** * Return a `Optional` from a `Optional` focused on an index of a `ReadonlyNonEmptyArray`. * * @category combinators * @since 2.3.8 */ export declare const indexNonEmpty: (i: number) => (sa: Optional>) => Optional /** * Return a `Optional` from a `Optional` focused on a key of a `ReadonlyRecord`. * * @category combinators * @since 2.3.0 */ export declare const key: (key: string) => (sa: Optional>) => Optional /** * Return a `Optional` from a `Optional` focused on a required key of a `ReadonlyRecord`. * * @category combinators * @since 2.3.0 */ export declare const atKey: ( key: string ) => (sa: Optional>>) => Optional> /** * Return a `Optional` from a `Optional` focused on the `Some` of a `Option` type. * * @category combinators * @since 2.3.0 */ export declare const some: (soa: Optional>) => Optional /** * Return a `Optional` from a `Optional` focused on the `Right` of a `Either` type. * * @category combinators * @since 2.3.0 */ export declare const right: (sea: Optional>) => Optional /** * Return a `Optional` from a `Optional` focused on the `Left` of a `Either` type. * * @category combinators * @since 2.3.0 */ export declare const left: (sea: Optional>) => Optional /** * Return a `Traversal` from a `Optional` focused on a `Traversable`. * * @category combinators * @since 2.3.0 */ export declare function traverse( T: Traversable1 ): (sta: Optional>) => Traversal /** * @category combinators * @since 2.3.2 */ export declare function findFirst( refinement: Refinement ): (sa: Optional>) => Optional export declare function findFirst(predicate: Predicate): (sa: Optional>) => Optional /** * @category combinators * @since 2.3.8 */ export declare function findFirstNonEmpty( refinement: Refinement ): (sa: Optional>) => Optional export declare function findFirstNonEmpty( predicate: Predicate ): (sa: Optional>) => Optional /** * @category Invariant * @since 2.3.0 */ export declare const imap: (f: (a: A) => B, g: (b: B) => A) => (fa: Optional) => Optional /** * @category instances * @since 2.3.0 */ export declare const URI = 'monocle-ts/Optional' /** * @category instances * @since 2.3.0 */ export declare type URI = typeof URI declare module 'fp-ts/es6/HKT' { interface URItoKind2 { readonly [URI]: Optional } } /** * @category instances * @since 2.3.0 */ export declare const Invariant: Invariant2 /** * @category instances * @since 2.3.8 */ export declare const Semigroupoid: Semigroupoid2 /** * @category instances * @since 2.3.0 */ export declare const Category: Category2