import { Foldable, Foldable1, Foldable2, Foldable3 } from 'fp-ts/es6/Foldable' 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 { Traversable, Traversable1, Traversable2, Traversable3 } from 'fp-ts/es6/Traversable' import * as at from './At' import * as iso from './Iso' import * as index from './Ix' import * as lens from './Lens' import * as optional from './Optional' import * as prism from './Prism' import * as traversal from './Traversal' export { /** * @since 2.3.0 */ at, /** * @since 2.3.0 */ iso, /** * @since 2.3.0 */ index, /** * @since 2.3.0 */ lens, /** * @since 2.3.0 */ prism, /** * @since 2.3.0 */ optional, /** * @since 2.3.0 */ traversal } /** * Laws: * 1. `reverseGet(get(s)) = s` * 2. `get(reversetGet(a)) = a` * * @category constructor * @since 1.0.0 */ export declare class Iso { readonly get: (s: S) => A readonly reverseGet: (a: A) => S /** * @since 1.0.0 */ readonly _tag: 'Iso' /** * @since 1.0.0 */ readonly unwrap: (s: S) => A /** * @since 1.0.0 */ readonly to: (s: S) => A /** * @since 1.0.0 */ readonly wrap: (a: A) => S /** * @since 1.0.0 */ readonly from: (a: A) => S constructor(get: (s: S) => A, reverseGet: (a: A) => S) /** * reverse the `Iso`: the source becomes the target and the target becomes the source * @since 1.0.0 */ reverse(): Iso /** * @since 1.0.0 */ modify(f: (a: A) => A): (s: S) => S /** * view an `Iso` as a `Lens` * * @since 1.0.0 */ asLens(): Lens /** * view an `Iso` as a `Prism` * * @since 1.0.0 */ asPrism(): Prism /** * view an `Iso` as a `Optional` * * @since 1.0.0 */ asOptional(): Optional /** * view an `Iso` as a `Traversal` * * @since 1.0.0 */ asTraversal(): Traversal /** * view an `Iso` as a `Fold` * * @since 1.0.0 */ asFold(): Fold /** * view an `Iso` as a `Getter` * * @since 1.0.0 */ asGetter(): Getter /** * view an `Iso` as a `Setter` * * @since 1.0.0 */ asSetter(): Setter /** * compose an `Iso` with an `Iso` * * @since 1.0.0 */ compose(ab: Iso): Iso /** * Alias of `compose` * * @since 1.0.0 */ composeIso(ab: Iso): Iso /** * compose an `Iso` with a `Lens ` * * @since 1.0.0 */ composeLens(ab: Lens): Lens /** * compose an `Iso` with a `Prism` * * @since 1.0.0 */ composePrism(ab: Prism): Prism /** * compose an `Iso` with an `Optional` * * @since 1.0.0 */ composeOptional(ab: Optional): Optional /** * compose an `Iso` with a `Traversal` * * @since 1.0.0 */ composeTraversal(ab: Traversal): Traversal /** * compose an `Iso` with a `Fold` * * @since 1.0.0 */ composeFold(ab: Fold): Fold /** * compose an `Iso` with a `Getter` * * @since 1.0.0 */ composeGetter(ab: Getter): Getter /** * compose an `Iso` with a `Setter` * * @since 1.0.0 */ composeSetter(ab: Setter): Setter } /** * @since 1.3.0 */ export interface LensFromPath { < K1 extends keyof S, K2 extends keyof S[K1], K3 extends keyof S[K1][K2], K4 extends keyof S[K1][K2][K3], K5 extends keyof S[K1][K2][K3][K4] >( path: [K1, K2, K3, K4, K5] ): Lens ( path: [K1, K2, K3, K4] ): Lens (path: [K1, K2, K3]): Lens (path: [K1, K2]): Lens (path: [K1]): Lens } /** * Laws: * 1. `get(set(a)(s)) = a` * 2. `set(get(s))(s) = s` * 3. `set(a)(set(a)(s)) = set(a)(s)` * * @category constructor * @since 1.0.0 */ export declare class Lens { readonly get: (s: S) => A readonly set: (a: A) => (s: S) => S /** * @since 1.0.0 */ readonly _tag: 'Lens' constructor(get: (s: S) => A, set: (a: A) => (s: S) => S) /** * @example * import { Lens } from 'monocle-ts' * * type Person = { * name: string * age: number * address: { * city: string * } * } * * const city = Lens.fromPath()(['address', 'city']) * * const person: Person = { name: 'Giulio', age: 43, address: { city: 'Milan' } } * * assert.strictEqual(city.get(person), 'Milan') * assert.deepStrictEqual(city.set('London')(person), { name: 'Giulio', age: 43, address: { city: 'London' } }) * * @since 1.0.0 */ static fromPath(): LensFromPath /** * Returns a `Lens` from a type and a prop * * @example * import { Lens } from 'monocle-ts' * * type Person = { * name: string * age: number * } * * const age = Lens.fromProp()('age') * * const person: Person = { name: 'Giulio', age: 43 } * * assert.strictEqual(age.get(person), 43) * assert.deepStrictEqual(age.set(44)(person), { name: 'Giulio', age: 44 }) * * @since 1.0.0 */ static fromProp():

(prop: P) => Lens /** * Returns a `Lens` from a type and an array of props * * @example * import { Lens } from 'monocle-ts' * * interface Person { * name: string * age: number * rememberMe: boolean * } * * const lens = Lens.fromProps()(['name', 'age']) * * const person: Person = { name: 'Giulio', age: 44, rememberMe: true } * * assert.deepStrictEqual(lens.get(person), { name: 'Giulio', age: 44 }) * assert.deepStrictEqual(lens.set({ name: 'Guido', age: 47 })(person), { name: 'Guido', age: 47, rememberMe: true }) * * @since 1.0.0 */ static fromProps():

( props: Array

) => Lens< S, { [K in P]: S[K] } > /** * Returns a `Lens` from a nullable (`A | null | undefined`) prop * * @example * import { Lens } from 'monocle-ts' * * interface Outer { * inner?: Inner * } * * interface Inner { * value: number * foo: string * } * * const inner = Lens.fromNullableProp()('inner', { value: 0, foo: 'foo' }) * const value = Lens.fromProp()('value') * const lens = inner.compose(value) * * assert.deepStrictEqual(lens.set(1)({}), { inner: { value: 1, foo: 'foo' } }) * assert.strictEqual(lens.get({}), 0) * assert.deepStrictEqual(lens.set(1)({ inner: { value: 1, foo: 'bar' } }), { inner: { value: 1, foo: 'bar' } }) * assert.strictEqual(lens.get({ inner: { value: 1, foo: 'bar' } }), 1) * * @since 1.0.0 */ static fromNullableProp(): (k: K, defaultValue: A) => Lens> /** * @since 1.0.0 */ modify(f: (a: A) => A): (s: S) => S /** * view a `Lens` as a Optional * * @since 1.0.0 */ asOptional(): Optional /** * view a `Lens` as a `Traversal` * * @since 1.0.0 */ asTraversal(): Traversal /** * view a `Lens` as a `Setter` * * @since 1.0.0 */ asSetter(): Setter /** * view a `Lens` as a `Getter` * * @since 1.0.0 */ asGetter(): Getter /** * view a `Lens` as a `Fold` * * @since 1.0.0 */ asFold(): Fold /** * compose a `Lens` with a `Lens` * * @since 1.0.0 */ compose(ab: Lens): Lens /** * Alias of `compose` * * @since 1.0.0 */ composeLens(ab: Lens): Lens /** * compose a `Lens` with a `Getter` * * @since 1.0.0 */ composeGetter(ab: Getter): Getter /** * compose a `Lens` with a `Fold` * * @since 1.0.0 */ composeFold(ab: Fold): Fold /** * compose a `Lens` with an `Optional` * * @since 1.0.0 */ composeOptional(ab: Optional): Optional /** * compose a `Lens` with an `Traversal` * * @since 1.0.0 */ composeTraversal(ab: Traversal): Traversal /** * compose a `Lens` with an `Setter` * * @since 1.0.0 */ composeSetter(ab: Setter): Setter /** * compose a `Lens` with an `Iso` * * @since 1.0.0 */ composeIso(ab: Iso): Lens /** * compose a `Lens` with a `Prism` * * @since 1.0.0 */ composePrism(ab: Prism): Optional } /** * Laws: * 1. `pipe(getOption(s), fold(() => s, reverseGet)) = s` * 2. `getOption(reverseGet(a)) = some(a)` * * @category constructor * @since 1.0.0 */ export declare class Prism { readonly getOption: (s: S) => Option readonly reverseGet: (a: A) => S /** * @since 1.0.0 */ readonly _tag: 'Prism' constructor(getOption: (s: S) => Option, reverseGet: (a: A) => S) /** * @since 1.0.0 */ static fromPredicate(refinement: Refinement): Prism static fromPredicate(predicate: Predicate): Prism /** * @since 1.0.0 */ static some(): Prism, A> /** * @since 1.0.0 */ modify(f: (a: A) => A): (s: S) => S /** * @since 1.0.0 */ modifyOption(f: (a: A) => A): (s: S) => Option /** * set the target of a `Prism` with a value * * @since 1.0.0 */ set(a: A): (s: S) => S /** * view a `Prism` as a `Optional` * * @since 1.0.0 */ asOptional(): Optional /** * view a `Prism` as a `Traversal` * * @since 1.0.0 */ asTraversal(): Traversal /** * view a `Prism` as a `Setter` * * @since 1.0.0 */ asSetter(): Setter /** * view a `Prism` as a `Fold` * * @since 1.0.0 */ asFold(): Fold /** * compose a `Prism` with a `Prism` * * @since 1.0.0 */ compose(ab: Prism): Prism /** * Alias of `compose` * * @since 1.0.0 */ composePrism(ab: Prism): Prism /** * compose a `Prism` with a `Optional` * * @since 1.0.0 */ composeOptional(ab: Optional): Optional /** * compose a `Prism` with a `Traversal` * * @since 1.0.0 */ composeTraversal(ab: Traversal): Traversal /** * compose a `Prism` with a `Fold` * * @since 1.0.0 */ composeFold(ab: Fold): Fold /** * compose a `Prism` with a `Setter` * * @since 1.0.0 */ composeSetter(ab: Setter): Setter /** * compose a `Prism` with a `Iso` * * @since 1.0.0 */ composeIso(ab: Iso): Prism /** * compose a `Prism` with a `Lens` * * @since 1.0.0 */ composeLens(ab: Lens): Optional /** * compose a `Prism` with a `Getter` * * @since 1.0.0 */ composeGetter(ab: Getter): Fold } declare type OptionPropertyNames = { [K in keyof S]-?: S[K] extends Option ? K : never }[keyof S] declare type OptionPropertyType> = S[K] extends Option ? A : never /** * @since 2.1.0 */ export interface OptionalFromPath { < K1 extends keyof S, K2 extends keyof NonNullable, K3 extends keyof NonNullable[K2]>, K4 extends keyof NonNullable[K2]>[K3]>, K5 extends keyof NonNullable[K2]>[K3]>[K4]> >( path: [K1, K2, K3, K4, K5] ): Optional[K2]>[K3]>[K4]>[K5]>> < K1 extends keyof S, K2 extends keyof NonNullable, K3 extends keyof NonNullable[K2]>, K4 extends keyof NonNullable[K2]>[K3]> >( path: [K1, K2, K3, K4] ): Optional[K2]>[K3]>[K4]>> , K3 extends keyof NonNullable[K2]>>( path: [K1, K2, K3] ): Optional[K2]>[K3]>> >(path: [K1, K2]): Optional< S, NonNullable[K2]> > (path: [K1]): Optional> } /** * 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)` * * @category constructor * @since 1.0.0 */ export declare class Optional { readonly getOption: (s: S) => Option readonly set: (a: A) => (s: S) => S /** * @since 1.0.0 */ readonly _tag: 'Optional' constructor(getOption: (s: S) => Option, set: (a: A) => (s: S) => S) /** * Returns an `Optional` from a nullable (`A | null | undefined`) prop * * @example * import { Optional } from 'monocle-ts' * * interface Phone { * number: string * } * interface Employment { * phone?: Phone * } * interface Info { * employment?: Employment * } * interface Response { * info?: Info * } * * const numberFromResponse = Optional.fromPath()(['info', 'employment', 'phone', 'number']) * * const response1: Response = { * info: { * employment: { * phone: { * number: '555-1234' * } * } * } * } * const response2: Response = { * info: { * employment: {} * } * } * * numberFromResponse.getOption(response1) // some('555-1234') * numberFromResponse.getOption(response2) // none * * @since 2.1.0 */ static fromPath(): OptionalFromPath /** * @example * import { Optional } from 'monocle-ts' * * interface S { * a: number | undefined | null * } * * const optional = Optional.fromNullableProp()('a') * * const s1: S = { a: undefined } * const s2: S = { a: null } * const s3: S = { a: 1 } * * assert.deepStrictEqual(optional.set(2)(s1), s1) * assert.deepStrictEqual(optional.set(2)(s2), s2) * assert.deepStrictEqual(optional.set(2)(s3), { a: 2 }) * * @since 1.0.0 */ static fromNullableProp(): (k: K) => Optional> /** * Returns an `Optional` from an option (`Option`) prop * * @example * import { Optional } from 'monocle-ts' * import * as O from 'fp-ts/Option' * * interface S { * a: O.Option * } * * const optional = Optional.fromOptionProp()('a') * const s1: S = { a: O.none } * const s2: S = { a: O.some(1) } * assert.deepStrictEqual(optional.set(2)(s1), s1) * assert.deepStrictEqual(optional.set(2)(s2), { a: O.some(2) }) * * @since 1.0.0 */ static fromOptionProp():

>(prop: P) => Optional> /** * @since 1.0.0 */ modify(f: (a: A) => A): (s: S) => S /** * @since 1.0.0 */ modifyOption(f: (a: A) => A): (s: S) => Option /** * view a `Optional` as a `Traversal` * * @since 1.0.0 */ asTraversal(): Traversal /** * view an `Optional` as a `Fold` * * @since 1.0.0 */ asFold(): Fold /** * view an `Optional` as a `Setter` * * @since 1.0.0 */ asSetter(): Setter /** * compose a `Optional` with a `Optional` * * @since 1.0.0 */ compose(ab: Optional): Optional /** * Alias of `compose` * * @since 1.0.0 */ composeOptional(ab: Optional): Optional /** * compose an `Optional` with a `Traversal` * * @since 1.0.0 */ composeTraversal(ab: Traversal): Traversal /** * compose an `Optional` with a `Fold` * * @since 1.0.0 */ composeFold(ab: Fold): Fold /** * compose an `Optional` with a `Setter` * * @since 1.0.0 */ composeSetter(ab: Setter): Setter /** * compose an `Optional` with a `Lens` * * @since 1.0.0 */ composeLens(ab: Lens): Optional /** * compose an `Optional` with a `Prism` * * @since 1.0.0 */ composePrism(ab: Prism): Optional /** * compose an `Optional` with a `Iso` * * @since 1.0.0 */ composeIso(ab: Iso): Optional /** * compose an `Optional` with a `Getter` * * @since 1.0.0 */ composeGetter(ab: Getter): Fold } /** * @since 1.0.0 */ export declare type ModifyF = traversal.ModifyF /** * @category constructor * @since 1.0.0 */ export declare class Traversal { readonly modifyF: ModifyF /** * @since 1.0.0 */ readonly _tag: 'Traversal' constructor(modifyF: ModifyF) /** * @since 1.0.0 */ modify(f: (a: A) => A): (s: S) => S /** * @since 1.0.0 */ set(a: A): (s: S) => S /** * focus the items matched by a `traversal` to those that match a predicate * * @example * import { fromTraversable, Lens } from 'monocle-ts' * import { Traversable } from 'fp-ts/Array' * * interface Person { * name: string; * cool: boolean; * } * * const peopleTraversal = fromTraversable(Traversable)() * const coolLens = Lens.fromProp()('cool') * const people = [{name: 'bill', cool: false}, {name: 'jill', cool: true}] * * const actual = peopleTraversal.filter(p => p.name === 'bill').composeLens(coolLens) * .set(true)(people) * * assert.deepStrictEqual(actual, [{name: 'bill', cool: true}, {name: 'jill', cool: true}]) * * @since 1.0.0 */ filter(refinement: Refinement): Traversal filter(predicate: Predicate): Traversal /** * view a `Traversal` as a `Fold` * * @since 1.0.0 */ asFold(): Fold /** * view a `Traversal` as a `Setter` * * @since 1.0.0 */ asSetter(): Setter /** * compose a `Traversal` with a `Traversal` * * @since 1.0.0 */ compose(ab: Traversal): Traversal /** * Alias of `compose` * * @since 1.0.0 */ composeTraversal(ab: Traversal): Traversal /** * compose a `Traversal` with a `Fold` * * @since 1.0.0 */ composeFold(ab: Fold): Fold /** * compose a `Traversal` with a `Setter` * * @since 1.0.0 */ composeSetter(ab: Setter): Setter /** * compose a `Traversal` with a `Optional` * * @since 1.0.0 */ composeOptional(ab: Optional): Traversal /** * compose a `Traversal` with a `Lens` * * @since 1.0.0 */ composeLens(ab: Lens): Traversal /** * compose a `Traversal` with a `Prism` * * @since 1.0.0 */ composePrism(ab: Prism): Traversal /** * compose a `Traversal` with a `Iso` * * @since 1.0.0 */ composeIso(ab: Iso): Traversal /** * compose a `Traversal` with a `Getter` * * @since 1.0.0 */ composeGetter(ab: Getter): Fold } /** * @category constructor * @since 1.2.0 */ export declare class At { readonly at: (i: I) => Lens /** * @since 1.0.0 */ readonly _tag: 'At' constructor(at: (i: I) => Lens) /** * lift an instance of `At` using an `Iso` * * @since 1.2.0 */ fromIso(iso: Iso): At } /** * @category constructor * @since 1.2.0 */ export declare class Index { readonly index: (i: I) => Optional /** * @since 1.0.0 */ readonly _tag: 'Index' constructor(index: (i: I) => Optional) /** * @since 1.2.0 */ static fromAt(at: At>): Index /** * lift an instance of `Index` using an `Iso` * * @since 1.2.0 */ fromIso(iso: Iso): Index } /** * @category constructor * @since 1.0.0 */ export declare class Getter { readonly get: (s: S) => A /** * @since 1.0.0 */ readonly _tag: 'Getter' constructor(get: (s: S) => A) /** * view a `Getter` as a `Fold` * * @since 1.0.0 */ asFold(): Fold /** * compose a `Getter` with a `Getter` * * @since 1.0.0 */ compose(ab: Getter): Getter /** * Alias of `compose` * * @since 1.0.0 */ composeGetter(ab: Getter): Getter /** * compose a `Getter` with a `Fold` * * @since 1.0.0 */ composeFold(ab: Fold): Fold /** * compose a `Getter` with a `Lens` * * @since 1.0.0 */ composeLens(ab: Lens): Getter /** * compose a `Getter` with a `Iso` * * @since 1.0.0 */ composeIso(ab: Iso): Getter /** * compose a `Getter` with a `Optional` * * @since 1.0.0 */ composeTraversal(ab: Traversal): Fold /** * compose a `Getter` with a `Optional` * * @since 1.0.0 */ composeOptional(ab: Optional): Fold /** * compose a `Getter` with a `Prism` * * @since 1.0.0 */ composePrism(ab: Prism): Fold } /** * @category constructor * @since 1.0.0 */ export declare class Fold { readonly foldMap: (M: Monoid) => (f: (a: A) => M) => (s: S) => M /** * @since 1.0.0 */ readonly _tag: 'Fold' /** * get all the targets of a `Fold` * * @since 1.0.0 */ readonly getAll: (s: S) => Array /** * check if at least one target satisfies the predicate * * @since 1.0.0 */ readonly exist: (p: Predicate) => Predicate /** * check if all targets satisfy the predicate * * @since 1.0.0 */ readonly all: (p: Predicate) => Predicate private readonly foldMapFirst constructor(foldMap: (M: Monoid) => (f: (a: A) => M) => (s: S) => M) /** * compose a `Fold` with a `Fold` * * @since 1.0.0 */ compose(ab: Fold): Fold /** * Alias of `compose` * * @since 1.0.0 */ composeFold(ab: Fold): Fold /** * compose a `Fold` with a `Getter` * * @since 1.0.0 */ composeGetter(ab: Getter): Fold /** * compose a `Fold` with a `Traversal` * * @since 1.0.0 */ composeTraversal(ab: Traversal): Fold /** * compose a `Fold` with a `Optional` * * @since 1.0.0 */ composeOptional(ab: Optional): Fold /** * compose a `Fold` with a `Lens` * * @since 1.0.0 */ composeLens(ab: Lens): Fold /** * compose a `Fold` with a `Prism` * * @since 1.0.0 */ composePrism(ab: Prism): Fold /** * compose a `Fold` with a `Iso` * * @since 1.0.0 */ composeIso(ab: Iso): Fold /** * find the first target of a `Fold` matching the predicate * * @since 1.0.0 */ find(p: Refinement): (s: S) => Option find(p: Predicate): (s: S) => Option /** * get the first target of a `Fold` * * @since 1.0.0 */ headOption(s: S): Option } /** * @category constructor * @since 1.0.0 */ export declare class Setter { readonly modify: (f: (a: A) => A) => (s: S) => S /** * @since 1.0.0 */ readonly _tag: 'Setter' constructor(modify: (f: (a: A) => A) => (s: S) => S) /** * @since 1.0.0 */ set(a: A): (s: S) => S /** * compose a `Setter` with a `Setter` * * @since 1.0.0 */ compose(ab: Setter): Setter /** * Alias of `compose` * * @since 1.0.0 */ composeSetter(ab: Setter): Setter /** * compose a `Setter` with a `Traversal` * * @since 1.0.0 */ composeTraversal(ab: Traversal): Setter /** * compose a `Setter` with a `Optional` * * @since 1.0.0 */ composeOptional(ab: Optional): Setter /** * compose a `Setter` with a `Lens` * * @since 1.0.0 */ composeLens(ab: Lens): Setter /** * compose a `Setter` with a `Prism` * * @since 1.0.0 */ composePrism(ab: Prism): Setter /** * compose a `Setter` with a `Iso` * * @since 1.0.0 */ composeIso(ab: Iso): Setter } /** * Create a `Traversal` from a `Traversable` * * @example * import { Lens, fromTraversable } from 'monocle-ts' * import { Traversable } from 'fp-ts/Array' * * interface Tweet { * text: string * } * * interface Tweets { * tweets: Tweet[] * } * * const tweetsLens = Lens.fromProp()('tweets') * const tweetTextLens = Lens.fromProp()('text') * const tweetTraversal = fromTraversable(Traversable)() * const composedTraversal = tweetsLens.composeTraversal(tweetTraversal).composeLens(tweetTextLens) * * const tweet1: Tweet = { text: 'hello world' } * const tweet2: Tweet = { text: 'foobar' } * const model: Tweets = { tweets: [tweet1, tweet2] } * * const actual = composedTraversal.modify(text => * text * .split('') * .reverse() * .join('') * )(model) * * assert.deepStrictEqual(actual, { tweets: [ { text: 'dlrow olleh' }, { text: 'raboof' } ] }) * * @category constructor * @since 1.0.0 */ export declare function fromTraversable( T: Traversable3 ): () => Traversal, A> export declare function fromTraversable(T: Traversable2): () => Traversal, A> export declare function fromTraversable(T: Traversable1): () => Traversal, A> export declare function fromTraversable(T: Traversable): () => Traversal, A> /** * Create a `Fold` from a `Foldable` * * @category constructor * @since 1.0.0 */ export declare function fromFoldable(F: Foldable3): () => Fold, A> export declare function fromFoldable(F: Foldable2): () => Fold, A> export declare function fromFoldable(F: Foldable1): () => Fold, A> export declare function fromFoldable(F: Foldable): () => Fold, A>