monocle-ts
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -16,2 +16,15 @@ # Changelog | ||
# 2.3.0 | ||
- **Experimental** | ||
- add `Iso` module (@gcanti) | ||
- add `Lens` module (@gcanti) | ||
- add `Prism` module (@gcanti) | ||
- add `Optional` module (@gcanti) | ||
- add `Traversal` module (@gcanti) | ||
- add `At` module (@gcanti) | ||
- add `Ix` module (@gcanti) | ||
- **Internal** | ||
- implement old APIs through new APIs (@gcanti) | ||
# 2.2.0 | ||
@@ -18,0 +31,0 @@ |
/** | ||
* @since 2.2.0 | ||
*/ | ||
import { Option } from 'fp-ts/es6/Option'; | ||
import { At } from '../index'; | ||
import { Option } from 'fp-ts/lib/Option' | ||
import { At } from '..' | ||
/** | ||
* @category constructor | ||
* @since 2.2.0 | ||
*/ | ||
export declare const atReadonlyRecord: <A = never>() => At<Readonly<Record<string, A>>, string, Option<A>>; | ||
export declare const atReadonlyRecord: <A = never>() => At<Readonly<Record<string, A>>, string, Option<A>> |
import * as R from './Record'; | ||
/** | ||
* @category constructor | ||
* @since 2.2.0 | ||
*/ | ||
export var atReadonlyRecord = R.atRecord; |
/** | ||
* @since 2.2.0 | ||
*/ | ||
import { Eq } from 'fp-ts/es6/Eq'; | ||
import { At } from '../index'; | ||
import { Eq } from 'fp-ts/lib/Eq' | ||
import { At } from '..' | ||
/** | ||
* @category constructor | ||
* @since 2.2.0 | ||
*/ | ||
export declare const atReadonlySet: <A = never>(E: Eq<A>) => At<ReadonlySet<A>, A, boolean>; | ||
export declare const atReadonlySet: <A = never>(E: Eq<A>) => At<ReadonlySet<A>, A, boolean> |
import * as S from './Set'; | ||
/** | ||
* @category constructor | ||
* @since 2.2.0 | ||
*/ | ||
export var atReadonlySet = S.atSet; |
/** | ||
* @since 1.7.0 | ||
*/ | ||
import { At } from '../index'; | ||
import { Option } from 'fp-ts/es6/Option'; | ||
import { At } from '..' | ||
import { Option } from 'fp-ts/lib/Option' | ||
/** | ||
* @category constructor | ||
* @since 1.7.0 | ||
*/ | ||
export declare function atRecord<A = never>(): At<Record<string, A>, string, Option<A>>; | ||
export declare function atRecord<A = never>(): At<Record<string, A>, string, Option<A>> |
/** | ||
* @since 1.7.0 | ||
*/ | ||
import { At, Lens } from '../index'; | ||
import { isNone } from 'fp-ts/es6/Option'; | ||
import * as R from 'fp-ts/es6/Record'; | ||
import { At, Lens } from '..'; | ||
import { isNone } from 'fp-ts/lib/Option'; | ||
import * as R from 'fp-ts/lib/Record'; | ||
/** | ||
* @category constructor | ||
* @since 1.7.0 | ||
@@ -9,0 +10,0 @@ */ |
/** | ||
* @since 1.2.0 | ||
*/ | ||
import { At } from '../index'; | ||
import { Eq } from 'fp-ts/es6/Eq'; | ||
import { At } from '..' | ||
import { Eq } from 'fp-ts/lib/Eq' | ||
/** | ||
* @category constructor | ||
* @since 1.2.0 | ||
*/ | ||
export declare function atSet<A = never>(E: Eq<A>): At<Set<A>, A, boolean>; | ||
export declare function atSet<A = never>(E: Eq<A>): At<Set<A>, A, boolean> |
/** | ||
* @since 1.2.0 | ||
*/ | ||
import { At, Lens } from '../index'; | ||
import * as S from 'fp-ts/es6/Set'; | ||
import { At, Lens } from '..'; | ||
import * as S from 'fp-ts/lib/Set'; | ||
/** | ||
* @category constructor | ||
* @since 1.2.0 | ||
@@ -8,0 +9,0 @@ */ |
/** | ||
* @since 1.6.0 | ||
*/ | ||
import { Either } from 'fp-ts/es6/Either'; | ||
import { Prism } from '.'; | ||
import { Either } from 'fp-ts/lib/Either' | ||
import { Prism } from '.' | ||
/** | ||
* @category constructor | ||
* @since 1.6.0 | ||
*/ | ||
export declare const _right: <L, A>() => Prism<Either<L, A>, A>; | ||
export declare const _right: <E, A>() => Prism<Either<E, A>, A> | ||
/** | ||
* @category constructor | ||
* @since 1.6.0 | ||
*/ | ||
export declare const _left: <L, A>() => Prism<Either<L, A>, L>; | ||
export declare const _left: <E, A>() => Prism<Either<E, A>, E> |
/** | ||
* @since 1.6.0 | ||
*/ | ||
import { right, left, fold } from 'fp-ts/es6/Either'; | ||
import { fromEither, none, some } from 'fp-ts/es6/Option'; | ||
import { right, left, fold } from 'fp-ts/lib/Either'; | ||
import { fromEither, none, some } from 'fp-ts/lib/Option'; | ||
import { Prism } from '.'; | ||
var r = new Prism(fromEither, right); | ||
/** | ||
* @category constructor | ||
* @since 1.6.0 | ||
@@ -14,4 +15,5 @@ */ | ||
/** | ||
* @category constructor | ||
* @since 1.6.0 | ||
*/ | ||
export var _left = function () { return l; }; |
2011
es6/index.d.ts
@@ -0,12 +1,45 @@ | ||
import { Foldable, Foldable1, Foldable2, Foldable3 } from 'fp-ts/lib/Foldable' | ||
import { Predicate, Refinement } from 'fp-ts/lib/function' | ||
import { HKT, Kind, Kind2, Kind3, URIS, URIS2, URIS3 } from 'fp-ts/lib/HKT' | ||
import { Monoid } from 'fp-ts/lib/Monoid' | ||
import { Option } from 'fp-ts/lib/Option' | ||
import { Traversable, Traversable1, Traversable2, Traversable3 } from 'fp-ts/lib/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 | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
import { HKT, URIS, URIS2, URIS3, Kind3, Kind2, Kind } from 'fp-ts/es6/HKT'; | ||
import { Monoid } from 'fp-ts/es6/Monoid'; | ||
import { Applicative, Applicative1, Applicative2, Applicative3, Applicative2C } from 'fp-ts/es6/Applicative'; | ||
import { Foldable, Foldable1, Foldable2, Foldable3 } from 'fp-ts/es6/Foldable'; | ||
import { Traversable, Traversable1, Traversable2, Traversable3 } from 'fp-ts/es6/Traversable'; | ||
import { Option } from 'fp-ts/es6/Option'; | ||
import { Predicate, Refinement } from 'fp-ts/es6/function'; | ||
/** | ||
* Laws: | ||
@@ -16,133 +49,134 @@ * 1. reverseGet(get(s)) = s | ||
* | ||
* @category constructor | ||
* @since 1.0.0 | ||
*/ | ||
export declare class Iso<S, A> { | ||
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<A, S>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
modify(f: (a: A) => A): (s: S) => S; | ||
/** | ||
* view an `Iso` as a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asLens(): Lens<S, A>; | ||
/** | ||
* view an `Iso` as a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asPrism(): Prism<S, A>; | ||
/** | ||
* view an `Iso` as a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asOptional(): Optional<S, A>; | ||
/** | ||
* view an `Iso` as a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asTraversal(): Traversal<S, A>; | ||
/** | ||
* view an `Iso` as a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asFold(): Fold<S, A>; | ||
/** | ||
* view an `Iso` as a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asGetter(): Getter<S, A>; | ||
/** | ||
* view an `Iso` as a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asSetter(): Setter<S, A>; | ||
/** | ||
* compose an `Iso` with an `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Iso<A, B>): Iso<S, B>; | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Iso<S, B>; | ||
/** | ||
* compose an `Iso` with a `Lens ` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Lens<S, B>; | ||
/** | ||
* compose an `Iso` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Prism<S, B>; | ||
/** | ||
* compose an `Iso` with an `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Optional<S, B>; | ||
/** | ||
* compose an `Iso` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B>; | ||
/** | ||
* compose an `Iso` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B>; | ||
/** | ||
* compose an `Iso` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Getter<S, B>; | ||
/** | ||
* compose an `Iso` with a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B>; | ||
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<A, S> | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
modify(f: (a: A) => A): (s: S) => S | ||
/** | ||
* view an `Iso` as a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asLens(): Lens<S, A> | ||
/** | ||
* view an `Iso` as a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asPrism(): Prism<S, A> | ||
/** | ||
* view an `Iso` as a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asOptional(): Optional<S, A> | ||
/** | ||
* view an `Iso` as a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asTraversal(): Traversal<S, A> | ||
/** | ||
* view an `Iso` as a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asFold(): Fold<S, A> | ||
/** | ||
* view an `Iso` as a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asGetter(): Getter<S, A> | ||
/** | ||
* view an `Iso` as a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asSetter(): Setter<S, A> | ||
/** | ||
* compose an `Iso` with an `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Iso<A, B>): Iso<S, B> | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Iso<S, B> | ||
/** | ||
* compose an `Iso` with a `Lens ` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Lens<S, B> | ||
/** | ||
* compose an `Iso` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Prism<S, B> | ||
/** | ||
* compose an `Iso` with an `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Optional<S, B> | ||
/** | ||
* compose an `Iso` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B> | ||
/** | ||
* compose an `Iso` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B> | ||
/** | ||
* compose an `Iso` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Getter<S, B> | ||
/** | ||
* compose an `Iso` with a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B> | ||
} | ||
@@ -153,7 +187,17 @@ /** | ||
export interface LensFromPath<S> { | ||
<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<S, S[K1][K2][K3][K4][K5]>; | ||
<K1 extends keyof S, K2 extends keyof S[K1], K3 extends keyof S[K1][K2], K4 extends keyof S[K1][K2][K3]>(path: [K1, K2, K3, K4]): Lens<S, S[K1][K2][K3][K4]>; | ||
<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]>; | ||
<K1 extends keyof S, K2 extends keyof S[K1]>(path: [K1, K2]): Lens<S, S[K1][K2]>; | ||
<K1 extends keyof S>(path: [K1]): Lens<S, S[K1]>; | ||
< | ||
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<S, S[K1][K2][K3][K4][K5]> | ||
<K1 extends keyof S, K2 extends keyof S[K1], K3 extends keyof S[K1][K2], K4 extends keyof S[K1][K2][K3]>( | ||
path: [K1, K2, K3, K4] | ||
): Lens<S, S[K1][K2][K3][K4]> | ||
<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]> | ||
<K1 extends keyof S, K2 extends keyof S[K1]>(path: [K1, K2]): Lens<S, S[K1][K2]> | ||
<K1 extends keyof S>(path: [K1]): Lens<S, S[K1]> | ||
} | ||
@@ -166,194 +210,200 @@ /** | ||
* | ||
* @category constructor | ||
* @since 1.0.0 | ||
*/ | ||
export declare class Lens<S, A> { | ||
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<Person>()(['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<S>(): LensFromPath<S>; | ||
/** | ||
* 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<Person>()('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<S>(): <P extends keyof S>(prop: P) => Lens<S, S[P]>; | ||
/** | ||
* 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<Person>()(['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<S>(): <P extends keyof S>(props: Array<P>) => 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<Outer>()('inner', { value: 0, foo: 'foo' }) | ||
* const value = Lens.fromProp<Inner>()('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<S>(): <A extends S[K], K extends keyof S>(k: K, defaultValue: A) => Lens<S, NonNullable<S[K]>>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
modify(f: (a: A) => A): (s: S) => S; | ||
/** | ||
* view a `Lens` as a Optional | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asOptional(): Optional<S, A>; | ||
/** | ||
* view a `Lens` as a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asTraversal(): Traversal<S, A>; | ||
/** | ||
* view a `Lens` as a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asSetter(): Setter<S, A>; | ||
/** | ||
* view a `Lens` as a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asGetter(): Getter<S, A>; | ||
/** | ||
* view a `Lens` as a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asFold(): Fold<S, A>; | ||
/** | ||
* compose a `Lens` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Lens<A, B>): Lens<S, B>; | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Lens<S, B>; | ||
/** | ||
* compose a `Lens` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Getter<S, B>; | ||
/** | ||
* compose a `Lens` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Lens` with an `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Optional<S, B>; | ||
/** | ||
* compose a `Lens` with an `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B>; | ||
/** | ||
* compose a `Lens` with an `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B>; | ||
/** | ||
* compose a `Lens` with an `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Lens<S, B>; | ||
/** | ||
* compose a `Lens` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Optional<S, B>; | ||
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<Person>()(['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<S>(): LensFromPath<S> | ||
/** | ||
* 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<Person>()('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<S>(): <P extends keyof S>(prop: P) => Lens<S, S[P]> | ||
/** | ||
* 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<Person>()(['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<S>(): <P extends keyof S>( | ||
props: Array<P> | ||
) => 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<Outer>()('inner', { value: 0, foo: 'foo' }) | ||
* const value = Lens.fromProp<Inner>()('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<S>(): <A extends S[K], K extends keyof S>(k: K, defaultValue: A) => Lens<S, NonNullable<S[K]>> | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
modify(f: (a: A) => A): (s: S) => S | ||
/** | ||
* view a `Lens` as a Optional | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asOptional(): Optional<S, A> | ||
/** | ||
* view a `Lens` as a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asTraversal(): Traversal<S, A> | ||
/** | ||
* view a `Lens` as a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asSetter(): Setter<S, A> | ||
/** | ||
* view a `Lens` as a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asGetter(): Getter<S, A> | ||
/** | ||
* view a `Lens` as a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asFold(): Fold<S, A> | ||
/** | ||
* compose a `Lens` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Lens<A, B>): Lens<S, B> | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Lens<S, B> | ||
/** | ||
* compose a `Lens` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Getter<S, B> | ||
/** | ||
* compose a `Lens` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Lens` with an `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Optional<S, B> | ||
/** | ||
* compose a `Lens` with an `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B> | ||
/** | ||
* compose a `Lens` with an `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B> | ||
/** | ||
* compose a `Lens` with an `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Lens<S, B> | ||
/** | ||
* compose a `Lens` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Optional<S, B> | ||
} | ||
@@ -365,118 +415,119 @@ /** | ||
* | ||
* @category constructor | ||
* @since 1.0.0 | ||
*/ | ||
export declare class Prism<S, A> { | ||
readonly getOption: (s: S) => Option<A>; | ||
readonly reverseGet: (a: A) => S; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
readonly _tag: 'Prism'; | ||
constructor(getOption: (s: S) => Option<A>, reverseGet: (a: A) => S); | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
static fromPredicate<S, A extends S>(refinement: Refinement<S, A>): Prism<S, A>; | ||
static fromPredicate<A>(predicate: Predicate<A>): Prism<A, A>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
static some<A>(): Prism<Option<A>, 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<S>; | ||
/** | ||
* 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<S, A>; | ||
/** | ||
* view a `Prism` as a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asTraversal(): Traversal<S, A>; | ||
/** | ||
* view a `Prism` as a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asSetter(): Setter<S, A>; | ||
/** | ||
* view a `Prism` as a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asFold(): Fold<S, A>; | ||
/** | ||
* compose a `Prism` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Prism<A, B>): Prism<S, B>; | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Prism<S, B>; | ||
/** | ||
* compose a `Prism` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Optional<S, B>; | ||
/** | ||
* compose a `Prism` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B>; | ||
/** | ||
* compose a `Prism` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Prism` with a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B>; | ||
/** | ||
* compose a `Prism` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Prism<S, B>; | ||
/** | ||
* compose a `Prism` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Optional<S, B>; | ||
/** | ||
* compose a `Prism` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Fold<S, B>; | ||
readonly getOption: (s: S) => Option<A> | ||
readonly reverseGet: (a: A) => S | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
readonly _tag: 'Prism' | ||
constructor(getOption: (s: S) => Option<A>, reverseGet: (a: A) => S) | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
static fromPredicate<S, A extends S>(refinement: Refinement<S, A>): Prism<S, A> | ||
static fromPredicate<A>(predicate: Predicate<A>): Prism<A, A> | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
static some<A>(): Prism<Option<A>, 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<S> | ||
/** | ||
* 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<S, A> | ||
/** | ||
* view a `Prism` as a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asTraversal(): Traversal<S, A> | ||
/** | ||
* view a `Prism` as a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asSetter(): Setter<S, A> | ||
/** | ||
* view a `Prism` as a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asFold(): Fold<S, A> | ||
/** | ||
* compose a `Prism` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Prism<A, B>): Prism<S, B> | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Prism<S, B> | ||
/** | ||
* compose a `Prism` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Optional<S, B> | ||
/** | ||
* compose a `Prism` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B> | ||
/** | ||
* compose a `Prism` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Prism` with a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B> | ||
/** | ||
* compose a `Prism` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Prism<S, B> | ||
/** | ||
* compose a `Prism` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Optional<S, B> | ||
/** | ||
* compose a `Prism` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Fold<S, B> | ||
} | ||
declare type OptionPropertyNames<S> = { | ||
[K in keyof S]-?: S[K] extends Option<any> ? K : never; | ||
}[keyof S]; | ||
declare type OptionPropertyType<S, K extends OptionPropertyNames<S>> = S[K] extends Option<infer A> ? A : never; | ||
[K in keyof S]-?: S[K] extends Option<any> ? K : never | ||
}[keyof S] | ||
declare type OptionPropertyType<S, K extends OptionPropertyNames<S>> = S[K] extends Option<infer A> ? A : never | ||
/** | ||
@@ -486,7 +537,27 @@ * @since 2.1.0 | ||
export interface OptionalFromPath<S> { | ||
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>, K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>, K4 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>, K5 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>(path: [K1, K2, K3, K4, K5]): Optional<S, NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>[K5]>>; | ||
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>, K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>, K4 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>>(path: [K1, K2, K3, K4]): Optional<S, NonNullable<NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>>; | ||
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>, K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>>(path: [K1, K2, K3]): Optional<S, NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>>; | ||
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>>(path: [K1, K2]): Optional<S, NonNullable<NonNullable<S[K1]>[K2]>>; | ||
<K1 extends keyof S>(path: [K1]): Optional<S, NonNullable<S[K1]>>; | ||
< | ||
K1 extends keyof S, | ||
K2 extends keyof NonNullable<S[K1]>, | ||
K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>, | ||
K4 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>, | ||
K5 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4] | ||
>( | ||
path: [K1, K2, K3, K4, K5] | ||
): Optional<S, NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>[K5]>> | ||
< | ||
K1 extends keyof S, | ||
K2 extends keyof NonNullable<S[K1]>, | ||
K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>, | ||
K4 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]> | ||
>( | ||
path: [K1, K2, K3, K4] | ||
): Optional<S, NonNullable<NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>> | ||
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>, K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>>( | ||
path: [K1, K2, K3] | ||
): Optional<S, NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>> | ||
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>>(path: [K1, K2]): Optional< | ||
S, | ||
NonNullable<NonNullable<S[K1]>[K2]> | ||
> | ||
<K1 extends keyof S>(path: [K1]): Optional<S, NonNullable<S[K1]>> | ||
} | ||
@@ -499,175 +570,176 @@ /** | ||
* | ||
* @category constructor | ||
* @since 1.0.0 | ||
*/ | ||
export declare class Optional<S, A> { | ||
readonly getOption: (s: S) => Option<A>; | ||
readonly set: (a: A) => (s: S) => S; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
readonly _tag: 'Optional'; | ||
constructor(getOption: (s: S) => Option<A>, 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<Response>()(['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<S>(): OptionalFromPath<S>; | ||
/** | ||
* @example | ||
* import { Optional } from 'monocle-ts' | ||
* | ||
* interface S { | ||
* a: number | undefined | null | ||
* } | ||
* | ||
* const optional = Optional.fromNullableProp<S>()('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<S>(): <K extends keyof S>(k: K) => Optional<S, NonNullable<S[K]>>; | ||
/** | ||
* Returns an `Optional` from an option (`Option<A>`) prop | ||
* | ||
* @example | ||
* import { Optional } from 'monocle-ts' | ||
* import * as O from 'fp-ts/es6/Option' | ||
* | ||
* interface S { | ||
* a: O.Option<number> | ||
* } | ||
* | ||
* const optional = Optional.fromOptionProp<S>()('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<S>(): <P extends OptionPropertyNames<S>>(prop: P) => Optional<S, OptionPropertyType<S, P>>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
modify(f: (a: A) => A): (s: S) => S; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
modifyOption(f: (a: A) => A): (s: S) => Option<S>; | ||
/** | ||
* view a `Optional` as a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asTraversal(): Traversal<S, A>; | ||
/** | ||
* view an `Optional` as a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asFold(): Fold<S, A>; | ||
/** | ||
* view an `Optional` as a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asSetter(): Setter<S, A>; | ||
/** | ||
* compose a `Optional` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Optional<A, B>): Optional<S, B>; | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Optional<S, B>; | ||
/** | ||
* compose an `Optional` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B>; | ||
/** | ||
* compose an `Optional` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B>; | ||
/** | ||
* compose an `Optional` with a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B>; | ||
/** | ||
* compose an `Optional` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Optional<S, B>; | ||
/** | ||
* compose an `Optional` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Optional<S, B>; | ||
/** | ||
* compose an `Optional` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Optional<S, B>; | ||
/** | ||
* compose an `Optional` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Fold<S, B>; | ||
readonly getOption: (s: S) => Option<A> | ||
readonly set: (a: A) => (s: S) => S | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
readonly _tag: 'Optional' | ||
constructor(getOption: (s: S) => Option<A>, 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<Response>()(['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<S>(): OptionalFromPath<S> | ||
/** | ||
* @example | ||
* import { Optional } from 'monocle-ts' | ||
* | ||
* interface S { | ||
* a: number | undefined | null | ||
* } | ||
* | ||
* const optional = Optional.fromNullableProp<S>()('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<S>(): <K extends keyof S>(k: K) => Optional<S, NonNullable<S[K]>> | ||
/** | ||
* Returns an `Optional` from an option (`Option<A>`) prop | ||
* | ||
* @example | ||
* import { Optional } from 'monocle-ts' | ||
* import * as O from 'fp-ts/lib/Option' | ||
* | ||
* interface S { | ||
* a: O.Option<number> | ||
* } | ||
* | ||
* const optional = Optional.fromOptionProp<S>()('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<S>(): <P extends OptionPropertyNames<S>>(prop: P) => Optional<S, OptionPropertyType<S, P>> | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
modify(f: (a: A) => A): (s: S) => S | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
modifyOption(f: (a: A) => A): (s: S) => Option<S> | ||
/** | ||
* view a `Optional` as a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asTraversal(): Traversal<S, A> | ||
/** | ||
* view an `Optional` as a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asFold(): Fold<S, A> | ||
/** | ||
* view an `Optional` as a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asSetter(): Setter<S, A> | ||
/** | ||
* compose a `Optional` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Optional<A, B>): Optional<S, B> | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Optional<S, B> | ||
/** | ||
* compose an `Optional` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B> | ||
/** | ||
* compose an `Optional` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B> | ||
/** | ||
* compose an `Optional` with a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B> | ||
/** | ||
* compose an `Optional` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Optional<S, B> | ||
/** | ||
* compose an `Optional` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Optional<S, B> | ||
/** | ||
* compose an `Optional` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Optional<S, B> | ||
/** | ||
* compose an `Optional` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Fold<S, B> | ||
} | ||
@@ -677,376 +749,376 @@ /** | ||
*/ | ||
export interface ModifyF<S, A> { | ||
<F extends URIS3>(F: Applicative3<F>): <U, L>(f: (a: A) => Kind3<F, U, L, A>) => (s: S) => Kind3<F, U, L, S>; | ||
<F extends URIS2>(F: Applicative2<F>): <L>(f: (a: A) => Kind2<F, L, A>) => (s: S) => Kind2<F, L, S>; | ||
<F extends URIS2, L>(F: Applicative2C<F, L>): (f: (a: A) => Kind2<F, L, A>) => (s: S) => Kind2<F, L, S>; | ||
<F extends URIS>(F: Applicative1<F>): (f: (a: A) => Kind<F, A>) => (s: S) => Kind<F, S>; | ||
<F>(F: Applicative<F>): (f: (a: A) => HKT<F, A>) => (s: S) => HKT<F, S>; | ||
} | ||
export declare type ModifyF<S, A> = traversal.ModifyF<S, A> | ||
/** | ||
* @category constructor | ||
* @since 1.0.0 | ||
*/ | ||
export declare class Traversal<S, A> { | ||
readonly modifyF: ModifyF<S, A>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
readonly _tag: 'Traversal'; | ||
constructor(modifyF: ModifyF<S, A>); | ||
/** | ||
* @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 { array } from 'fp-ts/es6/Array' | ||
* | ||
* interface Person { | ||
* name: string; | ||
* cool: boolean; | ||
* } | ||
* | ||
* const peopleTraversal = fromTraversable(array)<Person>() | ||
* const coolLens = Lens.fromProp<Person>()('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<B extends A>(refinement: Refinement<A, B>): Traversal<S, B>; | ||
filter(predicate: Predicate<A>): Traversal<S, A>; | ||
/** | ||
* view a `Traversal` as a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asFold(): Fold<S, A>; | ||
/** | ||
* view a `Traversal` as a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asSetter(): Setter<S, A>; | ||
/** | ||
* compose a `Traversal` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Traversal<A, B>): Traversal<S, B>; | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B>; | ||
/** | ||
* compose a `Traversal` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Traversal` with a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B>; | ||
/** | ||
* compose a `Traversal` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Traversal<S, B>; | ||
/** | ||
* compose a `Traversal` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Traversal<S, B>; | ||
/** | ||
* compose a `Traversal` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Traversal<S, B>; | ||
/** | ||
* compose a `Traversal` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Traversal<S, B>; | ||
/** | ||
* compose a `Traversal` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Fold<S, B>; | ||
readonly modifyF: ModifyF<S, A> | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
readonly _tag: 'Traversal' | ||
constructor(modifyF: ModifyF<S, A>) | ||
/** | ||
* @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 { array } from 'fp-ts/lib/Array' | ||
* | ||
* interface Person { | ||
* name: string; | ||
* cool: boolean; | ||
* } | ||
* | ||
* const peopleTraversal = fromTraversable(array)<Person>() | ||
* const coolLens = Lens.fromProp<Person>()('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<B extends A>(refinement: Refinement<A, B>): Traversal<S, B> | ||
filter(predicate: Predicate<A>): Traversal<S, A> | ||
/** | ||
* view a `Traversal` as a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asFold(): Fold<S, A> | ||
/** | ||
* view a `Traversal` as a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asSetter(): Setter<S, A> | ||
/** | ||
* compose a `Traversal` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Traversal<A, B>): Traversal<S, B> | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B> | ||
/** | ||
* compose a `Traversal` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Traversal` with a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B> | ||
/** | ||
* compose a `Traversal` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Traversal<S, B> | ||
/** | ||
* compose a `Traversal` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Traversal<S, B> | ||
/** | ||
* compose a `Traversal` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Traversal<S, B> | ||
/** | ||
* compose a `Traversal` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Traversal<S, B> | ||
/** | ||
* compose a `Traversal` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Fold<S, B> | ||
} | ||
/** | ||
* @category constructor | ||
* @since 1.2.0 | ||
*/ | ||
export declare class At<S, I, A> { | ||
readonly at: (i: I) => Lens<S, A>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
readonly _tag: 'At'; | ||
constructor(at: (i: I) => Lens<S, A>); | ||
/** | ||
* lift an instance of `At` using an `Iso` | ||
* | ||
* @since 1.2.0 | ||
*/ | ||
fromIso<T>(iso: Iso<T, S>): At<T, I, A>; | ||
readonly at: (i: I) => Lens<S, A> | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
readonly _tag: 'At' | ||
constructor(at: (i: I) => Lens<S, A>) | ||
/** | ||
* lift an instance of `At` using an `Iso` | ||
* | ||
* @since 1.2.0 | ||
*/ | ||
fromIso<T>(iso: Iso<T, S>): At<T, I, A> | ||
} | ||
/** | ||
* @category constructor | ||
* @since 1.2.0 | ||
*/ | ||
export declare class Index<S, I, A> { | ||
readonly index: (i: I) => Optional<S, A>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
readonly _tag: 'Index'; | ||
constructor(index: (i: I) => Optional<S, A>); | ||
/** | ||
* @since 1.2.0 | ||
*/ | ||
static fromAt<T, J, B>(at: At<T, J, Option<B>>): Index<T, J, B>; | ||
/** | ||
* lift an instance of `Index` using an `Iso` | ||
* | ||
* @since 1.2.0 | ||
*/ | ||
fromIso<T>(iso: Iso<T, S>): Index<T, I, A>; | ||
readonly index: (i: I) => Optional<S, A> | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
readonly _tag: 'Index' | ||
constructor(index: (i: I) => Optional<S, A>) | ||
/** | ||
* @since 1.2.0 | ||
*/ | ||
static fromAt<T, J, B>(at: At<T, J, Option<B>>): Index<T, J, B> | ||
/** | ||
* lift an instance of `Index` using an `Iso` | ||
* | ||
* @since 1.2.0 | ||
*/ | ||
fromIso<T>(iso: Iso<T, S>): Index<T, I, A> | ||
} | ||
/** | ||
* @category constructor | ||
* @since 1.0.0 | ||
*/ | ||
export declare class Getter<S, A> { | ||
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<S, A>; | ||
/** | ||
* compose a `Getter` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Getter<A, B>): Getter<S, B>; | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Getter<S, B>; | ||
/** | ||
* compose a `Getter` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Getter` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Getter<S, B>; | ||
/** | ||
* compose a `Getter` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Getter<S, B>; | ||
/** | ||
* compose a `Getter` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Getter` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Getter` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Fold<S, B>; | ||
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<S, A> | ||
/** | ||
* compose a `Getter` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Getter<A, B>): Getter<S, B> | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Getter<S, B> | ||
/** | ||
* compose a `Getter` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Getter` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Getter<S, B> | ||
/** | ||
* compose a `Getter` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Getter<S, B> | ||
/** | ||
* compose a `Getter` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Getter` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Getter` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Fold<S, B> | ||
} | ||
/** | ||
* @category constructor | ||
* @since 1.0.0 | ||
*/ | ||
export declare class Fold<S, A> { | ||
readonly foldMap: <M>(M: Monoid<M>) => (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<A>; | ||
/** | ||
* check if at least one target satisfies the predicate | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
readonly exist: (p: Predicate<A>) => Predicate<S>; | ||
/** | ||
* check if all targets satisfy the predicate | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
readonly all: (p: Predicate<A>) => Predicate<S>; | ||
private foldMapFirst; | ||
constructor(foldMap: <M>(M: Monoid<M>) => (f: (a: A) => M) => (s: S) => M); | ||
/** | ||
* compose a `Fold` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Fold<A, B>): Fold<S, B>; | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Fold` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Fold` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Fold` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Fold` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Fold` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Fold` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Fold<S, B>; | ||
/** | ||
* find the first target of a `Fold` matching the predicate | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
find<B extends A>(p: Refinement<A, B>): (s: S) => Option<B>; | ||
find(p: Predicate<A>): (s: S) => Option<A>; | ||
/** | ||
* get the first target of a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
headOption(s: S): Option<A>; | ||
readonly foldMap: <M>(M: Monoid<M>) => (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<A> | ||
/** | ||
* check if at least one target satisfies the predicate | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
readonly exist: (p: Predicate<A>) => Predicate<S> | ||
/** | ||
* check if all targets satisfy the predicate | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
readonly all: (p: Predicate<A>) => Predicate<S> | ||
private foldMapFirst | ||
constructor(foldMap: <M>(M: Monoid<M>) => (f: (a: A) => M) => (s: S) => M) | ||
/** | ||
* compose a `Fold` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Fold<A, B>): Fold<S, B> | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Fold` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Fold` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Fold` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Fold` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Fold` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Fold` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Fold<S, B> | ||
/** | ||
* find the first target of a `Fold` matching the predicate | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
find<B extends A>(p: Refinement<A, B>): (s: S) => Option<B> | ||
find(p: Predicate<A>): (s: S) => Option<A> | ||
/** | ||
* get the first target of a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
headOption(s: S): Option<A> | ||
} | ||
/** | ||
* @category constructor | ||
* @since 1.0.0 | ||
*/ | ||
export declare class Setter<S, A> { | ||
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<B>(ab: Setter<A, B>): Setter<S, B>; | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B>; | ||
/** | ||
* compose a `Setter` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Setter<S, B>; | ||
/** | ||
* compose a `Setter` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Setter<S, B>; | ||
/** | ||
* compose a `Setter` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Setter<S, B>; | ||
/** | ||
* compose a `Setter` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Setter<S, B>; | ||
/** | ||
* compose a `Setter` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Setter<S, B>; | ||
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<B>(ab: Setter<A, B>): Setter<S, B> | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B> | ||
/** | ||
* compose a `Setter` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Setter<S, B> | ||
/** | ||
* compose a `Setter` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Setter<S, B> | ||
/** | ||
* compose a `Setter` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Setter<S, B> | ||
/** | ||
* compose a `Setter` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Setter<S, B> | ||
/** | ||
* compose a `Setter` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Setter<S, B> | ||
} | ||
/** | ||
* create a `Traversal` from a `Traversable` | ||
* Create a `Traversal` from a `Traversable` | ||
* | ||
* @example | ||
* import { Lens, fromTraversable } from 'monocle-ts' | ||
* import { array } from 'fp-ts/es6/Array' | ||
* import { array } from 'fp-ts/lib/Array' | ||
* | ||
@@ -1079,17 +1151,20 @@ * interface Tweet { | ||
* | ||
* @category constructor | ||
* @since 1.0.0 | ||
*/ | ||
export declare function fromTraversable<T extends URIS3>(T: Traversable3<T>): <U, L, A>() => Traversal<Kind3<T, U, L, A>, A>; | ||
export declare function fromTraversable<T extends URIS2>(T: Traversable2<T>): <L, A>() => Traversal<Kind2<T, L, A>, A>; | ||
export declare function fromTraversable<T extends URIS>(T: Traversable1<T>): <A>() => Traversal<Kind<T, A>, A>; | ||
export declare function fromTraversable<T>(T: Traversable<T>): <A>() => Traversal<HKT<T, A>, A>; | ||
export declare function fromTraversable<T extends URIS3>( | ||
T: Traversable3<T> | ||
): <U, L, A>() => Traversal<Kind3<T, U, L, A>, A> | ||
export declare function fromTraversable<T extends URIS2>(T: Traversable2<T>): <L, A>() => Traversal<Kind2<T, L, A>, A> | ||
export declare function fromTraversable<T extends URIS>(T: Traversable1<T>): <A>() => Traversal<Kind<T, A>, A> | ||
export declare function fromTraversable<T>(T: Traversable<T>): <A>() => Traversal<HKT<T, A>, A> | ||
/** | ||
* create a `Fold` from a `Foldable` | ||
* Create a `Fold` from a `Foldable` | ||
* | ||
* @category constructor | ||
* @since 1.0.0 | ||
*/ | ||
export declare function fromFoldable<F extends URIS3>(F: Foldable3<F>): <U, L, A>() => Fold<Kind3<F, U, L, A>, A>; | ||
export declare function fromFoldable<F extends URIS2>(F: Foldable2<F>): <L, A>() => Fold<Kind2<F, L, A>, A>; | ||
export declare function fromFoldable<F extends URIS>(F: Foldable1<F>): <A>() => Fold<Kind<F, A>, A>; | ||
export declare function fromFoldable<F>(F: Foldable<F>): <A>() => Fold<HKT<F, A>, A>; | ||
export {}; | ||
export declare function fromFoldable<F extends URIS3>(F: Foldable3<F>): <U, L, A>() => Fold<Kind3<F, U, L, A>, A> | ||
export declare function fromFoldable<F extends URIS2>(F: Foldable2<F>): <L, A>() => Fold<Kind2<F, L, A>, A> | ||
export declare function fromFoldable<F extends URIS>(F: Foldable1<F>): <A>() => Fold<Kind<F, A>, A> | ||
export declare function fromFoldable<F>(F: Foldable<F>): <A>() => Fold<HKT<F, A>, A> |
278
es6/index.js
@@ -1,7 +0,61 @@ | ||
import { monoidAll, monoidAny } from 'fp-ts/es6/Monoid'; | ||
import { none, some, fromNullable, getFirstMonoid, fromPredicate, isNone, option } from 'fp-ts/es6/Option'; | ||
import { identity, constant } from 'fp-ts/es6/function'; | ||
import { identity as id } from 'fp-ts/es6/Identity'; | ||
import { getApplicative, make } from 'fp-ts/es6/Const'; | ||
import { getMonoid } from 'fp-ts/es6/Array'; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
import { getMonoid } from 'fp-ts/lib/Array'; | ||
import { getApplicative, make } from 'fp-ts/lib/Const'; | ||
import { constant, identity } from 'fp-ts/lib/function'; | ||
import { monoidAll, monoidAny } from 'fp-ts/lib/Monoid'; | ||
import { fromNullable, fromPredicate, getFirstMonoid, isNone, option, some } from 'fp-ts/lib/Option'; | ||
import { pipe } from 'fp-ts/lib/pipeable'; | ||
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 }; | ||
// | ||
// compat | ||
// | ||
var fromIso = function (iso) { return new Iso(iso.get, iso.reverseGet); }; | ||
var fromLens = function (lens) { return new Lens(lens.get, lens.set); }; | ||
var fromPrism = function (prism) { return new Prism(prism.getOption, prism.reverseGet); }; | ||
var fromOptional = function (optional) { | ||
return new Optional(optional.getOption, optional.set); | ||
}; | ||
var fromTraversal = function (traversal) { return new Traversal(traversal.modifyF); }; | ||
var fromAt = function (at) { return new At(function (i) { return fromLens(at.at(i)); }); }; | ||
var fromIndex = function (ix) { return new Index(function (i) { return fromOptional(ix.index(i)); }); }; | ||
// | ||
// old APIs | ||
// | ||
var update = function (o, k, a) { | ||
@@ -16,2 +70,3 @@ var _a; | ||
* | ||
* @category constructor | ||
* @since 1.0.0 | ||
@@ -49,3 +104,3 @@ */ | ||
Iso.prototype.reverse = function () { | ||
return new Iso(this.reverseGet, this.get); | ||
return fromIso(iso.reverse(this)); | ||
}; | ||
@@ -56,4 +111,3 @@ /** | ||
Iso.prototype.modify = function (f) { | ||
var _this = this; | ||
return function (s) { return _this.reverseGet(f(_this.get(s))); }; | ||
return iso.modify(f)(this); | ||
}; | ||
@@ -66,4 +120,3 @@ /** | ||
Iso.prototype.asLens = function () { | ||
var _this = this; | ||
return new Lens(this.get, function (a) { return function (_) { return _this.reverseGet(a); }; }); | ||
return fromLens(iso.asLens(this)); | ||
}; | ||
@@ -76,4 +129,3 @@ /** | ||
Iso.prototype.asPrism = function () { | ||
var _this = this; | ||
return new Prism(function (s) { return some(_this.get(s)); }, this.reverseGet); | ||
return fromPrism(iso.asPrism(this)); | ||
}; | ||
@@ -86,4 +138,3 @@ /** | ||
Iso.prototype.asOptional = function () { | ||
var _this = this; | ||
return new Optional(function (s) { return some(_this.get(s)); }, function (a) { return function (_) { return _this.reverseGet(a); }; }); | ||
return fromOptional(iso.asOptional(this)); | ||
}; | ||
@@ -96,6 +147,3 @@ /** | ||
Iso.prototype.asTraversal = function () { | ||
var _this = this; | ||
return new Traversal(function (F) { return function (f) { return function (s) { | ||
return F.map(f(_this.get(s)), function (a) { return _this.reverseGet(a); }); | ||
}; }; }); | ||
return fromTraversal(iso.asTraversal(this)); | ||
}; | ||
@@ -135,4 +183,3 @@ /** | ||
Iso.prototype.compose = function (ab) { | ||
var _this = this; | ||
return new Iso(function (s) { return ab.get(_this.get(s)); }, function (b) { return _this.reverseGet(ab.reverseGet(b)); }); | ||
return fromIso(iso.compose(ab)(this)); | ||
}; | ||
@@ -153,3 +200,3 @@ /** | ||
Iso.prototype.composeLens = function (ab) { | ||
return this.asLens().compose(ab); | ||
return fromLens(pipe(this, iso.asLens, lens.compose(ab))); | ||
}; | ||
@@ -162,3 +209,3 @@ /** | ||
Iso.prototype.composePrism = function (ab) { | ||
return this.asPrism().compose(ab); | ||
return fromPrism(pipe(this, iso.asPrism, prism.compose(ab))); | ||
}; | ||
@@ -171,3 +218,3 @@ /** | ||
Iso.prototype.composeOptional = function (ab) { | ||
return this.asOptional().compose(ab); | ||
return fromOptional(pipe(this, iso.asOptional, optional.compose(ab))); | ||
}; | ||
@@ -180,3 +227,3 @@ /** | ||
Iso.prototype.composeTraversal = function (ab) { | ||
return this.asTraversal().compose(ab); | ||
return fromTraversal(pipe(this, iso.asTraversal, traversal.compose(ab))); | ||
}; | ||
@@ -216,2 +263,3 @@ /** | ||
* | ||
* @category constructor | ||
* @since 1.0.0 | ||
@@ -277,47 +325,6 @@ */ | ||
Lens.fromProp = function () { | ||
return function (prop) { | ||
return new Lens(function (s) { return s[prop]; }, function (a) { return function (s) { return update(s, prop, a); }; }); | ||
}; | ||
return function (prop) { return fromLens(pipe(lens.id(), lens.prop(prop))); }; | ||
}; | ||
/** | ||
* 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<Person>()(['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 | ||
*/ | ||
Lens.fromProps = function () { | ||
return function (props) { | ||
var len = props.length; | ||
return new Lens(function (s) { | ||
var r = {}; | ||
for (var i = 0; i < len; i++) { | ||
var k = props[i]; | ||
r[k] = s[k]; | ||
} | ||
return r; | ||
}, function (a) { return function (s) { | ||
for (var i = 0; i < len; i++) { | ||
var k = props[i]; | ||
if (a[k] !== s[k]) { | ||
return Object.assign({}, s, a); | ||
} | ||
} | ||
return s; | ||
}; }); | ||
}; | ||
return function (props) { return fromLens(pipe(lens.id(), lens.props.apply(lens, props))); }; | ||
}; | ||
@@ -367,8 +374,3 @@ /** | ||
Lens.prototype.modify = function (f) { | ||
var _this = this; | ||
return function (s) { | ||
var v = _this.get(s); | ||
var n = f(v); | ||
return v === n ? s : _this.set(n)(s); | ||
}; | ||
return lens.modify(f)(this); | ||
}; | ||
@@ -381,4 +383,3 @@ /** | ||
Lens.prototype.asOptional = function () { | ||
var _this = this; | ||
return new Optional(function (s) { return some(_this.get(s)); }, this.set); | ||
return fromOptional(lens.asOptional(this)); | ||
}; | ||
@@ -391,6 +392,3 @@ /** | ||
Lens.prototype.asTraversal = function () { | ||
var _this = this; | ||
return new Traversal(function (F) { return function (f) { return function (s) { | ||
return F.map(f(_this.get(s)), function (a) { return _this.set(a)(s); }); | ||
}; }; }); | ||
return fromTraversal(lens.asTraversal(this)); | ||
}; | ||
@@ -430,4 +428,3 @@ /** | ||
Lens.prototype.compose = function (ab) { | ||
var _this = this; | ||
return new Lens(function (s) { return ab.get(_this.get(s)); }, function (b) { return function (s) { return _this.set(ab.set(b)(_this.get(s)))(s); }; }); | ||
return fromLens(lens.compose(ab)(this)); | ||
}; | ||
@@ -464,3 +461,3 @@ /** | ||
Lens.prototype.composeOptional = function (ab) { | ||
return this.asOptional().compose(ab); | ||
return fromOptional(pipe(this, lens.asOptional, optional.compose(ab))); | ||
}; | ||
@@ -473,3 +470,3 @@ /** | ||
Lens.prototype.composeTraversal = function (ab) { | ||
return this.asTraversal().compose(ab); | ||
return fromTraversal(pipe(this, lens.asTraversal, traversal.compose(ab))); | ||
}; | ||
@@ -490,3 +487,3 @@ /** | ||
Lens.prototype.composeIso = function (ab) { | ||
return this.compose(ab.asLens()); | ||
return fromLens(pipe(this, lens.compose(pipe(ab, iso.asLens)))); | ||
}; | ||
@@ -499,3 +496,3 @@ /** | ||
Lens.prototype.composePrism = function (ab) { | ||
return this.asOptional().compose(ab.asOptional()); | ||
return fromOptional(lens.composePrism(ab)(this)); | ||
}; | ||
@@ -510,2 +507,3 @@ return Lens; | ||
* | ||
* @category constructor | ||
* @since 1.0.0 | ||
@@ -523,3 +521,3 @@ */ | ||
Prism.fromPredicate = function (predicate) { | ||
return new Prism(function (s) { return (predicate(s) ? some(s) : none); }, identity); | ||
return fromPrism(prism.fromPredicate(predicate)); | ||
}; | ||
@@ -573,4 +571,3 @@ /** | ||
Prism.prototype.asOptional = function () { | ||
var _this = this; | ||
return new Optional(this.getOption, function (a) { return _this.set(a); }); | ||
return fromOptional(prism.asOptional(this)); | ||
}; | ||
@@ -583,12 +580,3 @@ /** | ||
Prism.prototype.asTraversal = function () { | ||
var _this = this; | ||
return new Traversal(function (F) { return function (f) { return function (s) { | ||
var oa = _this.getOption(s); | ||
if (isNone(oa)) { | ||
return F.of(s); | ||
} | ||
else { | ||
return F.map(f(oa.value), function (a) { return _this.set(a)(s); }); | ||
} | ||
}; }; }); | ||
return fromTraversal(prism.asTraversal(this)); | ||
}; | ||
@@ -622,4 +610,3 @@ /** | ||
Prism.prototype.compose = function (ab) { | ||
var _this = this; | ||
return new Prism(function (s) { return option.chain(_this.getOption(s), function (a) { return ab.getOption(a); }); }, function (b) { return _this.reverseGet(ab.reverseGet(b)); }); | ||
return fromPrism(prism.compose(ab)(this)); | ||
}; | ||
@@ -640,3 +627,3 @@ /** | ||
Prism.prototype.composeOptional = function (ab) { | ||
return this.asOptional().compose(ab); | ||
return fromOptional(pipe(this, prism.asOptional, optional.compose(ab))); | ||
}; | ||
@@ -649,3 +636,3 @@ /** | ||
Prism.prototype.composeTraversal = function (ab) { | ||
return this.asTraversal().compose(ab); | ||
return fromTraversal(pipe(this, prism.asTraversal, traversal.compose(ab))); | ||
}; | ||
@@ -674,3 +661,3 @@ /** | ||
Prism.prototype.composeIso = function (ab) { | ||
return this.compose(ab.asPrism()); | ||
return fromPrism(pipe(this, prism.compose(pipe(ab, iso.asPrism)))); | ||
}; | ||
@@ -683,3 +670,3 @@ /** | ||
Prism.prototype.composeLens = function (ab) { | ||
return this.asOptional().compose(ab.asOptional()); | ||
return fromOptional(prism.composeLens(ab)(this)); | ||
}; | ||
@@ -704,2 +691,3 @@ /** | ||
* | ||
* @category constructor | ||
* @since 1.0.0 | ||
@@ -794,3 +782,3 @@ */ | ||
* import { Optional } from 'monocle-ts' | ||
* import * as O from 'fp-ts/es6/Option' | ||
* import * as O from 'fp-ts/lib/Option' | ||
* | ||
@@ -817,12 +805,3 @@ * interface S { | ||
Optional.prototype.modify = function (f) { | ||
var _this = this; | ||
return function (s) { | ||
var os = _this.modifyOption(f)(s); | ||
if (isNone(os)) { | ||
return s; | ||
} | ||
else { | ||
return os.value; | ||
} | ||
}; | ||
return optional.modify(f)(this); | ||
}; | ||
@@ -833,9 +812,3 @@ /** | ||
Optional.prototype.modifyOption = function (f) { | ||
var _this = this; | ||
return function (s) { | ||
return option.map(_this.getOption(s), function (a) { | ||
var n = f(a); | ||
return n === a ? s : _this.set(n)(s); | ||
}); | ||
}; | ||
return optional.modifyOption(f)(this); | ||
}; | ||
@@ -848,12 +821,3 @@ /** | ||
Optional.prototype.asTraversal = function () { | ||
var _this = this; | ||
return new Traversal(function (F) { return function (f) { return function (s) { | ||
var oa = _this.getOption(s); | ||
if (isNone(oa)) { | ||
return F.of(s); | ||
} | ||
else { | ||
return F.map(f(oa.value), function (a) { return _this.set(a)(s); }); | ||
} | ||
}; }; }); | ||
return fromTraversal(optional.asTraversal(this)); | ||
}; | ||
@@ -887,4 +851,3 @@ /** | ||
Optional.prototype.compose = function (ab) { | ||
var _this = this; | ||
return new Optional(function (s) { return option.chain(_this.getOption(s), function (a) { return ab.getOption(a); }); }, function (b) { return _this.modify(ab.set(b)); }); | ||
return fromOptional(optional.compose(ab)(this)); | ||
}; | ||
@@ -905,3 +868,3 @@ /** | ||
Optional.prototype.composeTraversal = function (ab) { | ||
return this.asTraversal().compose(ab); | ||
return fromTraversal(pipe(this, optional.asTraversal, traversal.compose(ab))); | ||
}; | ||
@@ -930,3 +893,3 @@ /** | ||
Optional.prototype.composeLens = function (ab) { | ||
return this.compose(ab.asOptional()); | ||
return fromOptional(pipe(this, optional.compose(pipe(ab, lens.asOptional)))); | ||
}; | ||
@@ -939,3 +902,3 @@ /** | ||
Optional.prototype.composePrism = function (ab) { | ||
return this.compose(ab.asOptional()); | ||
return fromOptional(pipe(this, optional.compose(pipe(ab, prism.asOptional)))); | ||
}; | ||
@@ -948,3 +911,3 @@ /** | ||
Optional.prototype.composeIso = function (ab) { | ||
return this.compose(ab.asOptional()); | ||
return fromOptional(pipe(this, optional.compose(pipe(ab, iso.asOptional)))); | ||
}; | ||
@@ -963,2 +926,3 @@ /** | ||
/** | ||
* @category constructor | ||
* @since 1.0.0 | ||
@@ -980,3 +944,3 @@ */ | ||
Traversal.prototype.modify = function (f) { | ||
return this.modifyF(id)(f); | ||
return traversal.modify(f)(this); | ||
}; | ||
@@ -987,6 +951,6 @@ /** | ||
Traversal.prototype.set = function (a) { | ||
return this.modify(constant(a)); | ||
return traversal.set(a)(this); | ||
}; | ||
Traversal.prototype.filter = function (predicate) { | ||
return this.composePrism(Prism.fromPredicate(predicate)); | ||
return fromTraversal(traversal.filter(predicate)(this)); | ||
}; | ||
@@ -1017,4 +981,3 @@ /** | ||
Traversal.prototype.compose = function (ab) { | ||
var _this = this; | ||
return new Traversal(function (F) { return function (f) { return _this.modifyF(F)(ab.modifyF(F)(f)); }; }); | ||
return fromTraversal(traversal.compose(ab)(this)); | ||
}; | ||
@@ -1059,3 +1022,3 @@ /** | ||
Traversal.prototype.composeLens = function (ab) { | ||
return this.compose(ab.asTraversal()); | ||
return fromTraversal(pipe(this, traversal.compose(pipe(ab, lens.asTraversal)))); | ||
}; | ||
@@ -1068,3 +1031,3 @@ /** | ||
Traversal.prototype.composePrism = function (ab) { | ||
return this.compose(ab.asTraversal()); | ||
return fromTraversal(pipe(this, traversal.compose(pipe(ab, prism.asTraversal)))); | ||
}; | ||
@@ -1077,3 +1040,3 @@ /** | ||
Traversal.prototype.composeIso = function (ab) { | ||
return this.compose(ab.asTraversal()); | ||
return fromTraversal(pipe(this, traversal.compose(pipe(ab, iso.asTraversal)))); | ||
}; | ||
@@ -1092,2 +1055,3 @@ /** | ||
/** | ||
* @category constructor | ||
* @since 1.2.0 | ||
@@ -1109,4 +1073,3 @@ */ | ||
At.prototype.fromIso = function (iso) { | ||
var _this = this; | ||
return new At(function (i) { return iso.composeLens(_this.at(i)); }); | ||
return fromAt(at.fromIso(iso)(this)); | ||
}; | ||
@@ -1117,2 +1080,3 @@ return At; | ||
/** | ||
* @category constructor | ||
* @since 1.2.0 | ||
@@ -1132,3 +1096,3 @@ */ | ||
Index.fromAt = function (at) { | ||
return new Index(function (i) { return at.at(i).composePrism(Prism.some()); }); | ||
return fromIndex(index.fromAt(at)); | ||
}; | ||
@@ -1141,4 +1105,3 @@ /** | ||
Index.prototype.fromIso = function (iso) { | ||
var _this = this; | ||
return new Index(function (i) { return iso.composeOptional(_this.index(i)); }); | ||
return fromIndex(index.fromIso(iso)(this)); | ||
}; | ||
@@ -1149,2 +1112,3 @@ return Index; | ||
/** | ||
* @category constructor | ||
* @since 1.0.0 | ||
@@ -1238,2 +1202,3 @@ */ | ||
/** | ||
* @category constructor | ||
* @since 1.0.0 | ||
@@ -1333,2 +1298,3 @@ */ | ||
/** | ||
* @category constructor | ||
* @since 1.0.0 | ||
@@ -1411,8 +1377,4 @@ */ | ||
export function fromTraversable(T) { | ||
return function () { | ||
return new Traversal(function (F) { | ||
var traverseF = T.traverse(F); | ||
return function (f) { return function (s) { return traverseF(s, f); }; }; | ||
}); | ||
}; | ||
var f = traversal.fromTraversable(T); | ||
return function () { return fromTraversal(f()); }; | ||
} | ||
@@ -1419,0 +1381,0 @@ export function fromFoldable(F) { |
/** | ||
* @since 1.2.0 | ||
*/ | ||
import { Index } from '../index'; | ||
import { Index } from '..' | ||
/** | ||
* @category constructor | ||
* @since 1.2.0 | ||
*/ | ||
export declare function indexArray<A = never>(): Index<Array<A>, number, A>; | ||
export declare function indexArray<A = never>(): Index<Array<A>, number, A> |
/** | ||
* @since 1.2.0 | ||
*/ | ||
import { Index, Optional } from '../index'; | ||
import { lookup, updateAt } from 'fp-ts/es6/Array'; | ||
import { isNone } from 'fp-ts/es6/Option'; | ||
import { Index, Optional } from '..'; | ||
import { lookup, updateAt } from 'fp-ts/lib/Array'; | ||
import { isNone } from 'fp-ts/lib/Option'; | ||
/** | ||
* @category constructor | ||
* @since 1.2.0 | ||
@@ -9,0 +10,0 @@ */ |
/** | ||
* @since 1.5.0 | ||
*/ | ||
import { Index } from '../index'; | ||
import { NonEmptyArray } from 'fp-ts/es6/NonEmptyArray'; | ||
import { Index } from '..' | ||
import { NonEmptyArray } from 'fp-ts/lib/NonEmptyArray' | ||
/** | ||
* @category constructor | ||
* @since 1.5.0 | ||
*/ | ||
export declare function indexNonEmptyArray<A = never>(): Index<NonEmptyArray<A>, number, A>; | ||
export declare function indexNonEmptyArray<A = never>(): Index<NonEmptyArray<A>, number, A> |
/** | ||
* @since 1.5.0 | ||
*/ | ||
import { Index, Optional } from '../index'; | ||
import { updateAt } from 'fp-ts/es6/NonEmptyArray'; | ||
import { lookup } from 'fp-ts/es6/Array'; | ||
import { isNone } from 'fp-ts/es6/Option'; | ||
import { Index, Optional } from '..'; | ||
import { updateAt } from 'fp-ts/lib/NonEmptyArray'; | ||
import { lookup } from 'fp-ts/lib/Array'; | ||
import { isNone } from 'fp-ts/lib/Option'; | ||
/** | ||
* @category constructor | ||
* @since 1.5.0 | ||
@@ -10,0 +11,0 @@ */ |
/** | ||
* @since 2.2.0 | ||
*/ | ||
import { Index } from '../index'; | ||
import { Index } from '..' | ||
/** | ||
* @category constructor | ||
* @since 2.2.0 | ||
*/ | ||
export declare const indexReadonlyArray: <A = never>() => Index<ReadonlyArray<A>, number, A>; | ||
export declare const indexReadonlyArray: <A = never>() => Index<ReadonlyArray<A>, number, A> |
import * as A from './Array'; | ||
/** | ||
* @category constructor | ||
* @since 2.2.0 | ||
*/ | ||
export var indexReadonlyArray = A.indexArray; |
/** | ||
* @since 2.2.0 | ||
*/ | ||
import { Index } from '../index'; | ||
import { Index } from '..' | ||
/** | ||
* @category model | ||
* @since 2.2.0 | ||
*/ | ||
export interface ReadonlyNonEmptyArray<A> extends ReadonlyArray<A> { | ||
readonly 0: A; | ||
readonly 0: A | ||
} | ||
/** | ||
* @category constructor | ||
* @since 2.2.0 | ||
*/ | ||
export declare const indexReadonlyNonEmptyArray: <A = never>() => Index<ReadonlyNonEmptyArray<A>, number, A>; | ||
export declare const indexReadonlyNonEmptyArray: <A = never>() => Index<ReadonlyNonEmptyArray<A>, number, A> |
import * as NEA from './NonEmptyArray'; | ||
/** | ||
* @category constructor | ||
* @since 2.2.0 | ||
*/ | ||
export var indexReadonlyNonEmptyArray = NEA.indexNonEmptyArray; |
/** | ||
* @since 2.2.0 | ||
*/ | ||
import { Index } from '../index'; | ||
import { Index } from '..' | ||
/** | ||
* @category constructor | ||
* @since 2.2.0 | ||
*/ | ||
export declare const indexReadonlyRecord: <A = never>() => Index<Readonly<Record<string, A>>, string, A>; | ||
export declare const indexReadonlyRecord: <A = never>() => Index<Readonly<Record<string, A>>, string, A> |
import * as R from './Record'; | ||
/** | ||
* @category constructor | ||
* @since 2.2.0 | ||
*/ | ||
export var indexReadonlyRecord = R.indexRecord; |
/** | ||
* @since 1.7.0 | ||
*/ | ||
import { Index } from '../index'; | ||
import { Index } from '..' | ||
/** | ||
* @category constructor | ||
* @since 1.7.0 | ||
*/ | ||
export declare function indexRecord<A = never>(): Index<Record<string, A>, string, A>; | ||
export declare function indexRecord<A = never>(): Index<Record<string, A>, string, A> |
/** | ||
* @since 1.7.0 | ||
*/ | ||
import { Index } from '../index'; | ||
import { Index } from '..'; | ||
import { atRecord } from '../At/Record'; | ||
/** | ||
* @category constructor | ||
* @since 1.7.0 | ||
@@ -8,0 +9,0 @@ */ |
/** | ||
* @since 2.2.0 | ||
*/ | ||
import { Option } from 'fp-ts/lib/Option'; | ||
import { At } from '../index'; | ||
import { Option } from 'fp-ts/lib/Option' | ||
import { At } from '..' | ||
/** | ||
* @category constructor | ||
* @since 2.2.0 | ||
*/ | ||
export declare const atReadonlyRecord: <A = never>() => At<Readonly<Record<string, A>>, string, Option<A>>; | ||
export declare const atReadonlyRecord: <A = never>() => At<Readonly<Record<string, A>>, string, Option<A>> |
@@ -6,4 +6,5 @@ "use strict"; | ||
/** | ||
* @category constructor | ||
* @since 2.2.0 | ||
*/ | ||
exports.atReadonlyRecord = R.atRecord; |
/** | ||
* @since 2.2.0 | ||
*/ | ||
import { Eq } from 'fp-ts/lib/Eq'; | ||
import { At } from '../index'; | ||
import { Eq } from 'fp-ts/lib/Eq' | ||
import { At } from '..' | ||
/** | ||
* @category constructor | ||
* @since 2.2.0 | ||
*/ | ||
export declare const atReadonlySet: <A = never>(E: Eq<A>) => At<ReadonlySet<A>, A, boolean>; | ||
export declare const atReadonlySet: <A = never>(E: Eq<A>) => At<ReadonlySet<A>, A, boolean> |
@@ -6,4 +6,5 @@ "use strict"; | ||
/** | ||
* @category constructor | ||
* @since 2.2.0 | ||
*/ | ||
exports.atReadonlySet = S.atSet; |
/** | ||
* @since 1.7.0 | ||
*/ | ||
import { At } from '../index'; | ||
import { Option } from 'fp-ts/lib/Option'; | ||
import { At } from '..' | ||
import { Option } from 'fp-ts/lib/Option' | ||
/** | ||
* @category constructor | ||
* @since 1.7.0 | ||
*/ | ||
export declare function atRecord<A = never>(): At<Record<string, A>, string, Option<A>>; | ||
export declare function atRecord<A = never>(): At<Record<string, A>, string, Option<A>> |
@@ -7,11 +7,12 @@ "use strict"; | ||
*/ | ||
var index_1 = require("../index"); | ||
var __1 = require(".."); | ||
var Option_1 = require("fp-ts/lib/Option"); | ||
var R = require("fp-ts/lib/Record"); | ||
/** | ||
* @category constructor | ||
* @since 1.7.0 | ||
*/ | ||
function atRecord() { | ||
return new index_1.At(function (k) { | ||
return new index_1.Lens(function (r) { return R.lookup(k, r); }, function (oa) { return function (r) { | ||
return new __1.At(function (k) { | ||
return new __1.Lens(function (r) { return R.lookup(k, r); }, function (oa) { return function (r) { | ||
if (Option_1.isNone(oa)) { | ||
@@ -18,0 +19,0 @@ return R.deleteAt(k)(r); |
/** | ||
* @since 1.2.0 | ||
*/ | ||
import { At } from '../index'; | ||
import { Eq } from 'fp-ts/lib/Eq'; | ||
import { At } from '..' | ||
import { Eq } from 'fp-ts/lib/Eq' | ||
/** | ||
* @category constructor | ||
* @since 1.2.0 | ||
*/ | ||
export declare function atSet<A = never>(E: Eq<A>): At<Set<A>, A, boolean>; | ||
export declare function atSet<A = never>(E: Eq<A>): At<Set<A>, A, boolean> |
@@ -7,5 +7,6 @@ "use strict"; | ||
*/ | ||
var index_1 = require("../index"); | ||
var __1 = require(".."); | ||
var S = require("fp-ts/lib/Set"); | ||
/** | ||
* @category constructor | ||
* @since 1.2.0 | ||
@@ -17,8 +18,8 @@ */ | ||
var removeE = S.remove(E); | ||
return new index_1.At(function (at) { | ||
return new __1.At(function (at) { | ||
var insertEAt = insertE(at); | ||
var removeEAt = removeE(at); | ||
return new index_1.Lens(function (s) { return elemE(at, s); }, function (a) { return function (s) { return (a ? insertEAt(s) : removeEAt(s)); }; }); | ||
return new __1.Lens(function (s) { return elemE(at, s); }, function (a) { return function (s) { return (a ? insertEAt(s) : removeEAt(s)); }; }); | ||
}); | ||
} | ||
exports.atSet = atSet; |
/** | ||
* @since 1.6.0 | ||
*/ | ||
import { Either } from 'fp-ts/lib/Either'; | ||
import { Prism } from '.'; | ||
import { Either } from 'fp-ts/lib/Either' | ||
import { Prism } from '.' | ||
/** | ||
* @category constructor | ||
* @since 1.6.0 | ||
*/ | ||
export declare const _right: <L, A>() => Prism<Either<L, A>, A>; | ||
export declare const _right: <E, A>() => Prism<Either<E, A>, A> | ||
/** | ||
* @category constructor | ||
* @since 1.6.0 | ||
*/ | ||
export declare const _left: <L, A>() => Prism<Either<L, A>, L>; | ||
export declare const _left: <E, A>() => Prism<Either<E, A>, E> |
@@ -12,2 +12,3 @@ "use strict"; | ||
/** | ||
* @category constructor | ||
* @since 1.6.0 | ||
@@ -18,4 +19,5 @@ */ | ||
/** | ||
* @category constructor | ||
* @since 1.6.0 | ||
*/ | ||
exports._left = function () { return l; }; |
2009
lib/index.d.ts
@@ -0,12 +1,45 @@ | ||
import { Foldable, Foldable1, Foldable2, Foldable3 } from 'fp-ts/lib/Foldable' | ||
import { Predicate, Refinement } from 'fp-ts/lib/function' | ||
import { HKT, Kind, Kind2, Kind3, URIS, URIS2, URIS3 } from 'fp-ts/lib/HKT' | ||
import { Monoid } from 'fp-ts/lib/Monoid' | ||
import { Option } from 'fp-ts/lib/Option' | ||
import { Traversable, Traversable1, Traversable2, Traversable3 } from 'fp-ts/lib/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 | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
import { HKT, URIS, URIS2, URIS3, Kind3, Kind2, Kind } from 'fp-ts/lib/HKT'; | ||
import { Monoid } from 'fp-ts/lib/Monoid'; | ||
import { Applicative, Applicative1, Applicative2, Applicative3, Applicative2C } from 'fp-ts/lib/Applicative'; | ||
import { Foldable, Foldable1, Foldable2, Foldable3 } from 'fp-ts/lib/Foldable'; | ||
import { Traversable, Traversable1, Traversable2, Traversable3 } from 'fp-ts/lib/Traversable'; | ||
import { Option } from 'fp-ts/lib/Option'; | ||
import { Predicate, Refinement } from 'fp-ts/lib/function'; | ||
/** | ||
* Laws: | ||
@@ -16,133 +49,134 @@ * 1. reverseGet(get(s)) = s | ||
* | ||
* @category constructor | ||
* @since 1.0.0 | ||
*/ | ||
export declare class Iso<S, A> { | ||
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<A, S>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
modify(f: (a: A) => A): (s: S) => S; | ||
/** | ||
* view an `Iso` as a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asLens(): Lens<S, A>; | ||
/** | ||
* view an `Iso` as a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asPrism(): Prism<S, A>; | ||
/** | ||
* view an `Iso` as a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asOptional(): Optional<S, A>; | ||
/** | ||
* view an `Iso` as a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asTraversal(): Traversal<S, A>; | ||
/** | ||
* view an `Iso` as a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asFold(): Fold<S, A>; | ||
/** | ||
* view an `Iso` as a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asGetter(): Getter<S, A>; | ||
/** | ||
* view an `Iso` as a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asSetter(): Setter<S, A>; | ||
/** | ||
* compose an `Iso` with an `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Iso<A, B>): Iso<S, B>; | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Iso<S, B>; | ||
/** | ||
* compose an `Iso` with a `Lens ` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Lens<S, B>; | ||
/** | ||
* compose an `Iso` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Prism<S, B>; | ||
/** | ||
* compose an `Iso` with an `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Optional<S, B>; | ||
/** | ||
* compose an `Iso` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B>; | ||
/** | ||
* compose an `Iso` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B>; | ||
/** | ||
* compose an `Iso` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Getter<S, B>; | ||
/** | ||
* compose an `Iso` with a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B>; | ||
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<A, S> | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
modify(f: (a: A) => A): (s: S) => S | ||
/** | ||
* view an `Iso` as a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asLens(): Lens<S, A> | ||
/** | ||
* view an `Iso` as a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asPrism(): Prism<S, A> | ||
/** | ||
* view an `Iso` as a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asOptional(): Optional<S, A> | ||
/** | ||
* view an `Iso` as a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asTraversal(): Traversal<S, A> | ||
/** | ||
* view an `Iso` as a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asFold(): Fold<S, A> | ||
/** | ||
* view an `Iso` as a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asGetter(): Getter<S, A> | ||
/** | ||
* view an `Iso` as a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asSetter(): Setter<S, A> | ||
/** | ||
* compose an `Iso` with an `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Iso<A, B>): Iso<S, B> | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Iso<S, B> | ||
/** | ||
* compose an `Iso` with a `Lens ` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Lens<S, B> | ||
/** | ||
* compose an `Iso` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Prism<S, B> | ||
/** | ||
* compose an `Iso` with an `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Optional<S, B> | ||
/** | ||
* compose an `Iso` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B> | ||
/** | ||
* compose an `Iso` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B> | ||
/** | ||
* compose an `Iso` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Getter<S, B> | ||
/** | ||
* compose an `Iso` with a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B> | ||
} | ||
@@ -153,7 +187,17 @@ /** | ||
export interface LensFromPath<S> { | ||
<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<S, S[K1][K2][K3][K4][K5]>; | ||
<K1 extends keyof S, K2 extends keyof S[K1], K3 extends keyof S[K1][K2], K4 extends keyof S[K1][K2][K3]>(path: [K1, K2, K3, K4]): Lens<S, S[K1][K2][K3][K4]>; | ||
<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]>; | ||
<K1 extends keyof S, K2 extends keyof S[K1]>(path: [K1, K2]): Lens<S, S[K1][K2]>; | ||
<K1 extends keyof S>(path: [K1]): Lens<S, S[K1]>; | ||
< | ||
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<S, S[K1][K2][K3][K4][K5]> | ||
<K1 extends keyof S, K2 extends keyof S[K1], K3 extends keyof S[K1][K2], K4 extends keyof S[K1][K2][K3]>( | ||
path: [K1, K2, K3, K4] | ||
): Lens<S, S[K1][K2][K3][K4]> | ||
<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]> | ||
<K1 extends keyof S, K2 extends keyof S[K1]>(path: [K1, K2]): Lens<S, S[K1][K2]> | ||
<K1 extends keyof S>(path: [K1]): Lens<S, S[K1]> | ||
} | ||
@@ -166,194 +210,200 @@ /** | ||
* | ||
* @category constructor | ||
* @since 1.0.0 | ||
*/ | ||
export declare class Lens<S, A> { | ||
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<Person>()(['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<S>(): LensFromPath<S>; | ||
/** | ||
* 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<Person>()('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<S>(): <P extends keyof S>(prop: P) => Lens<S, S[P]>; | ||
/** | ||
* 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<Person>()(['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<S>(): <P extends keyof S>(props: Array<P>) => 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<Outer>()('inner', { value: 0, foo: 'foo' }) | ||
* const value = Lens.fromProp<Inner>()('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<S>(): <A extends S[K], K extends keyof S>(k: K, defaultValue: A) => Lens<S, NonNullable<S[K]>>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
modify(f: (a: A) => A): (s: S) => S; | ||
/** | ||
* view a `Lens` as a Optional | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asOptional(): Optional<S, A>; | ||
/** | ||
* view a `Lens` as a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asTraversal(): Traversal<S, A>; | ||
/** | ||
* view a `Lens` as a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asSetter(): Setter<S, A>; | ||
/** | ||
* view a `Lens` as a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asGetter(): Getter<S, A>; | ||
/** | ||
* view a `Lens` as a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asFold(): Fold<S, A>; | ||
/** | ||
* compose a `Lens` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Lens<A, B>): Lens<S, B>; | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Lens<S, B>; | ||
/** | ||
* compose a `Lens` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Getter<S, B>; | ||
/** | ||
* compose a `Lens` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Lens` with an `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Optional<S, B>; | ||
/** | ||
* compose a `Lens` with an `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B>; | ||
/** | ||
* compose a `Lens` with an `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B>; | ||
/** | ||
* compose a `Lens` with an `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Lens<S, B>; | ||
/** | ||
* compose a `Lens` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Optional<S, B>; | ||
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<Person>()(['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<S>(): LensFromPath<S> | ||
/** | ||
* 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<Person>()('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<S>(): <P extends keyof S>(prop: P) => Lens<S, S[P]> | ||
/** | ||
* 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<Person>()(['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<S>(): <P extends keyof S>( | ||
props: Array<P> | ||
) => 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<Outer>()('inner', { value: 0, foo: 'foo' }) | ||
* const value = Lens.fromProp<Inner>()('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<S>(): <A extends S[K], K extends keyof S>(k: K, defaultValue: A) => Lens<S, NonNullable<S[K]>> | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
modify(f: (a: A) => A): (s: S) => S | ||
/** | ||
* view a `Lens` as a Optional | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asOptional(): Optional<S, A> | ||
/** | ||
* view a `Lens` as a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asTraversal(): Traversal<S, A> | ||
/** | ||
* view a `Lens` as a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asSetter(): Setter<S, A> | ||
/** | ||
* view a `Lens` as a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asGetter(): Getter<S, A> | ||
/** | ||
* view a `Lens` as a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asFold(): Fold<S, A> | ||
/** | ||
* compose a `Lens` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Lens<A, B>): Lens<S, B> | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Lens<S, B> | ||
/** | ||
* compose a `Lens` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Getter<S, B> | ||
/** | ||
* compose a `Lens` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Lens` with an `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Optional<S, B> | ||
/** | ||
* compose a `Lens` with an `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B> | ||
/** | ||
* compose a `Lens` with an `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B> | ||
/** | ||
* compose a `Lens` with an `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Lens<S, B> | ||
/** | ||
* compose a `Lens` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Optional<S, B> | ||
} | ||
@@ -365,118 +415,119 @@ /** | ||
* | ||
* @category constructor | ||
* @since 1.0.0 | ||
*/ | ||
export declare class Prism<S, A> { | ||
readonly getOption: (s: S) => Option<A>; | ||
readonly reverseGet: (a: A) => S; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
readonly _tag: 'Prism'; | ||
constructor(getOption: (s: S) => Option<A>, reverseGet: (a: A) => S); | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
static fromPredicate<S, A extends S>(refinement: Refinement<S, A>): Prism<S, A>; | ||
static fromPredicate<A>(predicate: Predicate<A>): Prism<A, A>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
static some<A>(): Prism<Option<A>, 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<S>; | ||
/** | ||
* 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<S, A>; | ||
/** | ||
* view a `Prism` as a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asTraversal(): Traversal<S, A>; | ||
/** | ||
* view a `Prism` as a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asSetter(): Setter<S, A>; | ||
/** | ||
* view a `Prism` as a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asFold(): Fold<S, A>; | ||
/** | ||
* compose a `Prism` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Prism<A, B>): Prism<S, B>; | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Prism<S, B>; | ||
/** | ||
* compose a `Prism` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Optional<S, B>; | ||
/** | ||
* compose a `Prism` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B>; | ||
/** | ||
* compose a `Prism` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Prism` with a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B>; | ||
/** | ||
* compose a `Prism` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Prism<S, B>; | ||
/** | ||
* compose a `Prism` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Optional<S, B>; | ||
/** | ||
* compose a `Prism` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Fold<S, B>; | ||
readonly getOption: (s: S) => Option<A> | ||
readonly reverseGet: (a: A) => S | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
readonly _tag: 'Prism' | ||
constructor(getOption: (s: S) => Option<A>, reverseGet: (a: A) => S) | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
static fromPredicate<S, A extends S>(refinement: Refinement<S, A>): Prism<S, A> | ||
static fromPredicate<A>(predicate: Predicate<A>): Prism<A, A> | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
static some<A>(): Prism<Option<A>, 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<S> | ||
/** | ||
* 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<S, A> | ||
/** | ||
* view a `Prism` as a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asTraversal(): Traversal<S, A> | ||
/** | ||
* view a `Prism` as a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asSetter(): Setter<S, A> | ||
/** | ||
* view a `Prism` as a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asFold(): Fold<S, A> | ||
/** | ||
* compose a `Prism` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Prism<A, B>): Prism<S, B> | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Prism<S, B> | ||
/** | ||
* compose a `Prism` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Optional<S, B> | ||
/** | ||
* compose a `Prism` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B> | ||
/** | ||
* compose a `Prism` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Prism` with a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B> | ||
/** | ||
* compose a `Prism` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Prism<S, B> | ||
/** | ||
* compose a `Prism` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Optional<S, B> | ||
/** | ||
* compose a `Prism` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Fold<S, B> | ||
} | ||
declare type OptionPropertyNames<S> = { | ||
[K in keyof S]-?: S[K] extends Option<any> ? K : never; | ||
}[keyof S]; | ||
declare type OptionPropertyType<S, K extends OptionPropertyNames<S>> = S[K] extends Option<infer A> ? A : never; | ||
[K in keyof S]-?: S[K] extends Option<any> ? K : never | ||
}[keyof S] | ||
declare type OptionPropertyType<S, K extends OptionPropertyNames<S>> = S[K] extends Option<infer A> ? A : never | ||
/** | ||
@@ -486,7 +537,27 @@ * @since 2.1.0 | ||
export interface OptionalFromPath<S> { | ||
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>, K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>, K4 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>, K5 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>(path: [K1, K2, K3, K4, K5]): Optional<S, NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>[K5]>>; | ||
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>, K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>, K4 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>>(path: [K1, K2, K3, K4]): Optional<S, NonNullable<NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>>; | ||
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>, K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>>(path: [K1, K2, K3]): Optional<S, NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>>; | ||
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>>(path: [K1, K2]): Optional<S, NonNullable<NonNullable<S[K1]>[K2]>>; | ||
<K1 extends keyof S>(path: [K1]): Optional<S, NonNullable<S[K1]>>; | ||
< | ||
K1 extends keyof S, | ||
K2 extends keyof NonNullable<S[K1]>, | ||
K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>, | ||
K4 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>, | ||
K5 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4] | ||
>( | ||
path: [K1, K2, K3, K4, K5] | ||
): Optional<S, NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>[K5]>> | ||
< | ||
K1 extends keyof S, | ||
K2 extends keyof NonNullable<S[K1]>, | ||
K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>, | ||
K4 extends keyof NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]> | ||
>( | ||
path: [K1, K2, K3, K4] | ||
): Optional<S, NonNullable<NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>[K4]>> | ||
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>, K3 extends keyof NonNullable<NonNullable<S[K1]>[K2]>>( | ||
path: [K1, K2, K3] | ||
): Optional<S, NonNullable<NonNullable<NonNullable<S[K1]>[K2]>[K3]>> | ||
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>>(path: [K1, K2]): Optional< | ||
S, | ||
NonNullable<NonNullable<S[K1]>[K2]> | ||
> | ||
<K1 extends keyof S>(path: [K1]): Optional<S, NonNullable<S[K1]>> | ||
} | ||
@@ -499,175 +570,176 @@ /** | ||
* | ||
* @category constructor | ||
* @since 1.0.0 | ||
*/ | ||
export declare class Optional<S, A> { | ||
readonly getOption: (s: S) => Option<A>; | ||
readonly set: (a: A) => (s: S) => S; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
readonly _tag: 'Optional'; | ||
constructor(getOption: (s: S) => Option<A>, 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<Response>()(['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<S>(): OptionalFromPath<S>; | ||
/** | ||
* @example | ||
* import { Optional } from 'monocle-ts' | ||
* | ||
* interface S { | ||
* a: number | undefined | null | ||
* } | ||
* | ||
* const optional = Optional.fromNullableProp<S>()('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<S>(): <K extends keyof S>(k: K) => Optional<S, NonNullable<S[K]>>; | ||
/** | ||
* Returns an `Optional` from an option (`Option<A>`) prop | ||
* | ||
* @example | ||
* import { Optional } from 'monocle-ts' | ||
* import * as O from 'fp-ts/lib/Option' | ||
* | ||
* interface S { | ||
* a: O.Option<number> | ||
* } | ||
* | ||
* const optional = Optional.fromOptionProp<S>()('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<S>(): <P extends OptionPropertyNames<S>>(prop: P) => Optional<S, OptionPropertyType<S, P>>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
modify(f: (a: A) => A): (s: S) => S; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
modifyOption(f: (a: A) => A): (s: S) => Option<S>; | ||
/** | ||
* view a `Optional` as a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asTraversal(): Traversal<S, A>; | ||
/** | ||
* view an `Optional` as a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asFold(): Fold<S, A>; | ||
/** | ||
* view an `Optional` as a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asSetter(): Setter<S, A>; | ||
/** | ||
* compose a `Optional` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Optional<A, B>): Optional<S, B>; | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Optional<S, B>; | ||
/** | ||
* compose an `Optional` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B>; | ||
/** | ||
* compose an `Optional` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B>; | ||
/** | ||
* compose an `Optional` with a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B>; | ||
/** | ||
* compose an `Optional` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Optional<S, B>; | ||
/** | ||
* compose an `Optional` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Optional<S, B>; | ||
/** | ||
* compose an `Optional` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Optional<S, B>; | ||
/** | ||
* compose an `Optional` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Fold<S, B>; | ||
readonly getOption: (s: S) => Option<A> | ||
readonly set: (a: A) => (s: S) => S | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
readonly _tag: 'Optional' | ||
constructor(getOption: (s: S) => Option<A>, 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<Response>()(['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<S>(): OptionalFromPath<S> | ||
/** | ||
* @example | ||
* import { Optional } from 'monocle-ts' | ||
* | ||
* interface S { | ||
* a: number | undefined | null | ||
* } | ||
* | ||
* const optional = Optional.fromNullableProp<S>()('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<S>(): <K extends keyof S>(k: K) => Optional<S, NonNullable<S[K]>> | ||
/** | ||
* Returns an `Optional` from an option (`Option<A>`) prop | ||
* | ||
* @example | ||
* import { Optional } from 'monocle-ts' | ||
* import * as O from 'fp-ts/lib/Option' | ||
* | ||
* interface S { | ||
* a: O.Option<number> | ||
* } | ||
* | ||
* const optional = Optional.fromOptionProp<S>()('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<S>(): <P extends OptionPropertyNames<S>>(prop: P) => Optional<S, OptionPropertyType<S, P>> | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
modify(f: (a: A) => A): (s: S) => S | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
modifyOption(f: (a: A) => A): (s: S) => Option<S> | ||
/** | ||
* view a `Optional` as a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asTraversal(): Traversal<S, A> | ||
/** | ||
* view an `Optional` as a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asFold(): Fold<S, A> | ||
/** | ||
* view an `Optional` as a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asSetter(): Setter<S, A> | ||
/** | ||
* compose a `Optional` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Optional<A, B>): Optional<S, B> | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Optional<S, B> | ||
/** | ||
* compose an `Optional` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B> | ||
/** | ||
* compose an `Optional` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B> | ||
/** | ||
* compose an `Optional` with a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B> | ||
/** | ||
* compose an `Optional` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Optional<S, B> | ||
/** | ||
* compose an `Optional` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Optional<S, B> | ||
/** | ||
* compose an `Optional` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Optional<S, B> | ||
/** | ||
* compose an `Optional` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Fold<S, B> | ||
} | ||
@@ -677,372 +749,372 @@ /** | ||
*/ | ||
export interface ModifyF<S, A> { | ||
<F extends URIS3>(F: Applicative3<F>): <U, L>(f: (a: A) => Kind3<F, U, L, A>) => (s: S) => Kind3<F, U, L, S>; | ||
<F extends URIS2>(F: Applicative2<F>): <L>(f: (a: A) => Kind2<F, L, A>) => (s: S) => Kind2<F, L, S>; | ||
<F extends URIS2, L>(F: Applicative2C<F, L>): (f: (a: A) => Kind2<F, L, A>) => (s: S) => Kind2<F, L, S>; | ||
<F extends URIS>(F: Applicative1<F>): (f: (a: A) => Kind<F, A>) => (s: S) => Kind<F, S>; | ||
<F>(F: Applicative<F>): (f: (a: A) => HKT<F, A>) => (s: S) => HKT<F, S>; | ||
} | ||
export declare type ModifyF<S, A> = traversal.ModifyF<S, A> | ||
/** | ||
* @category constructor | ||
* @since 1.0.0 | ||
*/ | ||
export declare class Traversal<S, A> { | ||
readonly modifyF: ModifyF<S, A>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
readonly _tag: 'Traversal'; | ||
constructor(modifyF: ModifyF<S, A>); | ||
/** | ||
* @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 { array } from 'fp-ts/lib/Array' | ||
* | ||
* interface Person { | ||
* name: string; | ||
* cool: boolean; | ||
* } | ||
* | ||
* const peopleTraversal = fromTraversable(array)<Person>() | ||
* const coolLens = Lens.fromProp<Person>()('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<B extends A>(refinement: Refinement<A, B>): Traversal<S, B>; | ||
filter(predicate: Predicate<A>): Traversal<S, A>; | ||
/** | ||
* view a `Traversal` as a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asFold(): Fold<S, A>; | ||
/** | ||
* view a `Traversal` as a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asSetter(): Setter<S, A>; | ||
/** | ||
* compose a `Traversal` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Traversal<A, B>): Traversal<S, B>; | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B>; | ||
/** | ||
* compose a `Traversal` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Traversal` with a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B>; | ||
/** | ||
* compose a `Traversal` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Traversal<S, B>; | ||
/** | ||
* compose a `Traversal` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Traversal<S, B>; | ||
/** | ||
* compose a `Traversal` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Traversal<S, B>; | ||
/** | ||
* compose a `Traversal` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Traversal<S, B>; | ||
/** | ||
* compose a `Traversal` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Fold<S, B>; | ||
readonly modifyF: ModifyF<S, A> | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
readonly _tag: 'Traversal' | ||
constructor(modifyF: ModifyF<S, A>) | ||
/** | ||
* @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 { array } from 'fp-ts/lib/Array' | ||
* | ||
* interface Person { | ||
* name: string; | ||
* cool: boolean; | ||
* } | ||
* | ||
* const peopleTraversal = fromTraversable(array)<Person>() | ||
* const coolLens = Lens.fromProp<Person>()('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<B extends A>(refinement: Refinement<A, B>): Traversal<S, B> | ||
filter(predicate: Predicate<A>): Traversal<S, A> | ||
/** | ||
* view a `Traversal` as a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asFold(): Fold<S, A> | ||
/** | ||
* view a `Traversal` as a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
asSetter(): Setter<S, A> | ||
/** | ||
* compose a `Traversal` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Traversal<A, B>): Traversal<S, B> | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Traversal<S, B> | ||
/** | ||
* compose a `Traversal` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Traversal` with a `Setter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B> | ||
/** | ||
* compose a `Traversal` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Traversal<S, B> | ||
/** | ||
* compose a `Traversal` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Traversal<S, B> | ||
/** | ||
* compose a `Traversal` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Traversal<S, B> | ||
/** | ||
* compose a `Traversal` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Traversal<S, B> | ||
/** | ||
* compose a `Traversal` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Fold<S, B> | ||
} | ||
/** | ||
* @category constructor | ||
* @since 1.2.0 | ||
*/ | ||
export declare class At<S, I, A> { | ||
readonly at: (i: I) => Lens<S, A>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
readonly _tag: 'At'; | ||
constructor(at: (i: I) => Lens<S, A>); | ||
/** | ||
* lift an instance of `At` using an `Iso` | ||
* | ||
* @since 1.2.0 | ||
*/ | ||
fromIso<T>(iso: Iso<T, S>): At<T, I, A>; | ||
readonly at: (i: I) => Lens<S, A> | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
readonly _tag: 'At' | ||
constructor(at: (i: I) => Lens<S, A>) | ||
/** | ||
* lift an instance of `At` using an `Iso` | ||
* | ||
* @since 1.2.0 | ||
*/ | ||
fromIso<T>(iso: Iso<T, S>): At<T, I, A> | ||
} | ||
/** | ||
* @category constructor | ||
* @since 1.2.0 | ||
*/ | ||
export declare class Index<S, I, A> { | ||
readonly index: (i: I) => Optional<S, A>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
readonly _tag: 'Index'; | ||
constructor(index: (i: I) => Optional<S, A>); | ||
/** | ||
* @since 1.2.0 | ||
*/ | ||
static fromAt<T, J, B>(at: At<T, J, Option<B>>): Index<T, J, B>; | ||
/** | ||
* lift an instance of `Index` using an `Iso` | ||
* | ||
* @since 1.2.0 | ||
*/ | ||
fromIso<T>(iso: Iso<T, S>): Index<T, I, A>; | ||
readonly index: (i: I) => Optional<S, A> | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
readonly _tag: 'Index' | ||
constructor(index: (i: I) => Optional<S, A>) | ||
/** | ||
* @since 1.2.0 | ||
*/ | ||
static fromAt<T, J, B>(at: At<T, J, Option<B>>): Index<T, J, B> | ||
/** | ||
* lift an instance of `Index` using an `Iso` | ||
* | ||
* @since 1.2.0 | ||
*/ | ||
fromIso<T>(iso: Iso<T, S>): Index<T, I, A> | ||
} | ||
/** | ||
* @category constructor | ||
* @since 1.0.0 | ||
*/ | ||
export declare class Getter<S, A> { | ||
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<S, A>; | ||
/** | ||
* compose a `Getter` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Getter<A, B>): Getter<S, B>; | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Getter<S, B>; | ||
/** | ||
* compose a `Getter` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Getter` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Getter<S, B>; | ||
/** | ||
* compose a `Getter` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Getter<S, B>; | ||
/** | ||
* compose a `Getter` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Getter` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Getter` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Fold<S, B>; | ||
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<S, A> | ||
/** | ||
* compose a `Getter` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Getter<A, B>): Getter<S, B> | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Getter<S, B> | ||
/** | ||
* compose a `Getter` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Getter` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Getter<S, B> | ||
/** | ||
* compose a `Getter` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Getter<S, B> | ||
/** | ||
* compose a `Getter` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Getter` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Getter` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Fold<S, B> | ||
} | ||
/** | ||
* @category constructor | ||
* @since 1.0.0 | ||
*/ | ||
export declare class Fold<S, A> { | ||
readonly foldMap: <M>(M: Monoid<M>) => (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<A>; | ||
/** | ||
* check if at least one target satisfies the predicate | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
readonly exist: (p: Predicate<A>) => Predicate<S>; | ||
/** | ||
* check if all targets satisfy the predicate | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
readonly all: (p: Predicate<A>) => Predicate<S>; | ||
private foldMapFirst; | ||
constructor(foldMap: <M>(M: Monoid<M>) => (f: (a: A) => M) => (s: S) => M); | ||
/** | ||
* compose a `Fold` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Fold<A, B>): Fold<S, B>; | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Fold` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Fold` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Fold` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Fold` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Fold` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Fold<S, B>; | ||
/** | ||
* compose a `Fold` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Fold<S, B>; | ||
/** | ||
* find the first target of a `Fold` matching the predicate | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
find<B extends A>(p: Refinement<A, B>): (s: S) => Option<B>; | ||
find(p: Predicate<A>): (s: S) => Option<A>; | ||
/** | ||
* get the first target of a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
headOption(s: S): Option<A>; | ||
readonly foldMap: <M>(M: Monoid<M>) => (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<A> | ||
/** | ||
* check if at least one target satisfies the predicate | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
readonly exist: (p: Predicate<A>) => Predicate<S> | ||
/** | ||
* check if all targets satisfy the predicate | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
readonly all: (p: Predicate<A>) => Predicate<S> | ||
private foldMapFirst | ||
constructor(foldMap: <M>(M: Monoid<M>) => (f: (a: A) => M) => (s: S) => M) | ||
/** | ||
* compose a `Fold` with a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
compose<B>(ab: Fold<A, B>): Fold<S, B> | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeFold<B>(ab: Fold<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Fold` with a `Getter` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeGetter<B>(ab: Getter<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Fold` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Fold` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Fold` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Fold` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Fold<S, B> | ||
/** | ||
* compose a `Fold` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Fold<S, B> | ||
/** | ||
* find the first target of a `Fold` matching the predicate | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
find<B extends A>(p: Refinement<A, B>): (s: S) => Option<B> | ||
find(p: Predicate<A>): (s: S) => Option<A> | ||
/** | ||
* get the first target of a `Fold` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
headOption(s: S): Option<A> | ||
} | ||
/** | ||
* @category constructor | ||
* @since 1.0.0 | ||
*/ | ||
export declare class Setter<S, A> { | ||
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<B>(ab: Setter<A, B>): Setter<S, B>; | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B>; | ||
/** | ||
* compose a `Setter` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Setter<S, B>; | ||
/** | ||
* compose a `Setter` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Setter<S, B>; | ||
/** | ||
* compose a `Setter` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Setter<S, B>; | ||
/** | ||
* compose a `Setter` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Setter<S, B>; | ||
/** | ||
* compose a `Setter` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Setter<S, B>; | ||
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<B>(ab: Setter<A, B>): Setter<S, B> | ||
/** | ||
* Alias of `compose` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeSetter<B>(ab: Setter<A, B>): Setter<S, B> | ||
/** | ||
* compose a `Setter` with a `Traversal` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeTraversal<B>(ab: Traversal<A, B>): Setter<S, B> | ||
/** | ||
* compose a `Setter` with a `Optional` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeOptional<B>(ab: Optional<A, B>): Setter<S, B> | ||
/** | ||
* compose a `Setter` with a `Lens` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeLens<B>(ab: Lens<A, B>): Setter<S, B> | ||
/** | ||
* compose a `Setter` with a `Prism` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composePrism<B>(ab: Prism<A, B>): Setter<S, B> | ||
/** | ||
* compose a `Setter` with a `Iso` | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
composeIso<B>(ab: Iso<A, B>): Setter<S, B> | ||
} | ||
/** | ||
* create a `Traversal` from a `Traversable` | ||
* Create a `Traversal` from a `Traversable` | ||
* | ||
@@ -1079,17 +1151,20 @@ * @example | ||
* | ||
* @category constructor | ||
* @since 1.0.0 | ||
*/ | ||
export declare function fromTraversable<T extends URIS3>(T: Traversable3<T>): <U, L, A>() => Traversal<Kind3<T, U, L, A>, A>; | ||
export declare function fromTraversable<T extends URIS2>(T: Traversable2<T>): <L, A>() => Traversal<Kind2<T, L, A>, A>; | ||
export declare function fromTraversable<T extends URIS>(T: Traversable1<T>): <A>() => Traversal<Kind<T, A>, A>; | ||
export declare function fromTraversable<T>(T: Traversable<T>): <A>() => Traversal<HKT<T, A>, A>; | ||
export declare function fromTraversable<T extends URIS3>( | ||
T: Traversable3<T> | ||
): <U, L, A>() => Traversal<Kind3<T, U, L, A>, A> | ||
export declare function fromTraversable<T extends URIS2>(T: Traversable2<T>): <L, A>() => Traversal<Kind2<T, L, A>, A> | ||
export declare function fromTraversable<T extends URIS>(T: Traversable1<T>): <A>() => Traversal<Kind<T, A>, A> | ||
export declare function fromTraversable<T>(T: Traversable<T>): <A>() => Traversal<HKT<T, A>, A> | ||
/** | ||
* create a `Fold` from a `Foldable` | ||
* Create a `Fold` from a `Foldable` | ||
* | ||
* @category constructor | ||
* @since 1.0.0 | ||
*/ | ||
export declare function fromFoldable<F extends URIS3>(F: Foldable3<F>): <U, L, A>() => Fold<Kind3<F, U, L, A>, A>; | ||
export declare function fromFoldable<F extends URIS2>(F: Foldable2<F>): <L, A>() => Fold<Kind2<F, L, A>, A>; | ||
export declare function fromFoldable<F extends URIS>(F: Foldable1<F>): <A>() => Fold<Kind<F, A>, A>; | ||
export declare function fromFoldable<F>(F: Foldable<F>): <A>() => Fold<HKT<F, A>, A>; | ||
export {}; | ||
export declare function fromFoldable<F extends URIS3>(F: Foldable3<F>): <U, L, A>() => Fold<Kind3<F, U, L, A>, A> | ||
export declare function fromFoldable<F extends URIS2>(F: Foldable2<F>): <L, A>() => Fold<Kind2<F, L, A>, A> | ||
export declare function fromFoldable<F extends URIS>(F: Foldable1<F>): <A>() => Fold<Kind<F, A>, A> | ||
export declare function fromFoldable<F>(F: Foldable<F>): <A>() => Fold<HKT<F, A>, A> |
252
lib/index.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fromFoldable = exports.fromTraversable = exports.Setter = exports.Fold = exports.Getter = exports.Index = exports.At = exports.Traversal = exports.Optional = exports.Prism = exports.Lens = exports.Iso = void 0; | ||
exports.fromFoldable = exports.fromTraversable = exports.Setter = exports.Fold = exports.Getter = exports.Index = exports.At = exports.Traversal = exports.Optional = exports.Prism = exports.Lens = exports.Iso = exports.traversal = exports.optional = exports.prism = exports.lens = exports.index = exports.iso = exports.at = void 0; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var Array_1 = require("fp-ts/lib/Array"); | ||
var Const_1 = require("fp-ts/lib/Const"); | ||
var function_1 = require("fp-ts/lib/function"); | ||
var Monoid_1 = require("fp-ts/lib/Monoid"); | ||
var Option_1 = require("fp-ts/lib/Option"); | ||
var function_1 = require("fp-ts/lib/function"); | ||
var Identity_1 = require("fp-ts/lib/Identity"); | ||
var Const_1 = require("fp-ts/lib/Const"); | ||
var Array_1 = require("fp-ts/lib/Array"); | ||
var pipeable_1 = require("fp-ts/lib/pipeable"); | ||
var at = require("./At"); | ||
exports.at = at; | ||
var iso = require("./Iso"); | ||
exports.iso = iso; | ||
var index = require("./Ix"); | ||
exports.index = index; | ||
var lens = require("./Lens"); | ||
exports.lens = lens; | ||
var optional = require("./Optional"); | ||
exports.optional = optional; | ||
var prism = require("./Prism"); | ||
exports.prism = prism; | ||
var traversal = require("./Traversal"); | ||
exports.traversal = traversal; | ||
// | ||
// compat | ||
// | ||
var fromIso = function (iso) { return new Iso(iso.get, iso.reverseGet); }; | ||
var fromLens = function (lens) { return new Lens(lens.get, lens.set); }; | ||
var fromPrism = function (prism) { return new Prism(prism.getOption, prism.reverseGet); }; | ||
var fromOptional = function (optional) { | ||
return new Optional(optional.getOption, optional.set); | ||
}; | ||
var fromTraversal = function (traversal) { return new Traversal(traversal.modifyF); }; | ||
var fromAt = function (at) { return new At(function (i) { return fromLens(at.at(i)); }); }; | ||
var fromIndex = function (ix) { return new Index(function (i) { return fromOptional(ix.index(i)); }); }; | ||
// | ||
// old APIs | ||
// | ||
var update = function (o, k, a) { | ||
@@ -19,2 +51,3 @@ var _a; | ||
* | ||
* @category constructor | ||
* @since 1.0.0 | ||
@@ -52,3 +85,3 @@ */ | ||
Iso.prototype.reverse = function () { | ||
return new Iso(this.reverseGet, this.get); | ||
return fromIso(iso.reverse(this)); | ||
}; | ||
@@ -59,4 +92,3 @@ /** | ||
Iso.prototype.modify = function (f) { | ||
var _this = this; | ||
return function (s) { return _this.reverseGet(f(_this.get(s))); }; | ||
return iso.modify(f)(this); | ||
}; | ||
@@ -69,4 +101,3 @@ /** | ||
Iso.prototype.asLens = function () { | ||
var _this = this; | ||
return new Lens(this.get, function (a) { return function (_) { return _this.reverseGet(a); }; }); | ||
return fromLens(iso.asLens(this)); | ||
}; | ||
@@ -79,4 +110,3 @@ /** | ||
Iso.prototype.asPrism = function () { | ||
var _this = this; | ||
return new Prism(function (s) { return Option_1.some(_this.get(s)); }, this.reverseGet); | ||
return fromPrism(iso.asPrism(this)); | ||
}; | ||
@@ -89,4 +119,3 @@ /** | ||
Iso.prototype.asOptional = function () { | ||
var _this = this; | ||
return new Optional(function (s) { return Option_1.some(_this.get(s)); }, function (a) { return function (_) { return _this.reverseGet(a); }; }); | ||
return fromOptional(iso.asOptional(this)); | ||
}; | ||
@@ -99,6 +128,3 @@ /** | ||
Iso.prototype.asTraversal = function () { | ||
var _this = this; | ||
return new Traversal(function (F) { return function (f) { return function (s) { | ||
return F.map(f(_this.get(s)), function (a) { return _this.reverseGet(a); }); | ||
}; }; }); | ||
return fromTraversal(iso.asTraversal(this)); | ||
}; | ||
@@ -138,4 +164,3 @@ /** | ||
Iso.prototype.compose = function (ab) { | ||
var _this = this; | ||
return new Iso(function (s) { return ab.get(_this.get(s)); }, function (b) { return _this.reverseGet(ab.reverseGet(b)); }); | ||
return fromIso(iso.compose(ab)(this)); | ||
}; | ||
@@ -156,3 +181,3 @@ /** | ||
Iso.prototype.composeLens = function (ab) { | ||
return this.asLens().compose(ab); | ||
return fromLens(pipeable_1.pipe(this, iso.asLens, lens.compose(ab))); | ||
}; | ||
@@ -165,3 +190,3 @@ /** | ||
Iso.prototype.composePrism = function (ab) { | ||
return this.asPrism().compose(ab); | ||
return fromPrism(pipeable_1.pipe(this, iso.asPrism, prism.compose(ab))); | ||
}; | ||
@@ -174,3 +199,3 @@ /** | ||
Iso.prototype.composeOptional = function (ab) { | ||
return this.asOptional().compose(ab); | ||
return fromOptional(pipeable_1.pipe(this, iso.asOptional, optional.compose(ab))); | ||
}; | ||
@@ -183,3 +208,3 @@ /** | ||
Iso.prototype.composeTraversal = function (ab) { | ||
return this.asTraversal().compose(ab); | ||
return fromTraversal(pipeable_1.pipe(this, iso.asTraversal, traversal.compose(ab))); | ||
}; | ||
@@ -219,2 +244,3 @@ /** | ||
* | ||
* @category constructor | ||
* @since 1.0.0 | ||
@@ -280,47 +306,6 @@ */ | ||
Lens.fromProp = function () { | ||
return function (prop) { | ||
return new Lens(function (s) { return s[prop]; }, function (a) { return function (s) { return update(s, prop, a); }; }); | ||
}; | ||
return function (prop) { return fromLens(pipeable_1.pipe(lens.id(), lens.prop(prop))); }; | ||
}; | ||
/** | ||
* 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<Person>()(['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 | ||
*/ | ||
Lens.fromProps = function () { | ||
return function (props) { | ||
var len = props.length; | ||
return new Lens(function (s) { | ||
var r = {}; | ||
for (var i = 0; i < len; i++) { | ||
var k = props[i]; | ||
r[k] = s[k]; | ||
} | ||
return r; | ||
}, function (a) { return function (s) { | ||
for (var i = 0; i < len; i++) { | ||
var k = props[i]; | ||
if (a[k] !== s[k]) { | ||
return Object.assign({}, s, a); | ||
} | ||
} | ||
return s; | ||
}; }); | ||
}; | ||
return function (props) { return fromLens(pipeable_1.pipe(lens.id(), lens.props.apply(lens, props))); }; | ||
}; | ||
@@ -370,8 +355,3 @@ /** | ||
Lens.prototype.modify = function (f) { | ||
var _this = this; | ||
return function (s) { | ||
var v = _this.get(s); | ||
var n = f(v); | ||
return v === n ? s : _this.set(n)(s); | ||
}; | ||
return lens.modify(f)(this); | ||
}; | ||
@@ -384,4 +364,3 @@ /** | ||
Lens.prototype.asOptional = function () { | ||
var _this = this; | ||
return new Optional(function (s) { return Option_1.some(_this.get(s)); }, this.set); | ||
return fromOptional(lens.asOptional(this)); | ||
}; | ||
@@ -394,6 +373,3 @@ /** | ||
Lens.prototype.asTraversal = function () { | ||
var _this = this; | ||
return new Traversal(function (F) { return function (f) { return function (s) { | ||
return F.map(f(_this.get(s)), function (a) { return _this.set(a)(s); }); | ||
}; }; }); | ||
return fromTraversal(lens.asTraversal(this)); | ||
}; | ||
@@ -433,4 +409,3 @@ /** | ||
Lens.prototype.compose = function (ab) { | ||
var _this = this; | ||
return new Lens(function (s) { return ab.get(_this.get(s)); }, function (b) { return function (s) { return _this.set(ab.set(b)(_this.get(s)))(s); }; }); | ||
return fromLens(lens.compose(ab)(this)); | ||
}; | ||
@@ -467,3 +442,3 @@ /** | ||
Lens.prototype.composeOptional = function (ab) { | ||
return this.asOptional().compose(ab); | ||
return fromOptional(pipeable_1.pipe(this, lens.asOptional, optional.compose(ab))); | ||
}; | ||
@@ -476,3 +451,3 @@ /** | ||
Lens.prototype.composeTraversal = function (ab) { | ||
return this.asTraversal().compose(ab); | ||
return fromTraversal(pipeable_1.pipe(this, lens.asTraversal, traversal.compose(ab))); | ||
}; | ||
@@ -493,3 +468,3 @@ /** | ||
Lens.prototype.composeIso = function (ab) { | ||
return this.compose(ab.asLens()); | ||
return fromLens(pipeable_1.pipe(this, lens.compose(pipeable_1.pipe(ab, iso.asLens)))); | ||
}; | ||
@@ -502,3 +477,3 @@ /** | ||
Lens.prototype.composePrism = function (ab) { | ||
return this.asOptional().compose(ab.asOptional()); | ||
return fromOptional(lens.composePrism(ab)(this)); | ||
}; | ||
@@ -513,2 +488,3 @@ return Lens; | ||
* | ||
* @category constructor | ||
* @since 1.0.0 | ||
@@ -526,3 +502,3 @@ */ | ||
Prism.fromPredicate = function (predicate) { | ||
return new Prism(function (s) { return (predicate(s) ? Option_1.some(s) : Option_1.none); }, function_1.identity); | ||
return fromPrism(prism.fromPredicate(predicate)); | ||
}; | ||
@@ -576,4 +552,3 @@ /** | ||
Prism.prototype.asOptional = function () { | ||
var _this = this; | ||
return new Optional(this.getOption, function (a) { return _this.set(a); }); | ||
return fromOptional(prism.asOptional(this)); | ||
}; | ||
@@ -586,12 +561,3 @@ /** | ||
Prism.prototype.asTraversal = function () { | ||
var _this = this; | ||
return new Traversal(function (F) { return function (f) { return function (s) { | ||
var oa = _this.getOption(s); | ||
if (Option_1.isNone(oa)) { | ||
return F.of(s); | ||
} | ||
else { | ||
return F.map(f(oa.value), function (a) { return _this.set(a)(s); }); | ||
} | ||
}; }; }); | ||
return fromTraversal(prism.asTraversal(this)); | ||
}; | ||
@@ -625,4 +591,3 @@ /** | ||
Prism.prototype.compose = function (ab) { | ||
var _this = this; | ||
return new Prism(function (s) { return Option_1.option.chain(_this.getOption(s), function (a) { return ab.getOption(a); }); }, function (b) { return _this.reverseGet(ab.reverseGet(b)); }); | ||
return fromPrism(prism.compose(ab)(this)); | ||
}; | ||
@@ -643,3 +608,3 @@ /** | ||
Prism.prototype.composeOptional = function (ab) { | ||
return this.asOptional().compose(ab); | ||
return fromOptional(pipeable_1.pipe(this, prism.asOptional, optional.compose(ab))); | ||
}; | ||
@@ -652,3 +617,3 @@ /** | ||
Prism.prototype.composeTraversal = function (ab) { | ||
return this.asTraversal().compose(ab); | ||
return fromTraversal(pipeable_1.pipe(this, prism.asTraversal, traversal.compose(ab))); | ||
}; | ||
@@ -677,3 +642,3 @@ /** | ||
Prism.prototype.composeIso = function (ab) { | ||
return this.compose(ab.asPrism()); | ||
return fromPrism(pipeable_1.pipe(this, prism.compose(pipeable_1.pipe(ab, iso.asPrism)))); | ||
}; | ||
@@ -686,3 +651,3 @@ /** | ||
Prism.prototype.composeLens = function (ab) { | ||
return this.asOptional().compose(ab.asOptional()); | ||
return fromOptional(prism.composeLens(ab)(this)); | ||
}; | ||
@@ -707,2 +672,3 @@ /** | ||
* | ||
* @category constructor | ||
* @since 1.0.0 | ||
@@ -819,12 +785,3 @@ */ | ||
Optional.prototype.modify = function (f) { | ||
var _this = this; | ||
return function (s) { | ||
var os = _this.modifyOption(f)(s); | ||
if (Option_1.isNone(os)) { | ||
return s; | ||
} | ||
else { | ||
return os.value; | ||
} | ||
}; | ||
return optional.modify(f)(this); | ||
}; | ||
@@ -835,9 +792,3 @@ /** | ||
Optional.prototype.modifyOption = function (f) { | ||
var _this = this; | ||
return function (s) { | ||
return Option_1.option.map(_this.getOption(s), function (a) { | ||
var n = f(a); | ||
return n === a ? s : _this.set(n)(s); | ||
}); | ||
}; | ||
return optional.modifyOption(f)(this); | ||
}; | ||
@@ -850,12 +801,3 @@ /** | ||
Optional.prototype.asTraversal = function () { | ||
var _this = this; | ||
return new Traversal(function (F) { return function (f) { return function (s) { | ||
var oa = _this.getOption(s); | ||
if (Option_1.isNone(oa)) { | ||
return F.of(s); | ||
} | ||
else { | ||
return F.map(f(oa.value), function (a) { return _this.set(a)(s); }); | ||
} | ||
}; }; }); | ||
return fromTraversal(optional.asTraversal(this)); | ||
}; | ||
@@ -889,4 +831,3 @@ /** | ||
Optional.prototype.compose = function (ab) { | ||
var _this = this; | ||
return new Optional(function (s) { return Option_1.option.chain(_this.getOption(s), function (a) { return ab.getOption(a); }); }, function (b) { return _this.modify(ab.set(b)); }); | ||
return fromOptional(optional.compose(ab)(this)); | ||
}; | ||
@@ -907,3 +848,3 @@ /** | ||
Optional.prototype.composeTraversal = function (ab) { | ||
return this.asTraversal().compose(ab); | ||
return fromTraversal(pipeable_1.pipe(this, optional.asTraversal, traversal.compose(ab))); | ||
}; | ||
@@ -932,3 +873,3 @@ /** | ||
Optional.prototype.composeLens = function (ab) { | ||
return this.compose(ab.asOptional()); | ||
return fromOptional(pipeable_1.pipe(this, optional.compose(pipeable_1.pipe(ab, lens.asOptional)))); | ||
}; | ||
@@ -941,3 +882,3 @@ /** | ||
Optional.prototype.composePrism = function (ab) { | ||
return this.compose(ab.asOptional()); | ||
return fromOptional(pipeable_1.pipe(this, optional.compose(pipeable_1.pipe(ab, prism.asOptional)))); | ||
}; | ||
@@ -950,3 +891,3 @@ /** | ||
Optional.prototype.composeIso = function (ab) { | ||
return this.compose(ab.asOptional()); | ||
return fromOptional(pipeable_1.pipe(this, optional.compose(pipeable_1.pipe(ab, iso.asOptional)))); | ||
}; | ||
@@ -965,2 +906,3 @@ /** | ||
/** | ||
* @category constructor | ||
* @since 1.0.0 | ||
@@ -982,3 +924,3 @@ */ | ||
Traversal.prototype.modify = function (f) { | ||
return this.modifyF(Identity_1.identity)(f); | ||
return traversal.modify(f)(this); | ||
}; | ||
@@ -989,6 +931,6 @@ /** | ||
Traversal.prototype.set = function (a) { | ||
return this.modify(function_1.constant(a)); | ||
return traversal.set(a)(this); | ||
}; | ||
Traversal.prototype.filter = function (predicate) { | ||
return this.composePrism(Prism.fromPredicate(predicate)); | ||
return fromTraversal(traversal.filter(predicate)(this)); | ||
}; | ||
@@ -1019,4 +961,3 @@ /** | ||
Traversal.prototype.compose = function (ab) { | ||
var _this = this; | ||
return new Traversal(function (F) { return function (f) { return _this.modifyF(F)(ab.modifyF(F)(f)); }; }); | ||
return fromTraversal(traversal.compose(ab)(this)); | ||
}; | ||
@@ -1061,3 +1002,3 @@ /** | ||
Traversal.prototype.composeLens = function (ab) { | ||
return this.compose(ab.asTraversal()); | ||
return fromTraversal(pipeable_1.pipe(this, traversal.compose(pipeable_1.pipe(ab, lens.asTraversal)))); | ||
}; | ||
@@ -1070,3 +1011,3 @@ /** | ||
Traversal.prototype.composePrism = function (ab) { | ||
return this.compose(ab.asTraversal()); | ||
return fromTraversal(pipeable_1.pipe(this, traversal.compose(pipeable_1.pipe(ab, prism.asTraversal)))); | ||
}; | ||
@@ -1079,3 +1020,3 @@ /** | ||
Traversal.prototype.composeIso = function (ab) { | ||
return this.compose(ab.asTraversal()); | ||
return fromTraversal(pipeable_1.pipe(this, traversal.compose(pipeable_1.pipe(ab, iso.asTraversal)))); | ||
}; | ||
@@ -1094,2 +1035,3 @@ /** | ||
/** | ||
* @category constructor | ||
* @since 1.2.0 | ||
@@ -1111,4 +1053,3 @@ */ | ||
At.prototype.fromIso = function (iso) { | ||
var _this = this; | ||
return new At(function (i) { return iso.composeLens(_this.at(i)); }); | ||
return fromAt(at.fromIso(iso)(this)); | ||
}; | ||
@@ -1119,2 +1060,3 @@ return At; | ||
/** | ||
* @category constructor | ||
* @since 1.2.0 | ||
@@ -1134,3 +1076,3 @@ */ | ||
Index.fromAt = function (at) { | ||
return new Index(function (i) { return at.at(i).composePrism(Prism.some()); }); | ||
return fromIndex(index.fromAt(at)); | ||
}; | ||
@@ -1143,4 +1085,3 @@ /** | ||
Index.prototype.fromIso = function (iso) { | ||
var _this = this; | ||
return new Index(function (i) { return iso.composeOptional(_this.index(i)); }); | ||
return fromIndex(index.fromIso(iso)(this)); | ||
}; | ||
@@ -1151,2 +1092,3 @@ return Index; | ||
/** | ||
* @category constructor | ||
* @since 1.0.0 | ||
@@ -1240,2 +1182,3 @@ */ | ||
/** | ||
* @category constructor | ||
* @since 1.0.0 | ||
@@ -1335,2 +1278,3 @@ */ | ||
/** | ||
* @category constructor | ||
* @since 1.0.0 | ||
@@ -1413,8 +1357,4 @@ */ | ||
function fromTraversable(T) { | ||
return function () { | ||
return new Traversal(function (F) { | ||
var traverseF = T.traverse(F); | ||
return function (f) { return function (s) { return traverseF(s, f); }; }; | ||
}); | ||
}; | ||
var f = traversal.fromTraversable(T); | ||
return function () { return fromTraversal(f()); }; | ||
} | ||
@@ -1421,0 +1361,0 @@ exports.fromTraversable = fromTraversable; |
/** | ||
* @since 1.2.0 | ||
*/ | ||
import { Index } from '../index'; | ||
import { Index } from '..' | ||
/** | ||
* @category constructor | ||
* @since 1.2.0 | ||
*/ | ||
export declare function indexArray<A = never>(): Index<Array<A>, number, A>; | ||
export declare function indexArray<A = never>(): Index<Array<A>, number, A> |
@@ -7,11 +7,12 @@ "use strict"; | ||
*/ | ||
var index_1 = require("../index"); | ||
var __1 = require(".."); | ||
var Array_1 = require("fp-ts/lib/Array"); | ||
var Option_1 = require("fp-ts/lib/Option"); | ||
/** | ||
* @category constructor | ||
* @since 1.2.0 | ||
*/ | ||
function indexArray() { | ||
return new index_1.Index(function (i) { | ||
return new index_1.Optional(function (as) { return Array_1.lookup(i, as); }, function (a) { return function (as) { | ||
return new __1.Index(function (i) { | ||
return new __1.Optional(function (as) { return Array_1.lookup(i, as); }, function (a) { return function (as) { | ||
var oas = Array_1.updateAt(i, a)(as); | ||
@@ -18,0 +19,0 @@ if (Option_1.isNone(oas)) { |
/** | ||
* @since 1.5.0 | ||
*/ | ||
import { Index } from '../index'; | ||
import { NonEmptyArray } from 'fp-ts/lib/NonEmptyArray'; | ||
import { Index } from '..' | ||
import { NonEmptyArray } from 'fp-ts/lib/NonEmptyArray' | ||
/** | ||
* @category constructor | ||
* @since 1.5.0 | ||
*/ | ||
export declare function indexNonEmptyArray<A = never>(): Index<NonEmptyArray<A>, number, A>; | ||
export declare function indexNonEmptyArray<A = never>(): Index<NonEmptyArray<A>, number, A> |
@@ -7,3 +7,3 @@ "use strict"; | ||
*/ | ||
var index_1 = require("../index"); | ||
var __1 = require(".."); | ||
var NonEmptyArray_1 = require("fp-ts/lib/NonEmptyArray"); | ||
@@ -13,7 +13,8 @@ var Array_1 = require("fp-ts/lib/Array"); | ||
/** | ||
* @category constructor | ||
* @since 1.5.0 | ||
*/ | ||
function indexNonEmptyArray() { | ||
return new index_1.Index(function (i) { | ||
return new index_1.Optional(function (s) { return Array_1.lookup(i, s); }, function (a) { return function (nea) { | ||
return new __1.Index(function (i) { | ||
return new __1.Optional(function (s) { return Array_1.lookup(i, s); }, function (a) { return function (nea) { | ||
var onea = NonEmptyArray_1.updateAt(i, a)(nea); | ||
@@ -20,0 +21,0 @@ if (Option_1.isNone(onea)) { |
/** | ||
* @since 2.2.0 | ||
*/ | ||
import { Index } from '../index'; | ||
import { Index } from '..' | ||
/** | ||
* @category constructor | ||
* @since 2.2.0 | ||
*/ | ||
export declare const indexReadonlyArray: <A = never>() => Index<ReadonlyArray<A>, number, A>; | ||
export declare const indexReadonlyArray: <A = never>() => Index<ReadonlyArray<A>, number, A> |
@@ -6,4 +6,5 @@ "use strict"; | ||
/** | ||
* @category constructor | ||
* @since 2.2.0 | ||
*/ | ||
exports.indexReadonlyArray = A.indexArray; |
/** | ||
* @since 2.2.0 | ||
*/ | ||
import { Index } from '../index'; | ||
import { Index } from '..' | ||
/** | ||
* @category model | ||
* @since 2.2.0 | ||
*/ | ||
export interface ReadonlyNonEmptyArray<A> extends ReadonlyArray<A> { | ||
readonly 0: A; | ||
readonly 0: A | ||
} | ||
/** | ||
* @category constructor | ||
* @since 2.2.0 | ||
*/ | ||
export declare const indexReadonlyNonEmptyArray: <A = never>() => Index<ReadonlyNonEmptyArray<A>, number, A>; | ||
export declare const indexReadonlyNonEmptyArray: <A = never>() => Index<ReadonlyNonEmptyArray<A>, number, A> |
@@ -6,4 +6,5 @@ "use strict"; | ||
/** | ||
* @category constructor | ||
* @since 2.2.0 | ||
*/ | ||
exports.indexReadonlyNonEmptyArray = NEA.indexNonEmptyArray; |
/** | ||
* @since 2.2.0 | ||
*/ | ||
import { Index } from '../index'; | ||
import { Index } from '..' | ||
/** | ||
* @category constructor | ||
* @since 2.2.0 | ||
*/ | ||
export declare const indexReadonlyRecord: <A = never>() => Index<Readonly<Record<string, A>>, string, A>; | ||
export declare const indexReadonlyRecord: <A = never>() => Index<Readonly<Record<string, A>>, string, A> |
@@ -6,4 +6,5 @@ "use strict"; | ||
/** | ||
* @category constructor | ||
* @since 2.2.0 | ||
*/ | ||
exports.indexReadonlyRecord = R.indexRecord; |
/** | ||
* @since 1.7.0 | ||
*/ | ||
import { Index } from '../index'; | ||
import { Index } from '..' | ||
/** | ||
* @category constructor | ||
* @since 1.7.0 | ||
*/ | ||
export declare function indexRecord<A = never>(): Index<Record<string, A>, string, A>; | ||
export declare function indexRecord<A = never>(): Index<Record<string, A>, string, A> |
@@ -7,10 +7,11 @@ "use strict"; | ||
*/ | ||
var index_1 = require("../index"); | ||
var __1 = require(".."); | ||
var Record_1 = require("../At/Record"); | ||
/** | ||
* @category constructor | ||
* @since 1.7.0 | ||
*/ | ||
function indexRecord() { | ||
return index_1.Index.fromAt(Record_1.atRecord()); | ||
return __1.Index.fromAt(Record_1.atRecord()); | ||
} | ||
exports.indexRecord = indexRecord; |
{ | ||
"name": "monocle-ts", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "A porting of scala monocle library to TypeScript", | ||
@@ -21,3 +21,4 @@ "files": [ | ||
"clean": "rimraf lib/* es6/*", | ||
"build": "npm run clean && tsc && tsc -p tsconfig.es6.json && npm run import-path-rewrite", | ||
"build": "tsc -p ./tsconfig.build.json && tsc -p ./tsconfig.build-es6.json", | ||
"postbuild": "prettier --write \"./{lib,es6}/**/*.ts\"", | ||
"prepublish": "npm run build", | ||
@@ -46,5 +47,5 @@ "docs-fix-prettier": "prettier --no-semi --single-quote --print-width 120 --parser markdown --write \"README.md\"", | ||
"@types/node": "7.0.4", | ||
"docs-ts": "^0.4.0", | ||
"docs-ts": "^0.5.0", | ||
"dtslint": "github:gcanti/dtslint", | ||
"fp-ts": "^2.0.0", | ||
"fp-ts": "^2.6.5", | ||
"import-path-rewrite": "github:gcanti/import-path-rewrite", | ||
@@ -59,3 +60,3 @@ "jest": "^24.3.0", | ||
"tslint-config-standard": "^8.0.1", | ||
"typescript": "^3.9.3" | ||
"typescript": "^3.9.5" | ||
}, | ||
@@ -75,17 +76,3 @@ "tags": [ | ||
"fp-ts" | ||
], | ||
"jest": { | ||
"collectCoverage": true, | ||
"transform": { | ||
"^.+\\.tsx?$": "ts-jest" | ||
}, | ||
"testRegex": "test", | ||
"moduleFileExtensions": [ | ||
"ts", | ||
"js" | ||
], | ||
"testPathIgnorePatterns": [ | ||
"helpers.ts" | ||
] | ||
} | ||
] | ||
} |
128
README.md
@@ -7,3 +7,3 @@ [![build status](https://img.shields.io/travis/gcanti/monocle-ts/master.svg?style=flat-square)](https://travis-ci.org/gcanti/monocle-ts) | ||
(Adapted from [monocle site](http://julien-truffaut.github.io/Monocle/)) | ||
(Adapted from [monocle site](https://www.optics.dev/Monocle/)) | ||
@@ -86,9 +86,5 @@ Modifying immutable nested object in JavaScript is verbose which makes code difficult to understand and reason about. | ||
```ts | ||
const capitalizeName = company | ||
.compose(address) | ||
.compose(street) | ||
.compose(name) | ||
.modify(capitalize) | ||
const capitalizeName = company.compose(address).compose(street).compose(name).modify(capitalize) | ||
assert.deepStrictEqual(capitalizeName(employee), employeeCapitalized) // true | ||
assert.deepStrictEqual(capitalizeName(employee), employeeCapitalized) | ||
``` | ||
@@ -119,14 +115,9 @@ | ||
const firstLetterOptional = new Optional<string, string>( | ||
s => (s.length > 0 ? some(s[0]) : none), | ||
a => s => (s.length > 0 ? a + s.substring(1) : s) | ||
(s) => (s.length > 0 ? some(s[0]) : none), | ||
(a) => (s) => (s.length > 0 ? a + s.substring(1) : s) | ||
) | ||
const firstLetter = company | ||
.compose(address) | ||
.compose(street) | ||
.compose(name) | ||
.asOptional() | ||
.compose(firstLetterOptional) | ||
const firstLetter = company.compose(address).compose(street).compose(name).asOptional().compose(firstLetterOptional) | ||
assert.deepStrictEqual(firstLetter.modify(s => s.toUpperCase())(employee), employeeCapitalized) // true | ||
assert.deepStrictEqual(firstLetter.modify((s) => s.toUpperCase())(employee), employeeCapitalized) | ||
``` | ||
@@ -154,1 +145,106 @@ | ||
- [API Reference](https://gcanti.github.io/monocle-ts/) | ||
# Experimental modules | ||
From `monocle@2.3+` you can use the following experimental modules | ||
- `Iso` | ||
- `Lens` | ||
- `Prism` | ||
- `Optional` | ||
- `Traversal` | ||
- `At` | ||
- `Ix` | ||
which implement the same features contained in `index.ts` but are `pipe`-based instead of `class`-based. | ||
Here's the same examples with the new API | ||
```ts | ||
interface Street { | ||
num: number | ||
name: string | ||
} | ||
interface Address { | ||
city: string | ||
street: Street | ||
} | ||
interface Company { | ||
name: string | ||
address: Address | ||
} | ||
interface Employee { | ||
name: string | ||
company: Company | ||
} | ||
const employee: Employee = { | ||
name: 'john', | ||
company: { | ||
name: 'awesome inc', | ||
address: { | ||
city: 'london', | ||
street: { | ||
num: 23, | ||
name: 'high street' | ||
} | ||
} | ||
} | ||
} | ||
const capitalize = (s: string): string => s.substring(0, 1).toUpperCase() + s.substring(1) | ||
const employeeCapitalized = { | ||
...employee, | ||
company: { | ||
...employee.company, | ||
address: { | ||
...employee.company.address, | ||
street: { | ||
...employee.company.address.street, | ||
name: capitalize(employee.company.address.street.name) | ||
} | ||
} | ||
} | ||
} | ||
import * as assert from 'assert' | ||
import * as L from 'monocle-ts/lib/Lens' | ||
import { pipe } from 'fp-ts/lib/function' | ||
const capitalizeName = pipe( | ||
L.id<Employee>(), | ||
L.prop('company'), | ||
L.prop('address'), | ||
L.prop('street'), | ||
L.prop('name'), | ||
L.modify(capitalize) | ||
) | ||
assert.deepStrictEqual(capitalizeName(employee), employeeCapitalized) | ||
import * as O from 'monocle-ts/lib/Optional' | ||
import { some, none } from 'fp-ts/lib/Option' | ||
const firstLetterOptional: O.Optional<string, string> = { | ||
getOption: (s) => (s.length > 0 ? some(s[0]) : none), | ||
set: (a) => (s) => (s.length > 0 ? a + s.substring(1) : s) | ||
} | ||
const firstLetter = pipe( | ||
L.id<Employee>(), | ||
L.prop('company'), | ||
L.prop('address'), | ||
L.prop('street'), | ||
L.prop('name'), | ||
L.composeOptional(firstLetterOptional) | ||
) | ||
assert.deepStrictEqual( | ||
pipe( | ||
firstLetter, | ||
O.modify((s) => s.toUpperCase()) | ||
)(employee), | ||
employeeCapitalized | ||
) | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
276538
84
9789
247