optics-ts
Advanced tools
Comparing version 1.1.0 to 1.2.0
# Changelog | ||
## 1.1.0 (unreleased) | ||
## 1.2.0 | ||
- **New features** | ||
- Add `.at()` | ||
- Make `.find()` removable | ||
- **Deprecations** | ||
- Deprecate `.index()` in favor of `.at()` | ||
- **Documentation** | ||
- `strictNullChecks` compiler option is required (#5) | ||
## 1.1.0 | ||
- **New features** | ||
- Change `.index()` to also work on strings | ||
@@ -7,0 +17,0 @@ - Add `.head()` as an alias to `.index(0)` |
@@ -272,3 +272,3 @@ var __assign = (this && this.__assign) || function () { | ||
var removeMe = Symbol('__remove_me__'); | ||
var index = function (i) { | ||
var at = function (i) { | ||
return removable(compose(lens(function (source) { return (0 <= i && i < source.length ? source[i] : noMatch); }, function (_a) { | ||
@@ -307,4 +307,9 @@ var value = _a[0], source = _a[1]; | ||
}; | ||
// Like at(0), but the zero'th index must always be defined | ||
var fst = lens(function (value) { return value[0]; }, function (_a) { | ||
var value = _a[0], source = _a[1]; | ||
return [value, source[1]]; | ||
}); | ||
var find = function (predicate) { | ||
return compose(lens(function (source) { | ||
return removable(compose(lens(function (source) { | ||
var index = source.findIndex(predicate); | ||
@@ -317,9 +322,12 @@ if (index === -1) { | ||
var _b = _a[0], value = _b[0], index = _b[1], source = _a[1]; | ||
if (value === noMatch || index === -1) { | ||
if (value === noMatch) { | ||
return source; | ||
} | ||
if (value === removeMe) { | ||
return __spreadArrays(source.slice(0, index), source.slice(index + 1)); | ||
} | ||
var result = source.slice(); | ||
result[index] = value; | ||
return result; | ||
}), index(0)); | ||
}), fst, mustMatch)); | ||
}; | ||
@@ -340,4 +348,4 @@ var filter = function (predicate) { | ||
for (var _i = 0, indexes_1 = indexes; _i < indexes_1.length; _i++) { | ||
var index_1 = indexes_1[_i]; | ||
result[index_1] = values[j]; | ||
var index = indexes_1[_i]; | ||
result[index] = values[j]; | ||
j++; | ||
@@ -377,3 +385,3 @@ } | ||
}, | ||
enumerable: true, | ||
enumerable: false, | ||
configurable: true | ||
@@ -385,3 +393,3 @@ }); | ||
}, | ||
enumerable: true, | ||
enumerable: false, | ||
configurable: true | ||
@@ -420,8 +428,11 @@ }); | ||
}; | ||
Optic.prototype.index = function (i) { | ||
return new Optic(compose(this._ref, index(i))); | ||
Optic.prototype.at = function (i) { | ||
return new Optic(compose(this._ref, at(i))); | ||
}; | ||
Optic.prototype.head = function () { | ||
return new Optic(compose(this._ref, index(0))); | ||
return new Optic(compose(this._ref, at(0))); | ||
}; | ||
Optic.prototype.index = function (i) { | ||
return new Optic(compose(this._ref, at(i))); | ||
}; | ||
Optic.prototype.find = function (predicate) { | ||
@@ -428,0 +439,0 @@ return new Optic(compose(this._ref, find(predicate))); |
import { ElemType, Eq, IfElse, RequireString, Simplify } from './utils'; | ||
import { Adapt, Apply, Choice, Compose, DisallowTypeChange, ElemUnion, Elems, HKT, Id, Path2, Path3, Path4, Path5, Plant, Prop, Optional, Union } from './hkt'; | ||
export { Apply, Compose, Eq, HKT }; | ||
export declare type OpticFor<S> = Equivalence<S, DisallowTypeChange<S>, S>; | ||
export declare type OpticFor_<S> = Equivalence<S, Id, S>; | ||
export interface Equivalence<S, T extends HKT, A> { | ||
_tag: 'Equivalence'; | ||
compose<T2 extends HKT, A2>(optic: Equivalence<A, T2, A2>): Equivalence<S, Compose<T, T2>, A2>; | ||
compose<T2 extends HKT, A2>(optic: Iso<A, T2, A2>): Iso<S, Compose<T, T2>, A2>; | ||
iso<U>(there: (a: A) => U, back: (u: U) => A): Iso<S, Compose<T, Adapt<A, U>>, U>; | ||
compose<T2 extends HKT, A2>(optic: Lens<A, T2, A2>): Lens<S, Compose<T, T2>, A2>; | ||
prop<K extends keyof A>(key: K): Lens<S, Compose<T, Prop<A, K>>, A[K]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2], K4 extends keyof A[K1][K2][K3], K5 extends keyof A[K1][K2][K3][K4]>(path: [K1, K2, K3, K4, K5]): Lens<S, Compose<T, Path5<A, K1, K2, K3, K4, K5>>, A[K1][K2][K3][K4][K5]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2], K4 extends keyof A[K1][K2][K3]>(path: [K1, K2, K3, K4]): Lens<S, Compose<T, Path4<A, K1, K2, K3, K4>>, A[K1][K2][K3][K4]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2]>(path: [K1, K2, K3]): Lens<S, Compose<T, Path3<A, K1, K2, K3>>, A[K1][K2][K3]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1]>(path: [K1, K2]): Lens<S, Compose<T, Path2<A, K1, K2>>, A[K1][K2]>; | ||
path<K1 extends keyof A>(path: [K1]): Lens<S, Compose<T, Prop<A, K1>>, A[K1]>; | ||
pick<K extends keyof A>(keys: K[]): Lens<S, Compose<T, Plant<A, K>>, Pick<A, K>>; | ||
filter(predicate: (item: ElemType<A>) => boolean): Lens<S, Compose<T, Union<A>>, A>; | ||
valueOr<B>(defaultValue: B): Lens<S, Compose<T, Id>, Exclude<A, undefined> | B>; | ||
compose<T2 extends HKT, A2>(optic: Prism<A, T2, A2>): Prism<S, Compose<T, T2>, A2>; | ||
optional(): Prism<S, Compose<T, Optional>, Exclude<A, undefined>>; | ||
guard_<F extends HKT>(): <U extends A>(g: (a: A) => a is U) => Prism<S, Compose<T, F>, U>; | ||
guard<U extends A>(g: (a: A) => a is U): Prism<S, Compose<T, Choice<A, U>>, U>; | ||
find(predicate: (item: ElemType<A>) => boolean): Prism<S, Compose<T, ElemUnion<A>>, ElemType<A>>; | ||
when(predicate: (item: A) => boolean): Prism<S, Compose<T, Union<A>>, A>; | ||
index(i: number): IfElse<Eq<A, string>, RemovablePrism<S, Compose<T, DisallowTypeChange<string>>, string>, RemovablePrism<S, Compose<T, ElemUnion<A>>, ElemType<A>>>; | ||
head(): IfElse<Eq<A, string>, RemovablePrism<S, Compose<T, DisallowTypeChange<string>>, string>, RemovablePrism<S, Compose<T, ElemUnion<A>>, ElemType<A>>>; | ||
compose<T2 extends HKT, A2>(optic: Traversal<A, T2, A2>): Traversal<S, Compose<T, T2>, A2>; | ||
elems(): Traversal<S, Compose<T, Elems>, ElemType<A>>; | ||
chars(): RequireString<A, Traversal<S, Compose<T, DisallowTypeChange<string>>, string>>; | ||
words(): RequireString<A, Traversal<S, Compose<T, DisallowTypeChange<string>>, string>>; | ||
export declare type Removable = true | undefined; | ||
export interface Params<T extends HKT, R extends Removable = undefined> { | ||
readonly _T: T; | ||
readonly _R: R; | ||
} | ||
export declare type OpticParams = Params<any, any>; | ||
export declare type NextParams<C extends OpticParams, T extends HKT, R extends Removable = undefined> = Params<Compose<C['_T'], T>, R>; | ||
export declare type NextComposeParams<C1 extends OpticParams, C2 extends OpticParams> = Params<Compose<C1['_T'], C2['_T']>, C2['_R']>; | ||
export declare type OpticFor<S> = Equivalence<S, Params<DisallowTypeChange<S>>, S>; | ||
export declare type OpticFor_<S> = Equivalence<S, Params<Id>, S>; | ||
export interface Equivalence<S, T extends OpticParams, A> { | ||
readonly _tag: 'Equivalence'; | ||
readonly _removable: T['_R']; | ||
compose<T2 extends OpticParams, A2>(optic: Equivalence<A, T2, A2>): Equivalence<S, NextComposeParams<T, T2>, A2>; | ||
compose<T2 extends OpticParams, A2>(optic: Iso<A, T2, A2>): Iso<S, NextComposeParams<T, T2>, A2>; | ||
iso<U>(there: (a: A) => U, back: (u: U) => A): Iso<S, NextParams<T, Adapt<A, U>>, U>; | ||
compose<T2 extends OpticParams, A2>(optic: Lens<A, T2, A2>): Lens<S, NextComposeParams<T, T2>, A2>; | ||
prop<K extends keyof A>(key: K): Lens<S, NextParams<T, Prop<A, K>>, A[K]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2], K4 extends keyof A[K1][K2][K3], K5 extends keyof A[K1][K2][K3][K4]>(path: [K1, K2, K3, K4, K5]): Lens<S, NextParams<T, Path5<A, K1, K2, K3, K4, K5>>, A[K1][K2][K3][K4][K5]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2], K4 extends keyof A[K1][K2][K3]>(path: [K1, K2, K3, K4]): Lens<S, NextParams<T, Path4<A, K1, K2, K3, K4>>, A[K1][K2][K3][K4]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2]>(path: [K1, K2, K3]): Lens<S, NextParams<T, Path3<A, K1, K2, K3>>, A[K1][K2][K3]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1]>(path: [K1, K2]): Lens<S, NextParams<T, Path2<A, K1, K2>>, A[K1][K2]>; | ||
path<K1 extends keyof A>(path: [K1]): Lens<S, NextParams<T, Prop<A, K1>>, A[K1]>; | ||
pick<K extends keyof A>(keys: K[]): Lens<S, NextParams<T, Plant<A, K>>, Pick<A, K>>; | ||
filter(predicate: (item: ElemType<A>) => boolean): Lens<S, NextParams<T, Union<A>>, A>; | ||
valueOr<B>(defaultValue: B): Lens<S, NextParams<T, Id>, Exclude<A, undefined> | B>; | ||
compose<T2 extends OpticParams, A2>(optic: Prism<A, T2, A2>): Prism<S, NextComposeParams<T, T2>, A2>; | ||
optional(): Prism<S, NextParams<T, Optional>, Exclude<A, undefined>>; | ||
guard_<F extends HKT>(): <U extends A>(g: (a: A) => a is U) => Prism<S, NextParams<T, F>, U>; | ||
guard<U extends A>(g: (a: A) => a is U): Prism<S, NextParams<T, Choice<A, U>>, U>; | ||
find(predicate: (item: ElemType<A>) => boolean): Prism<S, NextParams<T, ElemUnion<A>, true>, ElemType<A>>; | ||
when(predicate: (item: A) => boolean): Prism<S, NextParams<T, Union<A>>, A>; | ||
at(i: number): IfElse<Eq<A, string>, Prism<S, NextParams<T, DisallowTypeChange<string>, true>, string>, Prism<S, NextParams<T, ElemUnion<A>, true>, ElemType<A>>>; | ||
head(): IfElse<Eq<A, string>, Prism<S, NextParams<T, DisallowTypeChange<string>, true>, string>, Prism<S, NextParams<T, ElemUnion<A>, true>, ElemType<A>>>; | ||
index(i: number): IfElse<Eq<A, string>, Prism<S, NextParams<T, DisallowTypeChange<string>, true>, string>, Prism<S, NextParams<T, ElemUnion<A>, true>, ElemType<A>>>; | ||
compose<T2 extends OpticParams, A2>(optic: Traversal<A, T2, A2>): Traversal<S, NextComposeParams<T, T2>, A2>; | ||
elems(): Traversal<S, NextParams<T, Elems>, ElemType<A>>; | ||
chars(): RequireString<A, Traversal<S, NextParams<T, DisallowTypeChange<string>>, string>>; | ||
words(): RequireString<A, Traversal<S, NextParams<T, DisallowTypeChange<string>>, string>>; | ||
compose<A2>(optic: Getter<A, A2>): Getter<S, A2>; | ||
@@ -37,33 +47,35 @@ to<B>(f: (a: A) => B): Getter<S, B>; | ||
compose<A2>(optic: Fold<A, A2>): Fold<S, A2>; | ||
compose<T2 extends HKT, A2>(optic: Setter<A, T2, A2>): Setter<S, Compose<T, T2>, A2>; | ||
prependTo(): Setter<S, Compose<T, ElemUnion<A>>, ElemType<A>>; | ||
appendTo(): Setter<S, Compose<T, ElemUnion<A>>, ElemType<A>>; | ||
compose<T2 extends OpticParams, A2>(optic: Setter<A, T2, A2>): Setter<S, NextComposeParams<T, T2>, A2>; | ||
prependTo(): Setter<S, NextParams<T, ElemUnion<A>>, ElemType<A>>; | ||
appendTo(): Setter<S, NextParams<T, ElemUnion<A>>, ElemType<A>>; | ||
} | ||
export interface Iso<S, T extends HKT, A> { | ||
_tag: 'Iso'; | ||
compose<T2 extends HKT, A2>(optic: Equivalence<A, T2, A2>): Iso<S, Compose<T, T2>, A2>; | ||
compose<T2 extends HKT, A2>(optic: Iso<A, T2, A2>): Iso<S, Compose<T, T2>, A2>; | ||
iso<U>(there: (a: A) => U, back: (u: U) => A): Iso<S, Compose<T, Adapt<A, U>>, U>; | ||
compose<T2 extends HKT, A2>(optic: Lens<A, T2, A2>): Lens<S, Compose<T, T2>, A2>; | ||
prop<K extends keyof A>(key: K): Lens<S, Compose<T, Prop<A, K>>, A[K]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2], K4 extends keyof A[K1][K2][K3], K5 extends keyof A[K1][K2][K3][K4]>(path: [K1, K2, K3, K4, K5]): Lens<S, Compose<T, Path5<A, K1, K2, K3, K4, K5>>, A[K1][K2][K3][K4][K5]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2], K4 extends keyof A[K1][K2][K3]>(path: [K1, K2, K3, K4]): Lens<S, Compose<T, Path4<A, K1, K2, K3, K4>>, A[K1][K2][K3][K4]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2]>(path: [K1, K2, K3]): Lens<S, Compose<T, Path3<A, K1, K2, K3>>, A[K1][K2][K3]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1]>(path: [K1, K2]): Lens<S, Compose<T, Path2<A, K1, K2>>, A[K1][K2]>; | ||
path<K1 extends keyof A>(path: [K1]): Lens<S, Compose<T, Prop<A, K1>>, A[K1]>; | ||
pick<K extends keyof A>(keys: K[]): Lens<S, Compose<T, Plant<A, K>>, Pick<A, K>>; | ||
filter(predicate: (item: ElemType<A>) => boolean): Lens<S, Compose<T, Union<A>>, A>; | ||
valueOr<B>(defaultValue: B): Lens<S, Compose<T, Id>, Exclude<A, undefined> | B>; | ||
compose<T2 extends HKT, A2>(optic: Prism<A, T2, A2>): Prism<S, Compose<T, T2>, A2>; | ||
optional(): Prism<S, Compose<T, Optional>, Exclude<A, undefined>>; | ||
guard_<F extends HKT>(): <U extends A>(g: (a: A) => a is U) => Prism<S, Compose<T, F>, U>; | ||
guard<U extends A>(g: (a: A) => a is U): Prism<S, Compose<T, Choice<A, U>>, U>; | ||
find(predicate: (item: ElemType<A>) => boolean): Prism<S, Compose<T, ElemUnion<A>>, ElemType<A>>; | ||
when(predicate: (item: A) => boolean): Prism<S, Compose<T, Union<A>>, A>; | ||
index(i: number): IfElse<Eq<A, string>, RemovablePrism<S, Compose<T, DisallowTypeChange<string>>, string>, RemovablePrism<S, Compose<T, ElemUnion<A>>, ElemType<A>>>; | ||
head(): IfElse<Eq<A, string>, RemovablePrism<S, Compose<T, DisallowTypeChange<string>>, string>, RemovablePrism<S, Compose<T, ElemUnion<A>>, ElemType<A>>>; | ||
compose<T2 extends HKT, A2>(optic: Traversal<A, T2, A2>): Traversal<S, Compose<T, T2>, A2>; | ||
elems(): Traversal<S, Compose<T, Elems>, ElemType<A>>; | ||
chars(): RequireString<A, Traversal<S, Compose<T, DisallowTypeChange<string>>, string>>; | ||
words(): RequireString<A, Traversal<S, Compose<T, DisallowTypeChange<string>>, string>>; | ||
export interface Iso<S, T extends OpticParams, A> { | ||
readonly _tag: 'Iso'; | ||
readonly _removable: T['_R']; | ||
compose<T2 extends OpticParams, A2>(optic: Equivalence<A, T2, A2>): Iso<S, NextComposeParams<T, T2>, A2>; | ||
compose<T2 extends OpticParams, A2>(optic: Iso<A, T2, A2>): Iso<S, NextComposeParams<T, T2>, A2>; | ||
iso<U>(there: (a: A) => U, back: (u: U) => A): Iso<S, NextParams<T, Adapt<A, U>>, U>; | ||
compose<T2 extends OpticParams, A2>(optic: Lens<A, T2, A2>): Lens<S, NextComposeParams<T, T2>, A2>; | ||
prop<K extends keyof A>(key: K): Lens<S, NextParams<T, Prop<A, K>>, A[K]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2], K4 extends keyof A[K1][K2][K3], K5 extends keyof A[K1][K2][K3][K4]>(path: [K1, K2, K3, K4, K5]): Lens<S, NextParams<T, Path5<A, K1, K2, K3, K4, K5>>, A[K1][K2][K3][K4][K5]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2], K4 extends keyof A[K1][K2][K3]>(path: [K1, K2, K3, K4]): Lens<S, NextParams<T, Path4<A, K1, K2, K3, K4>>, A[K1][K2][K3][K4]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2]>(path: [K1, K2, K3]): Lens<S, NextParams<T, Path3<A, K1, K2, K3>>, A[K1][K2][K3]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1]>(path: [K1, K2]): Lens<S, NextParams<T, Path2<A, K1, K2>>, A[K1][K2]>; | ||
path<K1 extends keyof A>(path: [K1]): Lens<S, NextParams<T, Prop<A, K1>>, A[K1]>; | ||
pick<K extends keyof A>(keys: K[]): Lens<S, NextParams<T, Plant<A, K>>, Pick<A, K>>; | ||
filter(predicate: (item: ElemType<A>) => boolean): Lens<S, NextParams<T, Union<A>>, A>; | ||
valueOr<B>(defaultValue: B): Lens<S, NextParams<T, Id>, Exclude<A, undefined> | B>; | ||
compose<T2 extends OpticParams, A2>(optic: Prism<A, T2, A2>): Prism<S, NextComposeParams<T, T2>, A2>; | ||
optional(): Prism<S, NextParams<T, Optional>, Exclude<A, undefined>>; | ||
guard_<F extends HKT>(): <U extends A>(g: (a: A) => a is U) => Prism<S, NextParams<T, F>, U>; | ||
guard<U extends A>(g: (a: A) => a is U): Prism<S, NextParams<T, Choice<A, U>>, U>; | ||
find(predicate: (item: ElemType<A>) => boolean): Prism<S, NextParams<T, ElemUnion<A>, true>, ElemType<A>>; | ||
when(predicate: (item: A) => boolean): Prism<S, NextParams<T, Union<A>>, A>; | ||
at(i: number): IfElse<Eq<A, string>, Prism<S, NextParams<T, DisallowTypeChange<string>, true>, string>, Prism<S, NextParams<T, ElemUnion<A>, true>, ElemType<A>>>; | ||
head(): IfElse<Eq<A, string>, Prism<S, NextParams<T, DisallowTypeChange<string>, true>, string>, Prism<S, NextParams<T, ElemUnion<A>, true>, ElemType<A>>>; | ||
index(i: number): IfElse<Eq<A, string>, Prism<S, NextParams<T, DisallowTypeChange<string>, true>, string>, Prism<S, NextParams<T, ElemUnion<A>, true>, ElemType<A>>>; | ||
compose<T2 extends OpticParams, A2>(optic: Traversal<A, T2, A2>): Traversal<S, NextComposeParams<T, T2>, A2>; | ||
elems(): Traversal<S, NextParams<T, Elems>, ElemType<A>>; | ||
chars(): RequireString<A, Traversal<S, NextParams<T, DisallowTypeChange<string>>, string>>; | ||
words(): RequireString<A, Traversal<S, NextParams<T, DisallowTypeChange<string>>, string>>; | ||
compose<A2>(optic: Getter<A, A2>): Getter<S, A2>; | ||
@@ -73,33 +85,35 @@ to<B>(f: (a: A) => B): Getter<S, B>; | ||
compose<A2>(optic: Fold<A, A2>): Fold<S, A2>; | ||
compose<T2 extends HKT, A2>(optic: Setter<A, T2, A2>): Setter<S, Compose<T, T2>, A2>; | ||
prependTo(): Setter<S, Compose<T, ElemUnion<A>>, ElemType<A>>; | ||
appendTo(): Setter<S, Compose<T, ElemUnion<A>>, ElemType<A>>; | ||
compose<T2 extends OpticParams, A2>(optic: Setter<A, T2, A2>): Setter<S, NextComposeParams<T, T2>, A2>; | ||
prependTo(): Setter<S, NextParams<T, ElemUnion<A>>, ElemType<A>>; | ||
appendTo(): Setter<S, NextParams<T, ElemUnion<A>>, ElemType<A>>; | ||
} | ||
export interface Lens<S, T extends HKT, A> { | ||
_tag: 'Lens'; | ||
compose<T2 extends HKT, A2>(optic: Equivalence<A, T2, A2>): Lens<S, Compose<T, T2>, A2>; | ||
compose<T2 extends HKT, A2>(optic: Iso<A, T2, A2>): Lens<S, Compose<T, T2>, A2>; | ||
iso<U>(there: (a: A) => U, back: (u: U) => A): Lens<S, Compose<T, Adapt<A, U>>, U>; | ||
compose<T2 extends HKT, A2>(optic: Lens<A, T2, A2>): Lens<S, Compose<T, T2>, A2>; | ||
prop<K extends keyof A>(key: K): Lens<S, Compose<T, Prop<A, K>>, A[K]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2], K4 extends keyof A[K1][K2][K3], K5 extends keyof A[K1][K2][K3][K4]>(path: [K1, K2, K3, K4, K5]): Lens<S, Compose<T, Path5<A, K1, K2, K3, K4, K5>>, A[K1][K2][K3][K4][K5]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2], K4 extends keyof A[K1][K2][K3]>(path: [K1, K2, K3, K4]): Lens<S, Compose<T, Path4<A, K1, K2, K3, K4>>, A[K1][K2][K3][K4]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2]>(path: [K1, K2, K3]): Lens<S, Compose<T, Path3<A, K1, K2, K3>>, A[K1][K2][K3]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1]>(path: [K1, K2]): Lens<S, Compose<T, Path2<A, K1, K2>>, A[K1][K2]>; | ||
path<K1 extends keyof A>(path: [K1]): Lens<S, Compose<T, Prop<A, K1>>, A[K1]>; | ||
pick<K extends keyof A>(keys: K[]): Lens<S, Compose<T, Plant<A, K>>, Pick<A, K>>; | ||
filter(predicate: (item: ElemType<A>) => boolean): Lens<S, Compose<T, Union<A>>, A>; | ||
valueOr<B>(defaultValue: B): Lens<S, Compose<T, Id>, Exclude<A, undefined> | B>; | ||
compose<T2 extends HKT, A2>(optic: Prism<A, T2, A2>): Prism<S, Compose<T, T2>, A2>; | ||
optional(): Prism<S, Compose<T, Optional>, Exclude<A, undefined>>; | ||
guard_<F extends HKT>(): <U extends A>(g: (a: A) => a is U) => Prism<S, Compose<T, F>, U>; | ||
guard<U extends A>(g: (a: A) => a is U): Prism<S, Compose<T, Choice<A, U>>, U>; | ||
find(predicate: (item: ElemType<A>) => boolean): Prism<S, Compose<T, ElemUnion<A>>, ElemType<A>>; | ||
when(predicate: (item: A) => boolean): Prism<S, Compose<T, Union<A>>, A>; | ||
index(i: number): IfElse<Eq<A, string>, RemovablePrism<S, Compose<T, DisallowTypeChange<string>>, string>, RemovablePrism<S, Compose<T, ElemUnion<A>>, ElemType<A>>>; | ||
head(): IfElse<Eq<A, string>, RemovablePrism<S, Compose<T, DisallowTypeChange<string>>, string>, RemovablePrism<S, Compose<T, ElemUnion<A>>, ElemType<A>>>; | ||
compose<T2 extends HKT, A2>(optic: Traversal<A, T2, A2>): Traversal<S, Compose<T, T2>, A2>; | ||
elems(): Traversal<S, Compose<T, Elems>, ElemType<A>>; | ||
chars(): RequireString<A, Traversal<S, Compose<T, DisallowTypeChange<string>>, string>>; | ||
words(): RequireString<A, Traversal<S, Compose<T, DisallowTypeChange<string>>, string>>; | ||
export interface Lens<S, T extends OpticParams, A> { | ||
readonly _tag: 'Lens'; | ||
readonly _removable: T['_R']; | ||
compose<T2 extends OpticParams, A2>(optic: Equivalence<A, T2, A2>): Lens<S, NextComposeParams<T, T2>, A2>; | ||
compose<T2 extends OpticParams, A2>(optic: Iso<A, T2, A2>): Lens<S, NextComposeParams<T, T2>, A2>; | ||
iso<U>(there: (a: A) => U, back: (u: U) => A): Lens<S, NextParams<T, Adapt<A, U>>, U>; | ||
compose<T2 extends OpticParams, A2>(optic: Lens<A, T2, A2>): Lens<S, NextComposeParams<T, T2>, A2>; | ||
prop<K extends keyof A>(key: K): Lens<S, NextParams<T, Prop<A, K>>, A[K]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2], K4 extends keyof A[K1][K2][K3], K5 extends keyof A[K1][K2][K3][K4]>(path: [K1, K2, K3, K4, K5]): Lens<S, NextParams<T, Path5<A, K1, K2, K3, K4, K5>>, A[K1][K2][K3][K4][K5]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2], K4 extends keyof A[K1][K2][K3]>(path: [K1, K2, K3, K4]): Lens<S, NextParams<T, Path4<A, K1, K2, K3, K4>>, A[K1][K2][K3][K4]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2]>(path: [K1, K2, K3]): Lens<S, NextParams<T, Path3<A, K1, K2, K3>>, A[K1][K2][K3]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1]>(path: [K1, K2]): Lens<S, NextParams<T, Path2<A, K1, K2>>, A[K1][K2]>; | ||
path<K1 extends keyof A>(path: [K1]): Lens<S, NextParams<T, Prop<A, K1>>, A[K1]>; | ||
pick<K extends keyof A>(keys: K[]): Lens<S, NextParams<T, Plant<A, K>>, Pick<A, K>>; | ||
filter(predicate: (item: ElemType<A>) => boolean): Lens<S, NextParams<T, Union<A>>, A>; | ||
valueOr<B>(defaultValue: B): Lens<S, NextParams<T, Id>, Exclude<A, undefined> | B>; | ||
compose<T2 extends OpticParams, A2>(optic: Prism<A, T2, A2>): Prism<S, NextComposeParams<T, T2>, A2>; | ||
optional(): Prism<S, NextParams<T, Optional>, Exclude<A, undefined>>; | ||
guard_<F extends HKT>(): <U extends A>(g: (a: A) => a is U) => Prism<S, NextParams<T, F>, U>; | ||
guard<U extends A>(g: (a: A) => a is U): Prism<S, NextParams<T, Choice<A, U>>, U>; | ||
find(predicate: (item: ElemType<A>) => boolean): Prism<S, NextParams<T, ElemUnion<A>, true>, ElemType<A>>; | ||
when(predicate: (item: A) => boolean): Prism<S, NextParams<T, Union<A>>, A>; | ||
at(i: number): IfElse<Eq<A, string>, Prism<S, NextParams<T, DisallowTypeChange<string>, true>, string>, Prism<S, NextParams<T, ElemUnion<A>, true>, ElemType<A>>>; | ||
head(): IfElse<Eq<A, string>, Prism<S, NextParams<T, DisallowTypeChange<string>, true>, string>, Prism<S, NextParams<T, ElemUnion<A>, true>, ElemType<A>>>; | ||
index(i: number): IfElse<Eq<A, string>, Prism<S, NextParams<T, DisallowTypeChange<string>, true>, string>, Prism<S, NextParams<T, ElemUnion<A>, true>, ElemType<A>>>; | ||
compose<T2 extends OpticParams, A2>(optic: Traversal<A, T2, A2>): Traversal<S, NextComposeParams<T, T2>, A2>; | ||
elems(): Traversal<S, NextParams<T, Elems>, ElemType<A>>; | ||
chars(): RequireString<A, Traversal<S, NextParams<T, DisallowTypeChange<string>>, string>>; | ||
words(): RequireString<A, Traversal<S, NextParams<T, DisallowTypeChange<string>>, string>>; | ||
compose<A2>(optic: Getter<A, A2>): Getter<S, A2>; | ||
@@ -109,34 +123,35 @@ to<B>(f: (a: A) => B): Getter<S, B>; | ||
compose<A2>(optic: Fold<A, A2>): Fold<S, A2>; | ||
compose<T2 extends HKT, A2>(optic: Setter<A, T2, A2>): Setter<S, Compose<T, T2>, A2>; | ||
prependTo(): Setter<S, Compose<T, ElemUnion<A>>, ElemType<A>>; | ||
appendTo(): Setter<S, Compose<T, ElemUnion<A>>, ElemType<A>>; | ||
compose<T2 extends OpticParams, A2>(optic: Setter<A, T2, A2>): Setter<S, NextComposeParams<T, T2>, A2>; | ||
prependTo(): Setter<S, NextParams<T, ElemUnion<A>>, ElemType<A>>; | ||
appendTo(): Setter<S, NextParams<T, ElemUnion<A>>, ElemType<A>>; | ||
} | ||
export interface Prism<S, T extends HKT, A> { | ||
_tag: 'Prism'; | ||
_removable?: true | undefined; | ||
compose<T2 extends HKT, A2>(optic: Equivalence<A, T2, A2>): Prism<S, Compose<T, T2>, A2>; | ||
compose<T2 extends HKT, A2>(optic: Iso<A, T2, A2>): Prism<S, Compose<T, T2>, A2>; | ||
iso<U>(there: (a: A) => U, back: (u: U) => A): Prism<S, Compose<T, Adapt<A, U>>, U>; | ||
compose<T2 extends HKT, A2>(optic: Lens<A, T2, A2>): Prism<S, Compose<T, T2>, A2>; | ||
prop<K extends keyof A>(key: K): Prism<S, Compose<T, Prop<A, K>>, A[K]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2], K4 extends keyof A[K1][K2][K3], K5 extends keyof A[K1][K2][K3][K4]>(path: [K1, K2, K3, K4, K5]): Prism<S, Compose<T, Path5<A, K1, K2, K3, K4, K5>>, A[K1][K2][K3][K4][K5]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2], K4 extends keyof A[K1][K2][K3]>(path: [K1, K2, K3, K4]): Prism<S, Compose<T, Path4<A, K1, K2, K3, K4>>, A[K1][K2][K3][K4]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2]>(path: [K1, K2, K3]): Prism<S, Compose<T, Path3<A, K1, K2, K3>>, A[K1][K2][K3]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1]>(path: [K1, K2]): Prism<S, Compose<T, Path2<A, K1, K2>>, A[K1][K2]>; | ||
path<K1 extends keyof A>(path: [K1]): Prism<S, Compose<T, Prop<A, K1>>, A[K1]>; | ||
pick<K extends keyof A>(keys: K[]): Prism<S, Compose<T, Plant<A, K>>, Pick<A, K>>; | ||
filter(predicate: (item: ElemType<A>) => boolean): Prism<S, Compose<T, Union<A>>, A>; | ||
valueOr<B>(defaultValue: B): Prism<S, Compose<T, Id>, Exclude<A, undefined> | B>; | ||
compose<T2 extends HKT, A2>(optic: Prism<A, T2, A2>): Prism<S, Compose<T, T2>, A2>; | ||
optional(): Prism<S, Compose<T, Optional>, Exclude<A, undefined>>; | ||
guard_<F extends HKT>(): <U extends A>(g: (a: A) => a is U) => Prism<S, Compose<T, F>, U>; | ||
guard<U extends A>(g: (a: A) => a is U): Prism<S, Compose<T, Choice<A, U>>, U>; | ||
find(predicate: (item: ElemType<A>) => boolean): Prism<S, Compose<T, ElemUnion<A>>, ElemType<A>>; | ||
when(predicate: (item: A) => boolean): Prism<S, Compose<T, Union<A>>, A>; | ||
index(i: number): IfElse<Eq<A, string>, RemovablePrism<S, Compose<T, DisallowTypeChange<string>>, string>, RemovablePrism<S, Compose<T, ElemUnion<A>>, ElemType<A>>>; | ||
head(): IfElse<Eq<A, string>, RemovablePrism<S, Compose<T, DisallowTypeChange<string>>, string>, RemovablePrism<S, Compose<T, ElemUnion<A>>, ElemType<A>>>; | ||
compose<T2 extends HKT, A2>(optic: Traversal<A, T2, A2>): Traversal<S, Compose<T, T2>, A2>; | ||
elems(): Traversal<S, Compose<T, Elems>, ElemType<A>>; | ||
chars(): RequireString<A, Traversal<S, Compose<T, DisallowTypeChange<string>>, string>>; | ||
words(): RequireString<A, Traversal<S, Compose<T, DisallowTypeChange<string>>, string>>; | ||
export interface Prism<S, T extends OpticParams, A> { | ||
readonly _tag: 'Prism'; | ||
readonly _removable: T['_R']; | ||
compose<T2 extends OpticParams, A2>(optic: Equivalence<A, T2, A2>): Prism<S, NextComposeParams<T, T2>, A2>; | ||
compose<T2 extends OpticParams, A2>(optic: Iso<A, T2, A2>): Prism<S, NextComposeParams<T, T2>, A2>; | ||
iso<U>(there: (a: A) => U, back: (u: U) => A): Prism<S, NextParams<T, Adapt<A, U>>, U>; | ||
compose<T2 extends OpticParams, A2>(optic: Lens<A, T2, A2>): Prism<S, NextComposeParams<T, T2>, A2>; | ||
prop<K extends keyof A>(key: K): Prism<S, NextParams<T, Prop<A, K>>, A[K]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2], K4 extends keyof A[K1][K2][K3], K5 extends keyof A[K1][K2][K3][K4]>(path: [K1, K2, K3, K4, K5]): Prism<S, NextParams<T, Path5<A, K1, K2, K3, K4, K5>>, A[K1][K2][K3][K4][K5]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2], K4 extends keyof A[K1][K2][K3]>(path: [K1, K2, K3, K4]): Prism<S, NextParams<T, Path4<A, K1, K2, K3, K4>>, A[K1][K2][K3][K4]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2]>(path: [K1, K2, K3]): Prism<S, NextParams<T, Path3<A, K1, K2, K3>>, A[K1][K2][K3]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1]>(path: [K1, K2]): Prism<S, NextParams<T, Path2<A, K1, K2>>, A[K1][K2]>; | ||
path<K1 extends keyof A>(path: [K1]): Prism<S, NextParams<T, Prop<A, K1>>, A[K1]>; | ||
pick<K extends keyof A>(keys: K[]): Prism<S, NextParams<T, Plant<A, K>>, Pick<A, K>>; | ||
filter(predicate: (item: ElemType<A>) => boolean): Prism<S, NextParams<T, Union<A>>, A>; | ||
valueOr<B>(defaultValue: B): Prism<S, NextParams<T, Id>, Exclude<A, undefined> | B>; | ||
compose<T2 extends OpticParams, A2>(optic: Prism<A, T2, A2>): Prism<S, NextComposeParams<T, T2>, A2>; | ||
optional(): Prism<S, NextParams<T, Optional>, Exclude<A, undefined>>; | ||
guard_<F extends HKT>(): <U extends A>(g: (a: A) => a is U) => Prism<S, NextParams<T, F>, U>; | ||
guard<U extends A>(g: (a: A) => a is U): Prism<S, NextParams<T, Choice<A, U>>, U>; | ||
find(predicate: (item: ElemType<A>) => boolean): Prism<S, NextParams<T, ElemUnion<A>, true>, ElemType<A>>; | ||
when(predicate: (item: A) => boolean): Prism<S, NextParams<T, Union<A>>, A>; | ||
at(i: number): IfElse<Eq<A, string>, Prism<S, NextParams<T, DisallowTypeChange<string>, true>, string>, Prism<S, NextParams<T, ElemUnion<A>, true>, ElemType<A>>>; | ||
head(): IfElse<Eq<A, string>, Prism<S, NextParams<T, DisallowTypeChange<string>, true>, string>, Prism<S, NextParams<T, ElemUnion<A>, true>, ElemType<A>>>; | ||
index(i: number): IfElse<Eq<A, string>, Prism<S, NextParams<T, DisallowTypeChange<string>, true>, string>, Prism<S, NextParams<T, ElemUnion<A>, true>, ElemType<A>>>; | ||
compose<T2 extends OpticParams, A2>(optic: Traversal<A, T2, A2>): Traversal<S, NextComposeParams<T, T2>, A2>; | ||
elems(): Traversal<S, NextParams<T, Elems>, ElemType<A>>; | ||
chars(): RequireString<A, Traversal<S, NextParams<T, DisallowTypeChange<string>>, string>>; | ||
words(): RequireString<A, Traversal<S, NextParams<T, DisallowTypeChange<string>>, string>>; | ||
compose<A2>(optic: Getter<A, A2>): AffineFold<S, A2>; | ||
@@ -146,34 +161,35 @@ to<B>(f: (a: A) => B): AffineFold<S, B>; | ||
compose<A2>(optic: Fold<A, A2>): Fold<S, A2>; | ||
compose<T2 extends HKT, A2>(optic: Setter<A, T2, A2>): Setter<S, Compose<T, T2>, A2>; | ||
prependTo(): Setter<S, Compose<T, ElemUnion<A>>, ElemType<A>>; | ||
appendTo(): Setter<S, Compose<T, ElemUnion<A>>, ElemType<A>>; | ||
compose<T2 extends OpticParams, A2>(optic: Setter<A, T2, A2>): Setter<S, NextComposeParams<T, T2>, A2>; | ||
prependTo(): Setter<S, NextParams<T, ElemUnion<A>>, ElemType<A>>; | ||
appendTo(): Setter<S, NextParams<T, ElemUnion<A>>, ElemType<A>>; | ||
} | ||
export interface Traversal<S, T extends HKT, A> { | ||
_tag: 'Traversal'; | ||
_removable?: true | undefined; | ||
compose<T2 extends HKT, A2>(optic: Equivalence<A, T2, A2>): Traversal<S, Compose<T, T2>, A2>; | ||
compose<T2 extends HKT, A2>(optic: Iso<A, T2, A2>): Traversal<S, Compose<T, T2>, A2>; | ||
iso<U>(there: (a: A) => U, back: (u: U) => A): Traversal<S, Compose<T, Adapt<A, U>>, U>; | ||
compose<T2 extends HKT, A2>(optic: Lens<A, T2, A2>): Traversal<S, Compose<T, T2>, A2>; | ||
prop<K extends keyof A>(key: K): Traversal<S, Compose<T, Prop<A, K>>, A[K]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2], K4 extends keyof A[K1][K2][K3], K5 extends keyof A[K1][K2][K3][K4]>(path: [K1, K2, K3, K4, K5]): Traversal<S, Compose<T, Path5<A, K1, K2, K3, K4, K5>>, A[K1][K2][K3][K4][K5]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2], K4 extends keyof A[K1][K2][K3]>(path: [K1, K2, K3, K4]): Traversal<S, Compose<T, Path4<A, K1, K2, K3, K4>>, A[K1][K2][K3][K4]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2]>(path: [K1, K2, K3]): Traversal<S, Compose<T, Path3<A, K1, K2, K3>>, A[K1][K2][K3]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1]>(path: [K1, K2]): Traversal<S, Compose<T, Path2<A, K1, K2>>, A[K1][K2]>; | ||
path<K1 extends keyof A>(path: [K1]): Traversal<S, Compose<T, Prop<A, K1>>, A[K1]>; | ||
pick<K extends keyof A>(keys: K[]): Traversal<S, Compose<T, Plant<A, K>>, Pick<A, K>>; | ||
filter(predicate: (item: ElemType<A>) => boolean): Traversal<S, Compose<T, Union<A>>, A>; | ||
valueOr<B>(defaultValue: B): Traversal<S, Compose<T, Id>, Exclude<A, undefined> | B>; | ||
compose<T2 extends HKT, A2>(optic: Prism<A, T2, A2>): Traversal<S, Compose<T, T2>, A2>; | ||
optional(): Traversal<S, Compose<T, Optional>, Exclude<A, undefined>>; | ||
guard_<F extends HKT>(): <U extends A>(g: (a: A) => a is U) => Traversal<S, Compose<T, F>, U>; | ||
guard<U extends A>(g: (a: A) => a is U): Traversal<S, Compose<T, Choice<A, U>>, U>; | ||
find(predicate: (item: ElemType<A>) => boolean): Traversal<S, Compose<T, ElemUnion<A>>, ElemType<A>>; | ||
when(predicate: (item: A) => boolean): Traversal<S, Compose<T, Union<A>>, A>; | ||
index(i: number): IfElse<Eq<A, string>, RemovableTraversal<S, Compose<T, DisallowTypeChange<string>>, string>, RemovableTraversal<S, Compose<T, ElemUnion<A>>, ElemType<A>>>; | ||
head(): IfElse<Eq<A, string>, RemovableTraversal<S, Compose<T, DisallowTypeChange<string>>, string>, RemovableTraversal<S, Compose<T, ElemUnion<A>>, ElemType<A>>>; | ||
compose<T2 extends HKT, A2>(optic: Traversal<A, T2, A2>): Traversal<S, Compose<T, T2>, A2>; | ||
elems(): Traversal<S, Compose<T, Elems>, ElemType<A>>; | ||
chars(): RequireString<A, Traversal<S, Compose<T, DisallowTypeChange<string>>, string>>; | ||
words(): RequireString<A, Traversal<S, Compose<T, DisallowTypeChange<string>>, string>>; | ||
export interface Traversal<S, T extends OpticParams, A> { | ||
readonly _tag: 'Traversal'; | ||
readonly _removable: T['_R']; | ||
compose<T2 extends OpticParams, A2>(optic: Equivalence<A, T2, A2>): Traversal<S, NextComposeParams<T, T2>, A2>; | ||
compose<T2 extends OpticParams, A2>(optic: Iso<A, T2, A2>): Traversal<S, NextComposeParams<T, T2>, A2>; | ||
iso<U>(there: (a: A) => U, back: (u: U) => A): Traversal<S, NextParams<T, Adapt<A, U>>, U>; | ||
compose<T2 extends OpticParams, A2>(optic: Lens<A, T2, A2>): Traversal<S, NextComposeParams<T, T2>, A2>; | ||
prop<K extends keyof A>(key: K): Traversal<S, NextParams<T, Prop<A, K>>, A[K]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2], K4 extends keyof A[K1][K2][K3], K5 extends keyof A[K1][K2][K3][K4]>(path: [K1, K2, K3, K4, K5]): Traversal<S, NextParams<T, Path5<A, K1, K2, K3, K4, K5>>, A[K1][K2][K3][K4][K5]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2], K4 extends keyof A[K1][K2][K3]>(path: [K1, K2, K3, K4]): Traversal<S, NextParams<T, Path4<A, K1, K2, K3, K4>>, A[K1][K2][K3][K4]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2]>(path: [K1, K2, K3]): Traversal<S, NextParams<T, Path3<A, K1, K2, K3>>, A[K1][K2][K3]>; | ||
path<K1 extends keyof A, K2 extends keyof A[K1]>(path: [K1, K2]): Traversal<S, NextParams<T, Path2<A, K1, K2>>, A[K1][K2]>; | ||
path<K1 extends keyof A>(path: [K1]): Traversal<S, NextParams<T, Prop<A, K1>>, A[K1]>; | ||
pick<K extends keyof A>(keys: K[]): Traversal<S, NextParams<T, Plant<A, K>>, Pick<A, K>>; | ||
filter(predicate: (item: ElemType<A>) => boolean): Traversal<S, NextParams<T, Union<A>>, A>; | ||
valueOr<B>(defaultValue: B): Traversal<S, NextParams<T, Id>, Exclude<A, undefined> | B>; | ||
compose<T2 extends OpticParams, A2>(optic: Prism<A, T2, A2>): Traversal<S, NextComposeParams<T, T2>, A2>; | ||
optional(): Traversal<S, NextParams<T, Optional>, Exclude<A, undefined>>; | ||
guard_<F extends HKT>(): <U extends A>(g: (a: A) => a is U) => Traversal<S, NextParams<T, F>, U>; | ||
guard<U extends A>(g: (a: A) => a is U): Traversal<S, NextParams<T, Choice<A, U>>, U>; | ||
find(predicate: (item: ElemType<A>) => boolean): Traversal<S, NextParams<T, ElemUnion<A>, true>, ElemType<A>>; | ||
when(predicate: (item: A) => boolean): Traversal<S, NextParams<T, Union<A>>, A>; | ||
at(i: number): IfElse<Eq<A, string>, Traversal<S, NextParams<T, DisallowTypeChange<string>, true>, string>, Traversal<S, NextParams<T, ElemUnion<A>, true>, ElemType<A>>>; | ||
head(): IfElse<Eq<A, string>, Traversal<S, NextParams<T, DisallowTypeChange<string>, true>, string>, Traversal<S, NextParams<T, ElemUnion<A>, true>, ElemType<A>>>; | ||
index(i: number): IfElse<Eq<A, string>, Traversal<S, NextParams<T, DisallowTypeChange<string>, true>, string>, Traversal<S, NextParams<T, ElemUnion<A>, true>, ElemType<A>>>; | ||
compose<T2 extends OpticParams, A2>(optic: Traversal<A, T2, A2>): Traversal<S, NextComposeParams<T, T2>, A2>; | ||
elems(): Traversal<S, NextParams<T, Elems>, ElemType<A>>; | ||
chars(): RequireString<A, Traversal<S, NextParams<T, DisallowTypeChange<string>>, string>>; | ||
words(): RequireString<A, Traversal<S, NextParams<T, DisallowTypeChange<string>>, string>>; | ||
compose<A2>(optic: Getter<A, A2>): Fold<S, A2>; | ||
@@ -183,12 +199,12 @@ to<B>(f: (a: A) => B): Fold<S, B>; | ||
compose<A2>(optic: Fold<A, A2>): Fold<S, A2>; | ||
compose<T2 extends HKT, A2>(optic: Setter<A, T2, A2>): Setter<S, Compose<T, T2>, A2>; | ||
prependTo(): Setter<S, Compose<T, ElemUnion<A>>, ElemType<A>>; | ||
appendTo(): Setter<S, Compose<T, ElemUnion<A>>, ElemType<A>>; | ||
compose<T2 extends OpticParams, A2>(optic: Setter<A, T2, A2>): Setter<S, NextComposeParams<T, T2>, A2>; | ||
prependTo(): Setter<S, NextParams<T, ElemUnion<A>>, ElemType<A>>; | ||
appendTo(): Setter<S, NextParams<T, ElemUnion<A>>, ElemType<A>>; | ||
} | ||
export interface Getter<S, A> { | ||
_tag: 'Getter'; | ||
compose<T2 extends HKT, A2>(optic: Equivalence<A, T2, A2>): Getter<S, A2>; | ||
compose<T2 extends HKT, A2>(optic: Iso<A, T2, A2>): Getter<S, A2>; | ||
readonly _tag: 'Getter'; | ||
compose<T2 extends OpticParams, A2>(optic: Equivalence<A, T2, A2>): Getter<S, A2>; | ||
compose<T2 extends OpticParams, A2>(optic: Iso<A, T2, A2>): Getter<S, A2>; | ||
iso<U>(there: (a: A) => U, back: (u: U) => A): Getter<S, U>; | ||
compose<T2 extends HKT, A2>(optic: Lens<A, T2, A2>): Getter<S, A2>; | ||
compose<T2 extends OpticParams, A2>(optic: Lens<A, T2, A2>): Getter<S, A2>; | ||
prop<K extends keyof A>(key: K): Getter<S, A[K]>; | ||
@@ -203,3 +219,3 @@ path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2], K4 extends keyof A[K1][K2][K3], K5 extends keyof A[K1][K2][K3][K4]>(path: [K1, K2, K3, K4, K5]): Getter<S, A[K1][K2][K3][K4][K5]>; | ||
valueOr<B>(defaultValue: B): Getter<S, Exclude<A, undefined> | B>; | ||
compose<T2 extends HKT, A2>(optic: Prism<A, T2, A2>): AffineFold<S, A2>; | ||
compose<T2 extends OpticParams, A2>(optic: Prism<A, T2, A2>): AffineFold<S, A2>; | ||
optional(): AffineFold<S, Exclude<A, undefined>>; | ||
@@ -210,5 +226,6 @@ guard_<F extends HKT>(): <U extends A>(g: (a: A) => a is U) => AffineFold<S, U>; | ||
when(predicate: (item: A) => boolean): AffineFold<S, A>; | ||
at(i: number): IfElse<Eq<A, string>, AffineFold<S, string>, AffineFold<S, ElemType<A>>>; | ||
head(): IfElse<Eq<A, string>, AffineFold<S, string>, AffineFold<S, ElemType<A>>>; | ||
index(i: number): IfElse<Eq<A, string>, AffineFold<S, string>, AffineFold<S, ElemType<A>>>; | ||
head(): IfElse<Eq<A, string>, AffineFold<S, string>, AffineFold<S, ElemType<A>>>; | ||
compose<T2 extends HKT, A2>(optic: Traversal<A, T2, A2>): Fold<S, A2>; | ||
compose<T2 extends OpticParams, A2>(optic: Traversal<A, T2, A2>): Fold<S, A2>; | ||
elems(): Fold<S, ElemType<A>>; | ||
@@ -223,7 +240,7 @@ chars(): RequireString<A, Fold<S, string>>; | ||
export interface AffineFold<S, A> { | ||
_tag: 'AffineFold'; | ||
compose<T2 extends HKT, A2>(optic: Equivalence<A, T2, A2>): AffineFold<S, A2>; | ||
compose<T2 extends HKT, A2>(optic: Iso<A, T2, A2>): AffineFold<S, A2>; | ||
readonly _tag: 'AffineFold'; | ||
compose<T2 extends OpticParams, A2>(optic: Equivalence<A, T2, A2>): AffineFold<S, A2>; | ||
compose<T2 extends OpticParams, A2>(optic: Iso<A, T2, A2>): AffineFold<S, A2>; | ||
iso<U>(there: (a: A) => U, back: (u: U) => A): AffineFold<S, U>; | ||
compose<T2 extends HKT, A2>(optic: Lens<A, T2, A2>): AffineFold<S, A2>; | ||
compose<T2 extends OpticParams, A2>(optic: Lens<A, T2, A2>): AffineFold<S, A2>; | ||
prop<K extends keyof A>(key: K): AffineFold<S, A[K]>; | ||
@@ -238,3 +255,3 @@ path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2], K4 extends keyof A[K1][K2][K3], K5 extends keyof A[K1][K2][K3][K4]>(path: [K1, K2, K3, K4, K5]): AffineFold<S, A[K1][K2][K3][K4][K5]>; | ||
valueOr<B>(defaultValue: B): AffineFold<S, Exclude<A, undefined> | B>; | ||
compose<T2 extends HKT, A2>(optic: Prism<A, T2, A2>): AffineFold<S, A2>; | ||
compose<T2 extends OpticParams, A2>(optic: Prism<A, T2, A2>): AffineFold<S, A2>; | ||
optional(): AffineFold<S, Exclude<A, undefined>>; | ||
@@ -245,5 +262,6 @@ guard_<F extends HKT>(): <U extends A>(g: (a: A) => a is U) => AffineFold<S, U>; | ||
when(predicate: (item: A) => boolean): AffineFold<S, A>; | ||
at(i: number): IfElse<Eq<A, string>, AffineFold<S, string>, AffineFold<S, ElemType<A>>>; | ||
head(): IfElse<Eq<A, string>, AffineFold<S, string>, AffineFold<S, ElemType<A>>>; | ||
index(i: number): IfElse<Eq<A, string>, AffineFold<S, string>, AffineFold<S, ElemType<A>>>; | ||
head(): IfElse<Eq<A, string>, AffineFold<S, string>, AffineFold<S, ElemType<A>>>; | ||
compose<T2 extends HKT, A2>(optic: Traversal<A, T2, A2>): Fold<S, A2>; | ||
compose<T2 extends OpticParams, A2>(optic: Traversal<A, T2, A2>): Fold<S, A2>; | ||
elems(): Fold<S, ElemType<A>>; | ||
@@ -258,7 +276,7 @@ chars(): RequireString<A, Fold<S, string>>; | ||
export interface Fold<S, A> { | ||
_tag: 'Fold'; | ||
compose<T2 extends HKT, A2>(optic: Equivalence<A, T2, A2>): Fold<S, A2>; | ||
compose<T2 extends HKT, A2>(optic: Iso<A, T2, A2>): Fold<S, A2>; | ||
readonly _tag: 'Fold'; | ||
compose<T2 extends OpticParams, A2>(optic: Equivalence<A, T2, A2>): Fold<S, A2>; | ||
compose<T2 extends OpticParams, A2>(optic: Iso<A, T2, A2>): Fold<S, A2>; | ||
iso<U>(there: (a: A) => U, back: (u: U) => A): Fold<S, U>; | ||
compose<T2 extends HKT, A2>(optic: Lens<A, T2, A2>): Fold<S, A2>; | ||
compose<T2 extends OpticParams, A2>(optic: Lens<A, T2, A2>): Fold<S, A2>; | ||
prop<K extends keyof A>(key: K): Fold<S, A[K]>; | ||
@@ -273,3 +291,3 @@ path<K1 extends keyof A, K2 extends keyof A[K1], K3 extends keyof A[K1][K2], K4 extends keyof A[K1][K2][K3], K5 extends keyof A[K1][K2][K3][K4]>(path: [K1, K2, K3, K4, K5]): Fold<S, A[K1][K2][K3][K4][K5]>; | ||
valueOr<B>(defaultValue: B): Fold<S, Exclude<A, undefined> | B>; | ||
compose<T2 extends HKT, A2>(optic: Prism<A, T2, A2>): Fold<S, A2>; | ||
compose<T2 extends OpticParams, A2>(optic: Prism<A, T2, A2>): Fold<S, A2>; | ||
optional(): Fold<S, Exclude<A, undefined>>; | ||
@@ -280,5 +298,6 @@ guard_<F extends HKT>(): <U extends A>(g: (a: A) => a is U) => Fold<S, U>; | ||
when(predicate: (item: A) => boolean): Fold<S, A>; | ||
at(i: number): IfElse<Eq<A, string>, Fold<S, string>, Fold<S, ElemType<A>>>; | ||
head(): IfElse<Eq<A, string>, Fold<S, string>, Fold<S, ElemType<A>>>; | ||
index(i: number): IfElse<Eq<A, string>, Fold<S, string>, Fold<S, ElemType<A>>>; | ||
head(): IfElse<Eq<A, string>, Fold<S, string>, Fold<S, ElemType<A>>>; | ||
compose<T2 extends HKT, A2>(optic: Traversal<A, T2, A2>): Fold<S, A2>; | ||
compose<T2 extends OpticParams, A2>(optic: Traversal<A, T2, A2>): Fold<S, A2>; | ||
elems(): Fold<S, ElemType<A>>; | ||
@@ -292,83 +311,72 @@ chars(): RequireString<A, Fold<S, string>>; | ||
} | ||
export interface Setter<S, T extends HKT, A> { | ||
_tag: 'Setter'; | ||
export interface Setter<S, T extends OpticParams, A> { | ||
readonly _tag: 'Setter'; | ||
readonly _removable: T['_R']; | ||
} | ||
export interface RemovablePrism<S, T extends HKT, A> extends Prism<S, T, A> { | ||
_removable: true; | ||
} | ||
export interface NonRemovablePrism<S, T extends HKT, A> extends Prism<S, T, A> { | ||
_removable: undefined; | ||
} | ||
export interface RemovableTraversal<S, T extends HKT, A> extends Traversal<S, T, A> { | ||
_removable: true; | ||
} | ||
export interface NonRemovableTraversal<S, T extends HKT, A> extends Traversal<S, T, A> { | ||
_removable: undefined; | ||
} | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Equivalence<S, T, A>, optic2: Equivalence<A, T2, A2>): Equivalence<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Equivalence<S, T, A>, optic2: Iso<A, T2, A2>): Iso<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Equivalence<S, T, A>, optic2: Lens<A, T2, A2>): Lens<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Equivalence<S, T, A>, optic2: Prism<A, T2, A2>): Prism<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Equivalence<S, T, A>, optic2: Traversal<A, T2, A2>): Traversal<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, A2>(optic1: Equivalence<S, T, A>, optic2: Getter<A, A2>): Getter<S, A2>; | ||
export declare function compose<S, T extends HKT, A, A2>(optic1: Equivalence<S, T, A>, optic2: AffineFold<A, A2>): AffineFold<S, A2>; | ||
export declare function compose<S, T extends HKT, A, A2>(optic1: Equivalence<S, T, A>, optic2: Fold<A, A2>): Fold<S, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Equivalence<S, T, A>, optic2: Setter<A, T2, A2>): Setter<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Iso<S, T, A>, optic2: Equivalence<A, T2, A2>): Iso<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Iso<S, T, A>, optic2: Iso<A, T2, A2>): Iso<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Iso<S, T, A>, optic2: Lens<A, T2, A2>): Lens<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Iso<S, T, A>, optic2: Prism<A, T2, A2>): Prism<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Iso<S, T, A>, optic2: Traversal<A, T2, A2>): Traversal<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, A2>(optic1: Iso<S, T, A>, optic2: Getter<A, A2>): Getter<S, A2>; | ||
export declare function compose<S, T extends HKT, A, A2>(optic1: Iso<S, T, A>, optic2: AffineFold<A, A2>): AffineFold<S, A2>; | ||
export declare function compose<S, T extends HKT, A, A2>(optic1: Iso<S, T, A>, optic2: Fold<A, A2>): Fold<S, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Iso<S, T, A>, optic2: Setter<A, T2, A2>): Setter<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Lens<S, T, A>, optic2: Equivalence<A, T2, A2>): Lens<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Lens<S, T, A>, optic2: Iso<A, T2, A2>): Lens<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Lens<S, T, A>, optic2: Lens<A, T2, A2>): Lens<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Lens<S, T, A>, optic2: Prism<A, T2, A2>): Prism<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Lens<S, T, A>, optic2: Traversal<A, T2, A2>): Traversal<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, A2>(optic1: Lens<S, T, A>, optic2: Getter<A, A2>): Getter<S, A2>; | ||
export declare function compose<S, T extends HKT, A, A2>(optic1: Lens<S, T, A>, optic2: AffineFold<A, A2>): AffineFold<S, A2>; | ||
export declare function compose<S, T extends HKT, A, A2>(optic1: Lens<S, T, A>, optic2: Fold<A, A2>): Fold<S, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Lens<S, T, A>, optic2: Setter<A, T2, A2>): Setter<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Prism<S, T, A>, optic2: Equivalence<A, T2, A2>): Prism<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Prism<S, T, A>, optic2: Iso<A, T2, A2>): Prism<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Prism<S, T, A>, optic2: Lens<A, T2, A2>): Prism<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Prism<S, T, A>, optic2: Prism<A, T2, A2>): Prism<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Prism<S, T, A>, optic2: Traversal<A, T2, A2>): Traversal<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, A2>(optic1: Prism<S, T, A>, optic2: Getter<A, A2>): AffineFold<S, A2>; | ||
export declare function compose<S, T extends HKT, A, A2>(optic1: Prism<S, T, A>, optic2: AffineFold<A, A2>): AffineFold<S, A2>; | ||
export declare function compose<S, T extends HKT, A, A2>(optic1: Prism<S, T, A>, optic2: Fold<A, A2>): Fold<S, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Prism<S, T, A>, optic2: Setter<A, T2, A2>): Setter<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Traversal<S, T, A>, optic2: Equivalence<A, T2, A2>): Traversal<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Traversal<S, T, A>, optic2: Iso<A, T2, A2>): Traversal<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Traversal<S, T, A>, optic2: Lens<A, T2, A2>): Traversal<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Traversal<S, T, A>, optic2: Prism<A, T2, A2>): Traversal<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Traversal<S, T, A>, optic2: Traversal<A, T2, A2>): Traversal<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, T extends HKT, A, A2>(optic1: Traversal<S, T, A>, optic2: Getter<A, A2>): Fold<S, A2>; | ||
export declare function compose<S, T extends HKT, A, A2>(optic1: Traversal<S, T, A>, optic2: AffineFold<A, A2>): Fold<S, A2>; | ||
export declare function compose<S, T extends HKT, A, A2>(optic1: Traversal<S, T, A>, optic2: Fold<A, A2>): Fold<S, A2>; | ||
export declare function compose<S, T extends HKT, A, T2 extends HKT, A2>(optic1: Traversal<S, T, A>, optic2: Setter<A, T2, A2>): Setter<S, Compose<T, T2>, A2>; | ||
export declare function compose<S, A, T2 extends HKT, A2>(optic1: Getter<S, A>, optic2: Equivalence<A, T2, A2>): Getter<S, A2>; | ||
export declare function compose<S, A, T2 extends HKT, A2>(optic1: Getter<S, A>, optic2: Iso<A, T2, A2>): Getter<S, A2>; | ||
export declare function compose<S, A, T2 extends HKT, A2>(optic1: Getter<S, A>, optic2: Lens<A, T2, A2>): Getter<S, A2>; | ||
export declare function compose<S, A, T2 extends HKT, A2>(optic1: Getter<S, A>, optic2: Prism<A, T2, A2>): AffineFold<S, A2>; | ||
export declare function compose<S, A, T2 extends HKT, A2>(optic1: Getter<S, A>, optic2: Traversal<A, T2, A2>): Fold<S, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Equivalence<S, T, A>, optic2: Equivalence<A, T2, A2>): Equivalence<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Equivalence<S, T, A>, optic2: Iso<A, T2, A2>): Iso<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Equivalence<S, T, A>, optic2: Lens<A, T2, A2>): Lens<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Equivalence<S, T, A>, optic2: Prism<A, T2, A2>): Prism<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Equivalence<S, T, A>, optic2: Traversal<A, T2, A2>): Traversal<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, A2>(optic1: Equivalence<S, T, A>, optic2: Getter<A, A2>): Getter<S, A2>; | ||
export declare function compose<S, T extends OpticParams, A, A2>(optic1: Equivalence<S, T, A>, optic2: AffineFold<A, A2>): AffineFold<S, A2>; | ||
export declare function compose<S, T extends OpticParams, A, A2>(optic1: Equivalence<S, T, A>, optic2: Fold<A, A2>): Fold<S, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Equivalence<S, T, A>, optic2: Setter<A, T2, A2>): Setter<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Iso<S, T, A>, optic2: Equivalence<A, T2, A2>): Iso<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Iso<S, T, A>, optic2: Iso<A, T2, A2>): Iso<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Iso<S, T, A>, optic2: Lens<A, T2, A2>): Lens<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Iso<S, T, A>, optic2: Prism<A, T2, A2>): Prism<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Iso<S, T, A>, optic2: Traversal<A, T2, A2>): Traversal<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, A2>(optic1: Iso<S, T, A>, optic2: Getter<A, A2>): Getter<S, A2>; | ||
export declare function compose<S, T extends OpticParams, A, A2>(optic1: Iso<S, T, A>, optic2: AffineFold<A, A2>): AffineFold<S, A2>; | ||
export declare function compose<S, T extends OpticParams, A, A2>(optic1: Iso<S, T, A>, optic2: Fold<A, A2>): Fold<S, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Iso<S, T, A>, optic2: Setter<A, T2, A2>): Setter<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Lens<S, T, A>, optic2: Equivalence<A, T2, A2>): Lens<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Lens<S, T, A>, optic2: Iso<A, T2, A2>): Lens<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Lens<S, T, A>, optic2: Lens<A, T2, A2>): Lens<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Lens<S, T, A>, optic2: Prism<A, T2, A2>): Prism<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Lens<S, T, A>, optic2: Traversal<A, T2, A2>): Traversal<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, A2>(optic1: Lens<S, T, A>, optic2: Getter<A, A2>): Getter<S, A2>; | ||
export declare function compose<S, T extends OpticParams, A, A2>(optic1: Lens<S, T, A>, optic2: AffineFold<A, A2>): AffineFold<S, A2>; | ||
export declare function compose<S, T extends OpticParams, A, A2>(optic1: Lens<S, T, A>, optic2: Fold<A, A2>): Fold<S, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Lens<S, T, A>, optic2: Setter<A, T2, A2>): Setter<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Prism<S, T, A>, optic2: Equivalence<A, T2, A2>): Prism<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Prism<S, T, A>, optic2: Iso<A, T2, A2>): Prism<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Prism<S, T, A>, optic2: Lens<A, T2, A2>): Prism<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Prism<S, T, A>, optic2: Prism<A, T2, A2>): Prism<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Prism<S, T, A>, optic2: Traversal<A, T2, A2>): Traversal<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, A2>(optic1: Prism<S, T, A>, optic2: Getter<A, A2>): AffineFold<S, A2>; | ||
export declare function compose<S, T extends OpticParams, A, A2>(optic1: Prism<S, T, A>, optic2: AffineFold<A, A2>): AffineFold<S, A2>; | ||
export declare function compose<S, T extends OpticParams, A, A2>(optic1: Prism<S, T, A>, optic2: Fold<A, A2>): Fold<S, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Prism<S, T, A>, optic2: Setter<A, T2, A2>): Setter<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Traversal<S, T, A>, optic2: Equivalence<A, T2, A2>): Traversal<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Traversal<S, T, A>, optic2: Iso<A, T2, A2>): Traversal<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Traversal<S, T, A>, optic2: Lens<A, T2, A2>): Traversal<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Traversal<S, T, A>, optic2: Prism<A, T2, A2>): Traversal<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Traversal<S, T, A>, optic2: Traversal<A, T2, A2>): Traversal<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, T extends OpticParams, A, A2>(optic1: Traversal<S, T, A>, optic2: Getter<A, A2>): Fold<S, A2>; | ||
export declare function compose<S, T extends OpticParams, A, A2>(optic1: Traversal<S, T, A>, optic2: AffineFold<A, A2>): Fold<S, A2>; | ||
export declare function compose<S, T extends OpticParams, A, A2>(optic1: Traversal<S, T, A>, optic2: Fold<A, A2>): Fold<S, A2>; | ||
export declare function compose<S, T extends OpticParams, A, T2 extends OpticParams, A2>(optic1: Traversal<S, T, A>, optic2: Setter<A, T2, A2>): Setter<S, NextComposeParams<T, T2>, A2>; | ||
export declare function compose<S, A, T2 extends OpticParams, A2>(optic1: Getter<S, A>, optic2: Equivalence<A, T2, A2>): Getter<S, A2>; | ||
export declare function compose<S, A, T2 extends OpticParams, A2>(optic1: Getter<S, A>, optic2: Iso<A, T2, A2>): Getter<S, A2>; | ||
export declare function compose<S, A, T2 extends OpticParams, A2>(optic1: Getter<S, A>, optic2: Lens<A, T2, A2>): Getter<S, A2>; | ||
export declare function compose<S, A, T2 extends OpticParams, A2>(optic1: Getter<S, A>, optic2: Prism<A, T2, A2>): AffineFold<S, A2>; | ||
export declare function compose<S, A, T2 extends OpticParams, A2>(optic1: Getter<S, A>, optic2: Traversal<A, T2, A2>): Fold<S, A2>; | ||
export declare function compose<S, A, A2>(optic1: Getter<S, A>, optic2: Getter<A, A2>): Getter<S, A2>; | ||
export declare function compose<S, A, A2>(optic1: Getter<S, A>, optic2: AffineFold<A, A2>): AffineFold<S, A2>; | ||
export declare function compose<S, A, A2>(optic1: Getter<S, A>, optic2: Fold<A, A2>): Fold<S, A2>; | ||
export declare function compose<S, A, T2 extends HKT, A2>(optic1: AffineFold<S, A>, optic2: Equivalence<A, T2, A2>): AffineFold<S, A2>; | ||
export declare function compose<S, A, T2 extends HKT, A2>(optic1: AffineFold<S, A>, optic2: Iso<A, T2, A2>): AffineFold<S, A2>; | ||
export declare function compose<S, A, T2 extends HKT, A2>(optic1: AffineFold<S, A>, optic2: Lens<A, T2, A2>): AffineFold<S, A2>; | ||
export declare function compose<S, A, T2 extends HKT, A2>(optic1: AffineFold<S, A>, optic2: Prism<A, T2, A2>): AffineFold<S, A2>; | ||
export declare function compose<S, A, T2 extends HKT, A2>(optic1: AffineFold<S, A>, optic2: Traversal<A, T2, A2>): Fold<S, A2>; | ||
export declare function compose<S, A, T2 extends OpticParams, A2>(optic1: AffineFold<S, A>, optic2: Equivalence<A, T2, A2>): AffineFold<S, A2>; | ||
export declare function compose<S, A, T2 extends OpticParams, A2>(optic1: AffineFold<S, A>, optic2: Iso<A, T2, A2>): AffineFold<S, A2>; | ||
export declare function compose<S, A, T2 extends OpticParams, A2>(optic1: AffineFold<S, A>, optic2: Lens<A, T2, A2>): AffineFold<S, A2>; | ||
export declare function compose<S, A, T2 extends OpticParams, A2>(optic1: AffineFold<S, A>, optic2: Prism<A, T2, A2>): AffineFold<S, A2>; | ||
export declare function compose<S, A, T2 extends OpticParams, A2>(optic1: AffineFold<S, A>, optic2: Traversal<A, T2, A2>): Fold<S, A2>; | ||
export declare function compose<S, A, A2>(optic1: AffineFold<S, A>, optic2: Getter<A, A2>): AffineFold<S, A2>; | ||
export declare function compose<S, A, A2>(optic1: AffineFold<S, A>, optic2: AffineFold<A, A2>): AffineFold<S, A2>; | ||
export declare function compose<S, A, A2>(optic1: AffineFold<S, A>, optic2: Fold<A, A2>): Fold<S, A2>; | ||
export declare function compose<S, A, T2 extends HKT, A2>(optic1: Fold<S, A>, optic2: Equivalence<A, T2, A2>): Fold<S, A2>; | ||
export declare function compose<S, A, T2 extends HKT, A2>(optic1: Fold<S, A>, optic2: Iso<A, T2, A2>): Fold<S, A2>; | ||
export declare function compose<S, A, T2 extends HKT, A2>(optic1: Fold<S, A>, optic2: Lens<A, T2, A2>): Fold<S, A2>; | ||
export declare function compose<S, A, T2 extends HKT, A2>(optic1: Fold<S, A>, optic2: Prism<A, T2, A2>): Fold<S, A2>; | ||
export declare function compose<S, A, T2 extends HKT, A2>(optic1: Fold<S, A>, optic2: Traversal<A, T2, A2>): Fold<S, A2>; | ||
export declare function compose<S, A, T2 extends OpticParams, A2>(optic1: Fold<S, A>, optic2: Equivalence<A, T2, A2>): Fold<S, A2>; | ||
export declare function compose<S, A, T2 extends OpticParams, A2>(optic1: Fold<S, A>, optic2: Iso<A, T2, A2>): Fold<S, A2>; | ||
export declare function compose<S, A, T2 extends OpticParams, A2>(optic1: Fold<S, A>, optic2: Lens<A, T2, A2>): Fold<S, A2>; | ||
export declare function compose<S, A, T2 extends OpticParams, A2>(optic1: Fold<S, A>, optic2: Prism<A, T2, A2>): Fold<S, A2>; | ||
export declare function compose<S, A, T2 extends OpticParams, A2>(optic1: Fold<S, A>, optic2: Traversal<A, T2, A2>): Fold<S, A2>; | ||
export declare function compose<S, A, A2>(optic1: Fold<S, A>, optic2: Getter<A, A2>): Fold<S, A2>; | ||
@@ -382,5 +390,5 @@ export declare function compose<S, A, A2>(optic1: Fold<S, A>, optic2: AffineFold<A, A2>): Fold<S, A2>; | ||
export declare function collect<S, A>(optic: Prism<S, any, A> | Traversal<S, any, A> | Fold<S, A>): (source: S) => A[]; | ||
export declare function modify<S, T extends HKT, A>(optic: Equivalence<S, T, A> | Iso<S, T, A> | Lens<S, T, A> | Prism<S, T, A> | Traversal<S, T, A>): <B>(f: (a: A) => B) => (source: S) => Simplify<S, Apply<T, B>>; | ||
export declare function set<S, T extends HKT, A>(optic: Equivalence<S, T, A> | Iso<S, T, A> | Lens<S, T, A> | Prism<S, T, A> | Traversal<S, T, A> | Setter<S, T, A>): <B>(value: B) => (source: S) => Simplify<S, Apply<T, B>>; | ||
export declare function remove<S>(optic: RemovablePrism<S, any, any> | RemovableTraversal<S, any, any>): (source: S) => S; | ||
export declare function modify<S, T extends OpticParams, A>(optic: Equivalence<S, T, A> | Iso<S, T, A> | Lens<S, T, A> | Prism<S, T, A> | Traversal<S, T, A>): <B>(f: (a: A) => B) => (source: S) => Simplify<S, Apply<T['_T'], B>>; | ||
export declare function set<S, T extends OpticParams, A>(optic: Equivalence<S, T, A> | Iso<S, T, A> | Lens<S, T, A> | Prism<S, T, A> | Traversal<S, T, A> | Setter<S, T, A>): <B>(value: B) => (source: S) => Simplify<S, Apply<T['_T'], B>>; | ||
export declare function remove<S>(optic: Prism<S, Params<any, true>, any> | Traversal<S, Params<any, true>, any>): (source: S) => S; | ||
export declare function pipe<A>(a: A): A; | ||
@@ -387,0 +395,0 @@ export declare function pipe<A, B>(a: A, ab: (a: A) => B): B; |
"use strict"; | ||
// This file is generated, do not edit! See ../scripts/generate-index.ts | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.pipe = exports.remove = exports.set = exports.modify = exports.collect = exports.preview = exports.get = exports.optic_ = exports.optic = exports.compose = void 0; | ||
var I = require("./internals"); | ||
@@ -5,0 +6,0 @@ function compose(optic1, optic2) { |
@@ -36,4 +36,5 @@ export declare const id: (x: any) => any; | ||
guard(fn: Function): Optic; | ||
at(i: number): Optic; | ||
head(): Optic; | ||
index(i: number): Optic; | ||
head(): Optic; | ||
find(predicate: (item: any) => boolean): Optic; | ||
@@ -40,0 +41,0 @@ elems(): Optic; |
@@ -21,2 +21,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.optic = exports.Optic = exports.collect = exports.preview = exports.get = exports.remove = exports.set = exports.modify = exports.compositionType = exports.id = void 0; | ||
exports.id = function (x) { return x; }; | ||
@@ -275,3 +276,3 @@ var Left = function (value) { return ({ | ||
var removeMe = Symbol('__remove_me__'); | ||
var index = function (i) { | ||
var at = function (i) { | ||
return removable(compose(lens(function (source) { return (0 <= i && i < source.length ? source[i] : noMatch); }, function (_a) { | ||
@@ -310,4 +311,9 @@ var value = _a[0], source = _a[1]; | ||
}; | ||
// Like at(0), but the zero'th index must always be defined | ||
var fst = lens(function (value) { return value[0]; }, function (_a) { | ||
var value = _a[0], source = _a[1]; | ||
return [value, source[1]]; | ||
}); | ||
var find = function (predicate) { | ||
return compose(lens(function (source) { | ||
return removable(compose(lens(function (source) { | ||
var index = source.findIndex(predicate); | ||
@@ -320,9 +326,12 @@ if (index === -1) { | ||
var _b = _a[0], value = _b[0], index = _b[1], source = _a[1]; | ||
if (value === noMatch || index === -1) { | ||
if (value === noMatch) { | ||
return source; | ||
} | ||
if (value === removeMe) { | ||
return __spreadArrays(source.slice(0, index), source.slice(index + 1)); | ||
} | ||
var result = source.slice(); | ||
result[index] = value; | ||
return result; | ||
}), index(0)); | ||
}), fst, mustMatch)); | ||
}; | ||
@@ -343,4 +352,4 @@ var filter = function (predicate) { | ||
for (var _i = 0, indexes_1 = indexes; _i < indexes_1.length; _i++) { | ||
var index_1 = indexes_1[_i]; | ||
result[index_1] = values[j]; | ||
var index = indexes_1[_i]; | ||
result[index] = values[j]; | ||
j++; | ||
@@ -380,3 +389,3 @@ } | ||
}, | ||
enumerable: true, | ||
enumerable: false, | ||
configurable: true | ||
@@ -388,3 +397,3 @@ }); | ||
}, | ||
enumerable: true, | ||
enumerable: false, | ||
configurable: true | ||
@@ -423,8 +432,11 @@ }); | ||
}; | ||
Optic.prototype.index = function (i) { | ||
return new Optic(compose(this._ref, index(i))); | ||
Optic.prototype.at = function (i) { | ||
return new Optic(compose(this._ref, at(i))); | ||
}; | ||
Optic.prototype.head = function () { | ||
return new Optic(compose(this._ref, index(0))); | ||
return new Optic(compose(this._ref, at(0))); | ||
}; | ||
Optic.prototype.index = function (i) { | ||
return new Optic(compose(this._ref, at(i))); | ||
}; | ||
Optic.prototype.find = function (predicate) { | ||
@@ -431,0 +443,0 @@ return new Optic(compose(this._ref, find(predicate))); |
{ | ||
"name": "optics-ts", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Type-safe, ergonomic, polymorphic optics for TypeScript", | ||
@@ -32,11 +32,11 @@ "repository": "https://github.com/akheron/optics-ts", | ||
"devDependencies": { | ||
"@babel/types": "^7.9.0", | ||
"@types/jest": "^25.1.4", | ||
"@babel/types": "^7.12.1", | ||
"@types/jest": "^26.0.15", | ||
"doctoc": "^1.4.0", | ||
"jest": "^25.1.0", | ||
"prettier": "^2.0.2", | ||
"ts-jest": "^25.2.1", | ||
"ts-node": "^8.8.1", | ||
"typescript": "^3.8.3" | ||
"jest": "^26.6.1", | ||
"prettier": "^2.1.2", | ||
"ts-jest": "^26.4.3", | ||
"ts-node": "^9.0.0", | ||
"typescript": "^4.0.5" | ||
} | ||
} |
@@ -23,2 +23,3 @@ # optics-ts | ||
- [Installation](#installation) | ||
- [Requirements](#requirements) | ||
- [Tutorial](#tutorial) | ||
@@ -57,4 +58,5 @@ - [Lens](#lens) | ||
- [`guard_<F extends HKT>(): <U extends A>(g: (a: A) => a is U) => Prism<S, T ยท F, U>`](#guard_f-extends-hkt-u-extends-ag-a-a--a-is-u--prisms-t-%C2%B7-f-u) | ||
- [`at(i: number): RemovablePrism<S, _, ElemType<A>>`](#ati-number-removableprisms-_-elemtypea) | ||
- [`head(): Prism<S, _, ElemType<A>>`](#head-prisms-_-elemtypea) | ||
- [`index(i: number): RemovablePrism<S, _, ElemType<A>>`](#indexi-number-removableprisms-_-elemtypea) | ||
- [`head(): Prism<S, _, ElemType<A>>`](#head-prisms-_-elemtypea) | ||
- [`find(p: (e: ElemType<A>) => boolean): Prism<S, _, ElemType<A>>`](#findp-e-elemtypea--boolean-prisms-_-elemtypea) | ||
@@ -90,2 +92,29 @@ - [`when(f: (a: A) => boolean): Prism<S, _, A>`](#whenf-a-a--boolean-prisms-_-a) | ||
## Requirements | ||
`optics-ts` requires the [`strictNullChecks` compiler | ||
option](https://www.typescriptlang.org/tsconfig#strictNullChecks). | ||
I strongly recommend enabling all strict options in your project's | ||
`tsconfig.json`: | ||
``` | ||
{ | ||
"compilerOptions": { | ||
"strict": true | ||
} | ||
} | ||
``` | ||
If this is not possible for your project, enable only the | ||
`strictNullChecks` option: | ||
``` | ||
{ | ||
"compilerOptions": { | ||
"strictNullChecks": true | ||
} | ||
} | ||
``` | ||
## Tutorial | ||
@@ -133,3 +162,3 @@ | ||
O.get(lens)(data) | ||
O.get(bar)(data) | ||
// => 42 | ||
@@ -141,3 +170,3 @@ ``` | ||
```typescript | ||
O.set(lens)(99)(data) | ||
O.set(bar)(99)(data) | ||
// => { | ||
@@ -148,3 +177,3 @@ // foo: { bar: 99 }, | ||
O.modify(lens)(x => x * 100)(data) | ||
O.modify(bar)(x => x * 100)(data) | ||
// => { | ||
@@ -259,3 +288,3 @@ // foo: { bar: 4200 }, | ||
`.index()` is a removable prism. It focuses on an index of an array, and | ||
`.at()` is a removable prism. It focuses on an index of an array, and | ||
lets you also remove that index: | ||
@@ -268,3 +297,3 @@ | ||
const secondUser = O.optic<Users>().index(1) | ||
const secondUser = O.optic<User[]>().at(1) | ||
@@ -500,15 +529,16 @@ const threeUsers: User[] = [ | ||
- `T` is a "higher-kinded type" or a "partially applied type operator" | ||
that yields the output type when applied to some type `B`. | ||
- `T` is a type that encodes how the output type is constructed with | ||
polymorphic writes, as well as info about the optic's removability | ||
Conceptually, when you write a value of type `B`, the output type will | ||
be `S` with `A` replaced by `B` at the focus(es) of the optic. `T` is | ||
the mechanism that transforms `B` to the output type. This construct | ||
makes it possible for the optics to be polymorphic on the type level. | ||
The read-only optics don't need `T` because you cannot write through | ||
them. | ||
be `S` with `A` replaced by `B` at the focus(es) of the optic. `T` | ||
contains a mechanism that transforms `B` to the output type. This | ||
construct makes it possible for the optics to be polymorphic on the type | ||
level. The read-only optics don't need `T` because you cannot write | ||
through them or remove their focus. | ||
In the following, we leave the exact definition of `T` for each optic | ||
out for clarity, writing just `_` in its place. It's usually clear from | ||
how the optic works what will come out if you put a different type in. | ||
how the optic works what will come out if you write a value of a | ||
different type. | ||
@@ -519,3 +549,3 @@ In the documentation of functions that can be used to write through an | ||
this captures the meaning quite well: `B` is applied to the | ||
higher-kinded type `T`, yielding the output type. | ||
"higher-kinded" type `T`, yielding the output type. | ||
@@ -628,3 +658,3 @@ Interested readers can refer to [hkt.ts](src/hkt.ts) to see how the | ||
TypeScript's type system also allows array's numeric indices when using | ||
`keyof`. Use the `index()` prism to focus on an array element at a given | ||
`keyof`. Use the `.at()` prism to focus on an array element at a given | ||
index. | ||
@@ -713,3 +743,3 @@ | ||
#### `index(i: number): RemovablePrism<S, _, ElemType<A>>` | ||
#### `at(i: number): RemovablePrism<S, _, ElemType<A>>` | ||
@@ -729,11 +759,15 @@ Only works on arrays and strings. Removable. | ||
Short for `index(0)`. | ||
Short for `at(0)`. | ||
#### `index(i: number): RemovablePrism<S, _, ElemType<A>>` | ||
**Deprecated**. Alias for `.at()`. | ||
#### `find(p: (e: ElemType<A>) => boolean): Prism<S, _, ElemType<A>>` | ||
Only works on array types. `ElemType<A>` is the element type of the | ||
array type `A`. | ||
Only works on array types. Removable. `ElemType<A>` is the element type | ||
of the array type `A`. | ||
Like `.index()`, but the index to be focused on is determined by | ||
finding the first element that matches the given predicate. | ||
Like `.at()`, but the index to be focused on is determined by finding | ||
the first element that matches the given predicate. | ||
@@ -740,0 +774,0 @@ When a different type `B` is written through this optic, the resulting |
109565
1571
858