monocle-ts
- Version 2.3.13
- Published
- 368 kB
- No dependencies
- MIT license
Install
npm i monocle-tsyarn add monocle-tspnpm add monocle-tsOverview
A porting of scala monocle library to TypeScript
Index
Functions
Classes
Interfaces
Type Aliases
Namespaces
iso
- asLens()
- asOptional()
- asPrism()
- asTraversal()
- atKey()
- Category
- component()
- compose()
- composeIso()
- composeLens()
- composeOptional()
- composePrism()
- composeTraversal()
- filter()
- findFirst()
- findFirstNonEmpty()
- fromNullable()
- id()
- imap()
- index()
- indexNonEmpty()
- Invariant
- iso()
- Iso
- key()
- left()
- modify()
- modifyF()
- prop()
- props()
- reverse()
- right()
- Semigroupoid
- some()
- traverse()
- URI
- URI
lens
- asOptional()
- asTraversal()
- atKey()
- Category
- component()
- compose()
- composeIso()
- composeLens()
- composeOptional()
- composePrism()
- composeTraversal()
- filter()
- findFirst()
- findFirstNonEmpty()
- fromNullable()
- id()
- imap()
- index()
- indexNonEmpty()
- Invariant
- key()
- left()
- lens()
- Lens
- modify()
- modifyF()
- prop()
- props()
- right()
- Semigroupoid
- some()
- traverse()
- URI
- URI
optional
- asTraversal()
- atKey()
- Category
- component()
- compose()
- composeIso()
- composeLens()
- composeOptional()
- composePrism()
- composeTraversal()
- filter()
- findFirst()
- findFirstNonEmpty()
- fromNullable()
- id()
- imap()
- index()
- indexNonEmpty()
- Invariant
- key()
- left()
- modify()
- modifyF()
- modifyOption()
- optional()
- Optional
- prop()
- props()
- right()
- Semigroupoid
- setOption()
- some()
- traverse()
- URI
- URI
prism
- asOptional()
- asTraversal()
- atKey()
- Category
- component()
- compose()
- composeIso()
- composeLens()
- composeOptional()
- composePrism()
- composeTraversal()
- filter()
- findFirst()
- findFirstNonEmpty()
- fromNullable()
- fromPredicate
- id()
- imap()
- index()
- indexNonEmpty()
- Invariant
- key()
- left()
- modify()
- modifyF()
- modifyOption()
- prism()
- Prism
- prop()
- props()
- right()
- Semigroupoid
- set()
- some()
- traverse()
- URI
- URI
traversal
- atKey()
- Category
- component()
- compose()
- composeIso()
- composeLens()
- composeOptional()
- composePrism()
- composeTraversal()
- filter()
- findFirst()
- findFirstNonEmpty()
- fold()
- foldMap()
- fromNullable()
- fromTraversable
- getAll()
- id()
- index()
- indexNonEmpty()
- key()
- left()
- modify()
- ModifyF
- prop()
- props()
- right()
- Semigroupoid
- set()
- some()
- traversal()
- Traversal
- traverse()
- URI
- URI
Functions
function fromFoldable
fromFoldable: { <F extends URIS3>(F: Foldable3<F>): <U, L, A>() => Fold<Kind3<F, U, L, A>, A>; <F extends URIS2>(F: Foldable2<F>): <L, A>() => Fold<Kind2<F, L, A>, A>; <F extends URIS>(F: Foldable1<F>): <A>() => Fold<Kind<F, A>, A>; <F>(F: Foldable<F>): <A>() => Fold<HKT<F, A>, A>;};Create a
Foldfrom aFoldableconstructor 1.0.0
function fromTraversable
fromTraversable: { <T extends URIS3>(T: Traversable3<T>): <U, L, A>() => Traversal< Kind3<T, U, L, A>, A >; <T extends URIS2>(T: Traversable2<T>): <L, A>() => Traversal<Kind2<T, L, A>, A>; <T extends URIS>(T: Traversable1<T>): <A>() => Traversal<Kind<T, A>, A>; <T>(T: Traversable<T>): <A>() => Traversal<HKT<T, A>, A>;};Create a
Traversalfrom aTraversableExample 1
import { Lens, fromTraversable } from 'monocle-ts' import { Traversable } from 'fp-ts/Array'
interface Tweet { text: string }
interface Tweets { tweets: Tweet[] }
const tweetsLens = Lens.fromProp()('tweets') const tweetTextLens = Lens.fromProp()('text') const tweetTraversal = fromTraversable(Traversable)() const composedTraversal = tweetsLens.composeTraversal(tweetTraversal).composeLens(tweetTextLens)
const tweet1: Tweet = { text: 'hello world' } const tweet2: Tweet = { text: 'foobar' } const model: Tweets = { tweets: [tweet1, tweet2] }
const actual = composedTraversal.modify(text => text .split('') .reverse() .join('') )(model)
assert.deepStrictEqual(actual, { tweets: [ { text: 'dlrow olleh' }, { text: 'raboof' } ] })
constructor 1.0.0
Classes
class At
class At<S, I, A> {}constructor 1.2.0
constructor
constructor(at: (i: I) => Lens<S, A>);property at
readonly at: (i: I) => Lens<S, A>;method fromIso
fromIso: <T>(iso: Iso<T, S>) => At<T, I, A>;lift an instance of
Atusing anIso1.2.0
class Fold
class Fold<S, A> {}constructor 1.0.0
constructor
constructor(foldMap: <M>(M: Monoid<M>) => (f: (a: A) => M) => (s: S) => M);property all
readonly all: (p: Predicate<A>) => Predicate<S>;check if all targets satisfy the predicate
1.0.0
property exist
readonly exist: (p: Predicate<A>) => Predicate<S>;check if at least one target satisfies the predicate
1.0.0
property foldMap
readonly foldMap: <M>(M: Monoid<M>) => (f: (a: A) => M) => (s: S) => M;property getAll
readonly getAll: (s: S) => Array<A>;get all the targets of a
Fold1.0.0
method compose
compose: <B>(ab: Fold<A, B>) => Fold<S, B>;compose a
Foldwith aFold1.0.0
method composeFold
composeFold: <B>(ab: Fold<A, B>) => Fold<S, B>;Alias of
compose1.0.0
method composeGetter
composeGetter: <B>(ab: Getter<A, B>) => Fold<S, B>;compose a
Foldwith aGetter1.0.0
method composeIso
composeIso: <B>(ab: Iso<A, B>) => Fold<S, B>;compose a
Foldwith aIso1.0.0
method composeLens
composeLens: <B>(ab: Lens<A, B>) => Fold<S, B>;compose a
Foldwith aLens1.0.0
method composeOptional
composeOptional: <B>(ab: Optional<A, B>) => Fold<S, B>;compose a
Foldwith aOptional1.0.0
method composePrism
composePrism: <B>(ab: Prism<A, B>) => Fold<S, B>;compose a
Foldwith aPrism1.0.0
method composeTraversal
composeTraversal: <B>(ab: Traversal<A, B>) => Fold<S, B>;compose a
Foldwith aTraversal1.0.0
method find
find: { <B extends A>(p: Refinement<A, B>): (s: S) => Option<B>; (p: Predicate<A>): (s: S) => Option<A>;};find the first target of a
Foldmatching the predicate1.0.0
method headOption
headOption: (s: S) => Option<A>;get the first target of a
Fold1.0.0
class Getter
class Getter<S, A> {}constructor 1.0.0
constructor
constructor(get: (s: S) => A);property get
readonly get: (s: S) => A;method asFold
asFold: () => Fold<S, A>;view a
Getteras aFold1.0.0
method compose
compose: <B>(ab: Getter<A, B>) => Getter<S, B>;compose a
Getterwith aGetter1.0.0
method composeFold
composeFold: <B>(ab: Fold<A, B>) => Fold<S, B>;compose a
Getterwith aFold1.0.0
method composeGetter
composeGetter: <B>(ab: Getter<A, B>) => Getter<S, B>;Alias of
compose1.0.0
method composeIso
composeIso: <B>(ab: Iso<A, B>) => Getter<S, B>;compose a
Getterwith aIso1.0.0
method composeLens
composeLens: <B>(ab: Lens<A, B>) => Getter<S, B>;compose a
Getterwith aLens1.0.0
method composeOptional
composeOptional: <B>(ab: Optional<A, B>) => Fold<S, B>;compose a
Getterwith aOptional1.0.0
method composePrism
composePrism: <B>(ab: Prism<A, B>) => Fold<S, B>;compose a
Getterwith aPrism1.0.0
method composeTraversal
composeTraversal: <B>(ab: Traversal<A, B>) => Fold<S, B>;compose a
Getterwith aOptional1.0.0
class Index
class Index<S, I, A> {}constructor 1.2.0
constructor
constructor(index: (i: I) => Optional<S, A>);property index
readonly index: (i: I) => Optional<S, A>;method fromAt
static fromAt: <T, J, B>(at: At<T, J, Option<B>>) => Index<T, J, B>;1.2.0
method fromIso
fromIso: <T>(iso: Iso<T, S>) => Index<T, I, A>;lift an instance of
Indexusing anIso1.2.0
class Iso
class Iso<S, A> {}Laws: 1.
reverseGet(get(s)) = s2.get(reversetGet(a)) = aconstructor 1.0.0
constructor
constructor(get: (s: S) => A, reverseGet: (a: A) => S);property from
readonly from: (a: A) => S;1.0.0
property get
readonly get: (s: S) => A;property reverseGet
readonly reverseGet: (a: A) => S;property to
readonly to: (s: S) => A;1.0.0
property unwrap
readonly unwrap: (s: S) => A;1.0.0
property wrap
readonly wrap: (a: A) => S;1.0.0
method asFold
asFold: () => Fold<S, A>;view an
Isoas aFold1.0.0
method asGetter
asGetter: () => Getter<S, A>;view an
Isoas aGetter1.0.0
method asLens
asLens: () => Lens<S, A>;view an
Isoas aLens1.0.0
method asOptional
asOptional: () => Optional<S, A>;view an
Isoas aOptional1.0.0
method asPrism
asPrism: () => Prism<S, A>;view an
Isoas aPrism1.0.0
method asSetter
asSetter: () => Setter<S, A>;view an
Isoas aSetter1.0.0
method asTraversal
asTraversal: () => Traversal<S, A>;view an
Isoas aTraversal1.0.0
method compose
compose: <B>(ab: Iso<A, B>) => Iso<S, B>;compose an
Isowith anIso1.0.0
method composeFold
composeFold: <B>(ab: Fold<A, B>) => Fold<S, B>;compose an
Isowith aFold1.0.0
method composeGetter
composeGetter: <B>(ab: Getter<A, B>) => Getter<S, B>;compose an
Isowith aGetter1.0.0
method composeIso
composeIso: <B>(ab: Iso<A, B>) => Iso<S, B>;Alias of
compose1.0.0
method composeLens
composeLens: <B>(ab: Lens<A, B>) => Lens<S, B>;compose an
Isowith aLens1.0.0
method composeOptional
composeOptional: <B>(ab: Optional<A, B>) => Optional<S, B>;compose an
Isowith anOptional1.0.0
method composePrism
composePrism: <B>(ab: Prism<A, B>) => Prism<S, B>;compose an
Isowith aPrism1.0.0
method composeSetter
composeSetter: <B>(ab: Setter<A, B>) => Setter<S, B>;compose an
Isowith aSetter1.0.0
method composeTraversal
composeTraversal: <B>(ab: Traversal<A, B>) => Traversal<S, B>;compose an
Isowith aTraversal1.0.0
method modify
modify: (f: (a: A) => A) => (s: S) => S;1.0.0
method reverse
reverse: () => Iso<A, S>;reverse the
Iso: the source becomes the target and the target becomes the source 1.0.0
class Lens
class Lens<S, A> {}Laws: 1.
get(set(a)(s)) = a2.set(get(s))(s) = s3.set(a)(set(a)(s)) = set(a)(s)constructor 1.0.0
constructor
constructor(get: (s: S) => A, set: (a: A) => (s: S) => S);property get
readonly get: (s: S) => A;property set
readonly set: (a: A) => (s: S) => S;method asFold
asFold: () => Fold<S, A>;view a
Lensas aFold1.0.0
method asGetter
asGetter: () => Getter<S, A>;view a
Lensas aGetter1.0.0
method asOptional
asOptional: () => Optional<S, A>;view a
Lensas a Optional1.0.0
method asSetter
asSetter: () => Setter<S, A>;view a
Lensas aSetter1.0.0
method asTraversal
asTraversal: () => Traversal<S, A>;view a
Lensas aTraversal1.0.0
method compose
compose: <B>(ab: Lens<A, B>) => Lens<S, B>;compose a
Lenswith aLens1.0.0
method composeFold
composeFold: <B>(ab: Fold<A, B>) => Fold<S, B>;compose a
Lenswith aFold1.0.0
method composeGetter
composeGetter: <B>(ab: Getter<A, B>) => Getter<S, B>;compose a
Lenswith aGetter1.0.0
method composeIso
composeIso: <B>(ab: Iso<A, B>) => Lens<S, B>;compose a
Lenswith anIso1.0.0
method composeLens
composeLens: <B>(ab: Lens<A, B>) => Lens<S, B>;Alias of
compose1.0.0
method composeOptional
composeOptional: <B>(ab: Optional<A, B>) => Optional<S, B>;compose a
Lenswith anOptional1.0.0
method composePrism
composePrism: <B>(ab: Prism<A, B>) => Optional<S, B>;compose a
Lenswith aPrism1.0.0
method composeSetter
composeSetter: <B>(ab: Setter<A, B>) => Setter<S, B>;compose a
Lenswith anSetter1.0.0
method composeTraversal
composeTraversal: <B>(ab: Traversal<A, B>) => Traversal<S, B>;compose a
Lenswith anTraversal1.0.0
method fromNullableProp
static fromNullableProp: <S>() => <A extends S[K], K extends keyof S>( k: K, defaultValue: A) => Lens<S, NonNullable<S[K]>>;Returns a
Lensfrom a nullable (A | null | undefined) propExample 1
import { Lens } from 'monocle-ts'
interface Outer { inner?: Inner }
interface Inner { value: number foo: string }
const inner = Lens.fromNullableProp()('inner', { value: 0, foo: 'foo' }) const value = Lens.fromProp()('value') const lens = inner.compose(value)
assert.deepStrictEqual(lens.set(1)({}), { inner: { value: 1, foo: 'foo' } }) assert.strictEqual(lens.get({}), 0) assert.deepStrictEqual(lens.set(1)({ inner: { value: 1, foo: 'bar' } }), { inner: { value: 1, foo: 'bar' } }) assert.strictEqual(lens.get({ inner: { value: 1, foo: 'bar' } }), 1)
1.0.0
method fromPath
static fromPath: <S>() => LensFromPath<S>;Example 1
import { Lens } from 'monocle-ts'
type Person = { name: string age: number address: { city: string } }
const city = Lens.fromPath()(['address', 'city'])
const person: Person = { name: 'Giulio', age: 43, address: { city: 'Milan' } }
assert.strictEqual(city.get(person), 'Milan') assert.deepStrictEqual(city.set('London')(person), { name: 'Giulio', age: 43, address: { city: 'London' } })
1.0.0
method fromProp
static fromProp: <S>() => <P extends keyof S>(prop: P) => Lens<S, S[P]>;Returns a
Lensfrom a type and a propExample 1
import { Lens } from 'monocle-ts'
type Person = { name: string age: number }
const age = Lens.fromProp()('age')
const person: Person = { name: 'Giulio', age: 43 }
assert.strictEqual(age.get(person), 43) assert.deepStrictEqual(age.set(44)(person), { name: 'Giulio', age: 44 })
1.0.0
method fromProps
static fromProps: <S>() => <P extends keyof S>( props: P[]) => Lens<S, { [K in P]: S[K] }>;Returns a
Lensfrom a type and an array of propsExample 1
import { Lens } from 'monocle-ts'
interface Person { name: string age: number rememberMe: boolean }
const lens = Lens.fromProps()(['name', 'age'])
const person: Person = { name: 'Giulio', age: 44, rememberMe: true }
assert.deepStrictEqual(lens.get(person), { name: 'Giulio', age: 44 }) assert.deepStrictEqual(lens.set({ name: 'Guido', age: 47 })(person), { name: 'Guido', age: 47, rememberMe: true })
1.0.0
method modify
modify: (f: (a: A) => A) => (s: S) => S;1.0.0
class Optional
class Optional<S, A> {}Laws: 1.
pipe(getOption(s), fold(() => s, a => set(a)(s))) = s2.getOption(set(a)(s)) = pipe(getOption(s), map(_ => a))3.set(a)(set(a)(s)) = set(a)(s)constructor 1.0.0
constructor
constructor(getOption: (s: S) => Option<A>, set: (a: A) => (s: S) => S);property getOption
readonly getOption: (s: S) => Option<A>;property set
readonly set: (a: A) => (s: S) => S;method asFold
asFold: () => Fold<S, A>;view an
Optionalas aFold1.0.0
method asSetter
asSetter: () => Setter<S, A>;view an
Optionalas aSetter1.0.0
method asTraversal
asTraversal: () => Traversal<S, A>;view a
Optionalas aTraversal1.0.0
method compose
compose: <B>(ab: Optional<A, B>) => Optional<S, B>;compose a
Optionalwith aOptional1.0.0
method composeFold
composeFold: <B>(ab: Fold<A, B>) => Fold<S, B>;compose an
Optionalwith aFold1.0.0
method composeGetter
composeGetter: <B>(ab: Getter<A, B>) => Fold<S, B>;compose an
Optionalwith aGetter1.0.0
method composeIso
composeIso: <B>(ab: Iso<A, B>) => Optional<S, B>;compose an
Optionalwith aIso1.0.0
method composeLens
composeLens: <B>(ab: Lens<A, B>) => Optional<S, B>;compose an
Optionalwith aLens1.0.0
method composeOptional
composeOptional: <B>(ab: Optional<A, B>) => Optional<S, B>;Alias of
compose1.0.0
method composePrism
composePrism: <B>(ab: Prism<A, B>) => Optional<S, B>;compose an
Optionalwith aPrism1.0.0
method composeSetter
composeSetter: <B>(ab: Setter<A, B>) => Setter<S, B>;compose an
Optionalwith aSetter1.0.0
method composeTraversal
composeTraversal: <B>(ab: Traversal<A, B>) => Traversal<S, B>;compose an
Optionalwith aTraversal1.0.0
method fromNullableProp
static fromNullableProp: <S>() => <K extends keyof S>( k: K) => Optional<S, NonNullable<S[K]>>;Example 1
import { Optional } from 'monocle-ts'
interface S { a: number | undefined | null }
const optional = Optional.fromNullableProp()('a')
const s1: S = { a: undefined } const s2: S = { a: null } const s3: S = { a: 1 }
assert.deepStrictEqual(optional.set(2)(s1), s1) assert.deepStrictEqual(optional.set(2)(s2), s2) assert.deepStrictEqual(optional.set(2)(s3), { a: 2 })
1.0.0
method fromOptionProp
static fromOptionProp: <S>() => <P extends OptionPropertyNames<S>>( prop: P) => Optional<S, OptionPropertyType<S, P>>;Returns an
Optionalfrom an option (Option<A>) propExample 1
import { Optional } from 'monocle-ts' import * as O from 'fp-ts/Option'
interface S { a: O.Option }
const optional = Optional.fromOptionProp()('a') const s1: S = { a: O.none } const s2: S = { a: O.some(1) } assert.deepStrictEqual(optional.set(2)(s1), s1) assert.deepStrictEqual(optional.set(2)(s2), { a: O.some(2) })
1.0.0
method fromPath
static fromPath: <S>() => OptionalFromPath<S>;Returns an
Optionalfrom a nullable (A | null | undefined) propExample 1
import { Optional } from 'monocle-ts'
interface Phone { number: string } interface Employment { phone?: Phone } interface Info { employment?: Employment } interface Response { info?: Info }
const numberFromResponse = Optional.fromPath()(['info', 'employment', 'phone', 'number'])
const response1: Response = { info: { employment: { phone: { number: '555-1234' } } } } const response2: Response = { info: { employment: {} } }
numberFromResponse.getOption(response1) // some('555-1234') numberFromResponse.getOption(response2) // none
2.1.0
method modify
modify: (f: (a: A) => A) => (s: S) => S;1.0.0
method modifyOption
modifyOption: (f: (a: A) => A) => (s: S) => Option<S>;1.0.0
class Prism
class Prism<S, A> {}Laws: 1.
pipe(getOption(s), fold(() => s, reverseGet)) = s2.getOption(reverseGet(a)) = some(a)constructor 1.0.0
constructor
constructor(getOption: (s: S) => Option<A>, reverseGet: (a: A) => S);property getOption
readonly getOption: (s: S) => Option<A>;property reverseGet
readonly reverseGet: (a: A) => S;method asFold
asFold: () => Fold<S, A>;view a
Prismas aFold1.0.0
method asOptional
asOptional: () => Optional<S, A>;view a
Prismas aOptional1.0.0
method asSetter
asSetter: () => Setter<S, A>;view a
Prismas aSetter1.0.0
method asTraversal
asTraversal: () => Traversal<S, A>;view a
Prismas aTraversal1.0.0
method compose
compose: <B>(ab: Prism<A, B>) => Prism<S, B>;compose a
Prismwith aPrism1.0.0
method composeFold
composeFold: <B>(ab: Fold<A, B>) => Fold<S, B>;compose a
Prismwith aFold1.0.0
method composeGetter
composeGetter: <B>(ab: Getter<A, B>) => Fold<S, B>;compose a
Prismwith aGetter1.0.0
method composeIso
composeIso: <B>(ab: Iso<A, B>) => Prism<S, B>;compose a
Prismwith aIso1.0.0
method composeLens
composeLens: <B>(ab: Lens<A, B>) => Optional<S, B>;compose a
Prismwith aLens1.0.0
method composeOptional
composeOptional: <B>(ab: Optional<A, B>) => Optional<S, B>;compose a
Prismwith aOptional1.0.0
method composePrism
composePrism: <B>(ab: Prism<A, B>) => Prism<S, B>;Alias of
compose1.0.0
method composeSetter
composeSetter: <B>(ab: Setter<A, B>) => Setter<S, B>;compose a
Prismwith aSetter1.0.0
method composeTraversal
composeTraversal: <B>(ab: Traversal<A, B>) => Traversal<S, B>;compose a
Prismwith aTraversal1.0.0
method fromPredicate
static fromPredicate: { <S, A extends S>(refinement: Refinement<S, A>): Prism<S, A>; <A>(predicate: Predicate<A>): Prism<A, A>;};1.0.0
method modify
modify: (f: (a: A) => A) => (s: S) => S;1.0.0
method modifyOption
modifyOption: (f: (a: A) => A) => (s: S) => Option<S>;1.0.0
method set
set: (a: A) => (s: S) => S;set the target of a
Prismwith a value1.0.0
method some
static some: <A>() => Prism<Option<A>, A>;1.0.0
class Setter
class Setter<S, A> {}constructor 1.0.0
constructor
constructor(modify: (f: (a: A) => A) => (s: S) => S);property modify
readonly modify: (f: (a: A) => A) => (s: S) => S;method compose
compose: <B>(ab: Setter<A, B>) => Setter<S, B>;compose a
Setterwith aSetter1.0.0
method composeIso
composeIso: <B>(ab: Iso<A, B>) => Setter<S, B>;compose a
Setterwith aIso1.0.0
method composeLens
composeLens: <B>(ab: Lens<A, B>) => Setter<S, B>;compose a
Setterwith aLens1.0.0
method composeOptional
composeOptional: <B>(ab: Optional<A, B>) => Setter<S, B>;compose a
Setterwith aOptional1.0.0
method composePrism
composePrism: <B>(ab: Prism<A, B>) => Setter<S, B>;compose a
Setterwith aPrism1.0.0
method composeSetter
composeSetter: <B>(ab: Setter<A, B>) => Setter<S, B>;Alias of
compose1.0.0
method composeTraversal
composeTraversal: <B>(ab: Traversal<A, B>) => Setter<S, B>;compose a
Setterwith aTraversal1.0.0
method set
set: (a: A) => (s: S) => S;1.0.0
class Traversal
class Traversal<S, A> {}constructor 1.0.0
constructor
constructor(modifyF: ModifyF<S, A>);property modifyF
readonly modifyF: ModifyF<S, A>;method asFold
asFold: () => Fold<S, A>;view a
Traversalas aFold1.0.0
method asSetter
asSetter: () => Setter<S, A>;view a
Traversalas aSetter1.0.0
method compose
compose: <B>(ab: Traversal<A, B>) => Traversal<S, B>;compose a
Traversalwith aTraversal1.0.0
method composeFold
composeFold: <B>(ab: Fold<A, B>) => Fold<S, B>;compose a
Traversalwith aFold1.0.0
method composeGetter
composeGetter: <B>(ab: Getter<A, B>) => Fold<S, B>;compose a
Traversalwith aGetter1.0.0
method composeIso
composeIso: <B>(ab: Iso<A, B>) => Traversal<S, B>;compose a
Traversalwith aIso1.0.0
method composeLens
composeLens: <B>(ab: Lens<A, B>) => Traversal<S, B>;compose a
Traversalwith aLens1.0.0
method composeOptional
composeOptional: <B>(ab: Optional<A, B>) => Traversal<S, B>;compose a
Traversalwith aOptional1.0.0
method composePrism
composePrism: <B>(ab: Prism<A, B>) => Traversal<S, B>;compose a
Traversalwith aPrism1.0.0
method composeSetter
composeSetter: <B>(ab: Setter<A, B>) => Setter<S, B>;compose a
Traversalwith aSetter1.0.0
method composeTraversal
composeTraversal: <B>(ab: Traversal<A, B>) => Traversal<S, B>;Alias of
compose1.0.0
method filter
filter: { <B extends A>(refinement: Refinement<A, B>): Traversal<S, B>; (predicate: Predicate<A>): Traversal<S, A>;};focus the items matched by a
traversalto those that match a predicateExample 1
import { fromTraversable, Lens } from 'monocle-ts' import { Traversable } from 'fp-ts/Array'
interface Person { name: string; cool: boolean; }
const peopleTraversal = fromTraversable(Traversable)() const coolLens = Lens.fromProp()('cool') const people = [{name: 'bill', cool: false}, {name: 'jill', cool: true}]
const actual = peopleTraversal.filter(p => p.name === 'bill').composeLens(coolLens) .set(true)(people)
assert.deepStrictEqual(actual, [{name: 'bill', cool: true}, {name: 'jill', cool: true}])
1.0.0
method modify
modify: (f: (a: A) => A) => (s: S) => S;1.0.0
method set
set: (a: A) => (s: S) => S;1.0.0
Interfaces
interface LensFromPath
interface LensFromPath<S> {}1.3.0
call signature
< 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]>;call signature
< 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]>;call signature
<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]>;call signature
<K1 extends keyof S, K2 extends keyof S[K1]>(path: [K1, K2]): Lens<S, S[K1][K2]>;call signature
<K1 extends keyof S>(path: [K1]): Lens<S, S[K1]>;interface OptionalFromPath
interface OptionalFromPath<S> {}2.1.0
call signature
< 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<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] >>;call signature
< 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]>>;call signature
< 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]>>;call signature
<K1 extends keyof S, K2 extends keyof NonNullable<S[K1]>>( path: [K1, K2]): Optional<S, NonNullable<NonNullable<S[K1]>[K2]>>;call signature
<K1 extends keyof S>(path: [K1]): Optional<S, NonNullable<S[K1]>>;Type Aliases
type ModifyF
type ModifyF<S, A> = traversal.ModifyF<S, A>;1.0.0
Namespaces
namespace at
module 'lib/At.d.ts' {}**This module is experimental**
Experimental features are published in order to get early feedback from the community.
A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
2.3.0
function at
at: <S, I, A>(at: (i: I) => Lens<S, A>) => At<S, I, A>;constructors 2.3.8
function atReadonlyMap
atReadonlyMap: <K>( E: Eq<K>) => <A = never>() => At<ReadonlyMap<K, A>, K, O.Option<A>>;constructors 2.3.7
function atReadonlyRecord
atReadonlyRecord: <A = never>() => At< ReadonlyRecord<string, A>, string, Option<A>>;constructors 2.3.7
function atReadonlySet
atReadonlySet: <A>(E: Eq<A>) => At<ReadonlySet<A>, A, boolean>;constructors 2.3.7
function atRecord
atRecord: <A = never>() => At<ReadonlyRecord<string, A>, string, Option<A>>;Use
atReadonlyRecordinstead.constructors 2.3.2
Deprecated
function fromIso
fromIso: <T, S>(iso: Iso<T, S>) => <I, A>(sia: At<S, I, A>) => At<T, I, A>;Lift an instance of
Atusing anIso.constructors 2.3.0
namespace index
module 'lib/Ix.d.ts' {}**This module is experimental**
Experimental features are published in order to get early feedback from the community.
A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
2.3.0
function fromAt
fromAt: <T, J, B>(at: At<T, J, O.Option<B>>) => Index<T, J, B>;constructors 2.3.0
function fromIso
fromIso: <T, S>(iso: Iso<T, S>) => <I, A>(sia: Index<S, I, A>) => Index<T, I, A>;Lift an instance of
Indexusing anIso.constructors 2.3.0
function index
index: <S, I, A>(index: (i: I) => Optional<S, A>) => Index<S, I, A>;constructors 2.3.8
function indexArray
indexArray: <A = never>() => Index<readonly A[], number, A>;Use
indexReadonlyArrayinstead.constructors 2.3.2
Deprecated
function indexReadonlyArray
indexReadonlyArray: <A = never>() => Index<readonly A[], number, A>;constructors 2.3.7
function indexReadonlyMap
indexReadonlyMap: <K>( E: Eq<K>) => <A = never>() => Index<ReadonlyMap<K, A>, K, A>;constructors 2.3.7
function indexReadonlyNonEmptyArray
indexReadonlyNonEmptyArray: <A = never>() => Index< ReadonlyNonEmptyArray<A>, number, A>;constructors 2.3.8
function indexReadonlyRecord
indexReadonlyRecord: <A = never>() => Index< ReadonlyRecord<string, A>, string, A>;constructors 2.3.7
function indexRecord
indexRecord: <A = never>() => Index<ReadonlyRecord<string, A>, string, A>;Use
indexReadonlyRecordinstead.constructors 2.3.2
Deprecated
namespace iso
module 'lib/Iso.d.ts' {}**This module is experimental**
Experimental features are published in order to get early feedback from the community.
A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
An
Isois an optic which converts elements of typeSinto elements of typeAwithout loss.Laws:
1.
reverseGet(get(s)) = s2.get(reversetGet(a)) = a2.3.0
variable Category
const Category: Category2<'monocle-ts/Iso'>;instances 2.3.0
variable Invariant
const Invariant: Invariant2<'monocle-ts/Iso'>;instances 2.3.0
variable Semigroupoid
const Semigroupoid: Semigroupoid2<'monocle-ts/Iso'>;instances 2.3.8
variable URI
const URI: string;instances 2.3.0
function asLens
asLens: <S, A>(sa: Iso<S, A>) => Lens<S, A>;View an
Isoas aLens.converters 2.3.0
function asOptional
asOptional: <S, A>(sa: Iso<S, A>) => Optional<S, A>;View an
Isoas aOptional.converters 2.3.0
function asPrism
asPrism: <S, A>(sa: Iso<S, A>) => Prism<S, A>;View an
Isoas aPrism.converters 2.3.0
function asTraversal
asTraversal: <S, A>(sa: Iso<S, A>) => Traversal<S, A>;View an
Isoas aTraversal.converters 2.3.0
function atKey
atKey: ( key: string) => <S, A>(sa: Iso<S, Readonly<Record<string, A>>>) => Lens<S, Option<A>>;Return a
Lensfrom aIsofocused on a required key of aReadonlyRecord.combinators 2.3.8
function component
component: <A extends readonly unknown[], P extends keyof A>( prop: P) => <S>(sa: Iso<S, A>) => Lens<S, A[P]>;Return a
Lensfrom aIsofocused on a component of a tuple.combinators 2.3.8
function compose
compose: <A, B>(ab: Iso<A, B>) => <S>(sa: Iso<S, A>) => Iso<S, B>;Compose an
Isowith anIso.compositions 2.3.0
function composeIso
composeIso: <A, B>(ab: Iso<A, B>) => <S>(sa: Iso<S, A>) => Iso<S, B>;Alias of
compose.compositions 2.3.8
function composeLens
composeLens: <A, B>(ab: Lens<A, B>) => <S>(sa: Iso<S, A>) => Lens<S, B>;Compose an
Isowith aLens.compositions 2.3.8
function composeOptional
composeOptional: <A, B>( ab: Optional<A, B>) => <S>(sa: Iso<S, A>) => Optional<S, B>;Compose an
Isowith aOptional.compositions 2.3.8
function composePrism
composePrism: <A, B>(ab: Prism<A, B>) => <S>(sa: Iso<S, A>) => Prism<S, B>;Compose an
Isowith aPrism.compositions 2.3.8
function composeTraversal
composeTraversal: <A, B>( ab: Traversal<A, B>) => <S>(sa: Iso<S, A>) => Traversal<S, B>;Compose an
Isowith aTraversal.compositions 2.3.8
function filter
filter: { <A, B extends A>(refinement: Refinement<A, B>): <S>( sa: Iso<S, A> ) => Prism<S, B>; <A>(predicate: Predicate<A>): <S>(sa: Iso<S, A>) => Prism<S, A>;};combinators 2.3.8
function findFirst
findFirst: { <A, B extends A>(refinement: Refinement<A, B>): <S>( sa: Iso<S, readonly A[]> ) => Optional<S, B>; <A>(predicate: Predicate<A>): <S>(sa: Iso<S, readonly A[]>) => Optional<S, A>;};combinators 2.3.8
function findFirstNonEmpty
findFirstNonEmpty: { <A, B extends A>(refinement: Refinement<A, B>): <S>( sa: Iso<S, ReadonlyNonEmptyArray<A>> ) => Optional<S, B>; <A>(predicate: Predicate<A>): <S>( sa: Iso<S, ReadonlyNonEmptyArray<A>> ) => Optional<S, A>;};combinators 2.3.8
function fromNullable
fromNullable: <S, A>(sa: Iso<S, A>) => Prism<S, NonNullable<A>>;Return a
Prismfrom aIsofocused on a nullable value.combinators 2.3.8
function id
id: <S>() => Iso<S, S>;constructors 2.3.0
function imap
imap: <A, B>(f: (a: A) => B, g: (b: B) => A) => <S>(sa: Iso<S, A>) => Iso<S, B>;Invariant 2.3.0
function index
index: (i: number) => <S, A>(sa: Iso<S, readonly A[]>) => Optional<S, A>;Return a
Optionalfrom aIsofocused on an index of aReadonlyArray.combinators 2.3.8
function indexNonEmpty
indexNonEmpty: ( i: number) => <S, A>(sa: Iso<S, ReadonlyNonEmptyArray<A>>) => Optional<S, A>;Return a
Optionalfrom aIsofocused on an index of aReadonlyNonEmptyArray.combinators 2.3.8
function iso
iso: <S, A>(get: (s: S) => A, reverseGet: (a: A) => S) => Iso<S, A>;constructors 2.3.8
function key
key: ( key: string) => <S, A>(sa: Iso<S, Readonly<Record<string, A>>>) => Optional<S, A>;Return a
Optionalfrom aIsofocused on a key of aReadonlyRecord.combinators 2.3.8
function left
left: <S, E, A>(sea: Iso<S, Either<E, A>>) => Prism<S, E>;Return a
Prismfrom aIsofocused on theLeftof aEithertype.combinators 2.3.8
function modify
modify: <A, B extends A = A>( f: (a: A) => B) => <S>(sa: Iso<S, A>) => (s: S) => S;combinators 2.3.0
function modifyF
modifyF: { <F extends URIS3>(F: Functor3<F>): <A, R, E>( f: (a: A) => Kind3<F, R, E, A> ) => <S>(sa: Iso<S, A>) => (s: S) => Kind3<F, R, E, S>; <F extends URIS2>(F: Functor2<F>): <A, E>( f: (a: A) => Kind2<F, E, A> ) => <S>(sa: Iso<S, A>) => (s: S) => Kind2<F, E, S>; <F extends URIS>(F: Functor1<F>): <A>( f: (a: A) => Kind<F, A> ) => <S>(sa: Iso<S, A>) => (s: S) => Kind<F, S>; <F>(F: Functor<F>): <A>( f: (a: A) => HKT<F, A> ) => <S>(sa: Iso<S, A>) => (s: S) => HKT<F, S>;};combinators 2.3.5
function prop
prop: <A, P extends keyof A>(prop: P) => <S>(sa: Iso<S, A>) => Lens<S, A[P]>;Return a
Lensfrom aIsoand a prop.combinators 2.3.8
function props
props: <A, P extends keyof A>( props_0: P, props_1: P, ...props_2: P[]) => <S>(sa: Iso<S, A>) => Lens<S, { [K in P]: A[K] }>;Return a
Lensfrom aIsoand a list of props.combinators 2.3.8
function reverse
reverse: <S, A>(sa: Iso<S, A>) => Iso<A, S>;constructors 2.3.0
function right
right: <S, E, A>(sea: Iso<S, Either<E, A>>) => Prism<S, A>;Return a
Prismfrom aIsofocused on theRightof aEithertype.combinators 2.3.8
function some
some: <S, A>(soa: Iso<S, Option<A>>) => Prism<S, A>;Return a
Prismfrom aIsofocused on theSomeof aOptiontype.combinators 2.3.8
function traverse
traverse: <T extends URIS>( T: Traversable1<T>) => <S, A>(sta: Iso<S, Kind<T, A>>) => Traversal<S, A>;Return a
Traversalfrom aIsofocused on aTraversable.combinators 2.3.8
interface Iso
interface Iso<S, A> {}model 2.3.0
property get
readonly get: (s: S) => A;property reverseGet
readonly reverseGet: (a: A) => S;type URI
type URI = typeof URI;instances 2.3.0
namespace lens
module 'lib/Lens.d.ts' {}**This module is experimental**
Experimental features are published in order to get early feedback from the community.
A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
A
Lensis an optic used to zoom inside a product.Lenses have two type parameters generally calledSandA:Lens<S, A>whereSrepresents the product andAan element inside ofS.Laws:
1.
get(set(a)(s)) = a2.set(get(s))(s) = s3.set(a)(set(a)(s)) = set(a)(s)2.3.0
variable Category
const Category: Category2<'monocle-ts/Lens'>;instances 2.3.0
variable Invariant
const Invariant: Invariant2<'monocle-ts/Lens'>;instances 2.3.0
variable Semigroupoid
const Semigroupoid: Semigroupoid2<'monocle-ts/Lens'>;instances 2.3.8
variable URI
const URI: string;instances 2.3.0
function asOptional
asOptional: <S, A>(sa: Lens<S, A>) => Optional<S, A>;View a
Lensas aOptional.converters 2.3.0
function asTraversal
asTraversal: <S, A>(sa: Lens<S, A>) => Traversal<S, A>;View a
Lensas aTraversal.converters 2.3.0
function atKey
atKey: ( key: string) => <S, A>(sa: Lens<S, ReadonlyRecord<string, A>>) => Lens<S, Option<A>>;Return a
Lensfrom aLensfocused on a required key of aReadonlyRecord.combinators 2.3.0
function component
component: <A extends readonly unknown[], P extends keyof A>( prop: P) => <S>(sa: Lens<S, A>) => Lens<S, A[P]>;Return a
Lensfrom aLensfocused on a component of a tuple.combinators 2.3.0
function compose
compose: <A, B>(ab: Lens<A, B>) => <S>(sa: Lens<S, A>) => Lens<S, B>;Compose a
Lenswith aLens.compositions 2.3.0
function composeIso
composeIso: <A, B>(ab: Iso<A, B>) => <S>(sa: Lens<S, A>) => Lens<S, B>;Compose a
Lenswith aIso.compositions 2.3.8
function composeLens
composeLens: <A, B>(ab: Lens<A, B>) => <S>(sa: Lens<S, A>) => Lens<S, B>;Alias of
compose.compositions 2.3.8
function composeOptional
composeOptional: <A, B>( ab: Optional<A, B>) => <S>(sa: Lens<S, A>) => Optional<S, B>;Compose a
Lenswith anOptional.compositions 2.3.0
function composePrism
composePrism: <A, B>(ab: Prism<A, B>) => <S>(sa: Lens<S, A>) => Optional<S, B>;Compose a
Lenswith aPrism.compositions 2.3.0
function composeTraversal
composeTraversal: <A, B>( ab: Traversal<A, B>) => <S>(sa: Lens<S, A>) => Traversal<S, B>;Compose a
Lenswith anTraversal.compositions 2.3.8
function filter
filter: { <A, B extends A>(refinement: Refinement<A, B>): <S>( sa: Lens<S, A> ) => Optional<S, B>; <A>(predicate: Predicate<A>): <S>(sa: Lens<S, A>) => Optional<S, A>;};combinators 2.3.0
function findFirst
findFirst: { <A, B extends A>(refinement: Refinement<A, B>): <S>( sa: Lens<S, readonly A[]> ) => Optional<S, B>; <A>(predicate: Predicate<A>): <S>(sa: Lens<S, readonly A[]>) => Optional<S, A>;};combinators 2.3.2
function findFirstNonEmpty
findFirstNonEmpty: { <A, B extends A>(refinement: Refinement<A, B>): <S>( sa: Lens<S, ReadonlyNonEmptyArray<A>> ) => Optional<S, B>; <A>(predicate: Predicate<A>): <S>( sa: Lens<S, ReadonlyNonEmptyArray<A>> ) => Optional<S, A>;};combinators 2.3.8
function fromNullable
fromNullable: <S, A>(sa: Lens<S, A>) => Optional<S, NonNullable<A>>;Return a
Optionalfrom aLensfocused on a nullable value.combinators 2.3.0
function id
id: <S>() => Lens<S, S>;constructors 2.3.0
function imap
imap: <A, B>( f: (a: A) => B, g: (b: B) => A) => <E>(sa: Lens<E, A>) => Lens<E, B>;Invariant 2.3.0
function index
index: (i: number) => <S, A>(sa: Lens<S, readonly A[]>) => Optional<S, A>;Return a
Optionalfrom aLensfocused on an index of aReadonlyArray.combinators 2.3.0
function indexNonEmpty
indexNonEmpty: ( i: number) => <S, A>(sa: Lens<S, ReadonlyNonEmptyArray<A>>) => Optional<S, A>;Return a
Optionalfrom aLensfocused on an index of aReadonlyNonEmptyArray.combinators 2.3.8
function key
key: ( key: string) => <S, A>(sa: Lens<S, Readonly<Record<string, A>>>) => Optional<S, A>;Return a
Optionalfrom aLensfocused on a key of aReadonlyRecord.combinators 2.3.0
function left
left: <S, E, A>(sea: Lens<S, Either<E, A>>) => Optional<S, E>;Return a
Optionalfrom aLensfocused on theLeftof aEithertype.combinators 2.3.0
function lens
lens: <S, A>(get: (s: S) => A, set: (a: A) => (s: S) => S) => Lens<S, A>;constructors 2.3.8
function modify
modify: <A, B extends A = A>( f: (a: A) => B) => <S>(sa: Lens<S, A>) => (s: S) => S;combinators 2.3.0
function modifyF
modifyF: { <F extends URIS3>(F: Functor3<F>): <A, R, E>( f: (a: A) => Kind3<F, R, E, A> ) => <S>(sa: Lens<S, A>) => (s: S) => Kind3<F, R, E, S>; <F extends URIS2>(F: Functor2<F>): <A, E>( f: (a: A) => Kind2<F, E, A> ) => <S>(sa: Lens<S, A>) => (s: S) => Kind2<F, E, S>; <F extends URIS>(F: Functor1<F>): <A>( f: (a: A) => Kind<F, A> ) => <S>(sa: Lens<S, A>) => (s: S) => Kind<F, S>; <F>(F: Functor<F>): <A>( f: (a: A) => HKT<F, A> ) => <S>(sa: Lens<S, A>) => (s: S) => HKT<F, S>;};combinators 2.3.5
function prop
prop: <A, P extends keyof A>(prop: P) => <S>(sa: Lens<S, A>) => Lens<S, A[P]>;Return a
Lensfrom aLensand a prop.combinators 2.3.0
function props
props: <A, P extends keyof A>( props_0: P, props_1: P, ...props_2: P[]) => <S>(sa: Lens<S, A>) => Lens<S, { [K in P]: A[K] }>;Return a
Lensfrom aLensand a list of props.combinators 2.3.0
function right
right: <S, E, A>(sea: Lens<S, Either<E, A>>) => Optional<S, A>;Return a
Optionalfrom aLensfocused on theRightof aEithertype.combinators 2.3.0
function some
some: <S, A>(soa: Lens<S, Option<A>>) => Optional<S, A>;Return a
Optionalfrom aLensfocused on theSomeof aOptiontype.combinators 2.3.0
function traverse
traverse: <T extends URIS>( T: Traversable1<T>) => <S, A>(sta: Lens<S, Kind<T, A>>) => Traversal<S, A>;Return a
Traversalfrom aLensfocused on aTraversable.combinators 2.3.0
interface Lens
interface Lens<S, A> {}model 2.3.0
type URI
type URI = typeof URI;instances 2.3.0
namespace optional
module 'lib/Optional.d.ts' {}**This module is experimental**
Experimental features are published in order to get early feedback from the community.
A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
An
Optionalis an optic used to zoom inside a product. Unlike theLens, the element that theOptionalfocuses on may not exist.Optionals have two type parameters generally calledSandA:Optional<S, A>whereSrepresents the product andAan optional element inside ofS.Laws:
1.
pipe(getOption(s), fold(() => s, a => set(a)(s))) = s2.getOption(set(a)(s)) = pipe(getOption(s), map(_ => a))3.set(a)(set(a)(s)) = set(a)(s)2.3.0
variable Category
const Category: Category2<'monocle-ts/Optional'>;instances 2.3.0
variable Invariant
const Invariant: Invariant2<'monocle-ts/Optional'>;instances 2.3.0
variable Semigroupoid
const Semigroupoid: Semigroupoid2<'monocle-ts/Optional'>;instances 2.3.8
variable URI
const URI: string;instances 2.3.0
function asTraversal
asTraversal: <S, A>(sa: Optional<S, A>) => Traversal<S, A>;View a
Optionalas aTraversal.converters 2.3.0
function atKey
atKey: ( key: string) => <S, A>( sa: Optional<S, Readonly<Record<string, A>>>) => Optional<S, O.Option<A>>;Return a
Optionalfrom aOptionalfocused on a required key of aReadonlyRecord.combinators 2.3.0
function component
component: <A extends readonly unknown[], P extends keyof A>( prop: P) => <S>(sa: Optional<S, A>) => Optional<S, A[P]>;Return a
Optionalfrom aOptionalfocused on a component of a tuple.combinators 2.3.0
function compose
compose: <A, B>(ab: Optional<A, B>) => <S>(sa: Optional<S, A>) => Optional<S, B>;Compose a
Optionalwith aOptional.compositions 2.3.0
function composeIso
composeIso: <A, B>(ab: Iso<A, B>) => <S>(sa: Optional<S, A>) => Optional<S, B>;Compose a
Optionalwith aIso.compositions 2.3.8
function composeLens
composeLens: <A, B>(ab: Lens<A, B>) => <S>(sa: Optional<S, A>) => Optional<S, B>;Compose a
Optionalwith aLens.compositions 2.3.7
function composeOptional
composeOptional: <A, B>( ab: Optional<A, B>) => <S>(sa: Optional<S, A>) => Optional<S, B>;Alias of
compose.compositions 2.3.8
function composePrism
composePrism: <A, B>( ab: Prism<A, B>) => <S>(sa: Optional<S, A>) => Optional<S, B>;Compose a
Optionalwith aPrism.compositions 2.3.7
function composeTraversal
composeTraversal: <A, B>( ab: Traversal<A, B>) => <S>(sa: Optional<S, A>) => Traversal<S, B>;Compose a
Optionalwith anTraversal.compositions 2.3.8
function filter
filter: { <A, B extends A>(refinement: Refinement<A, B>): <S>( sa: Optional<S, A> ) => Optional<S, B>; <A>(predicate: Predicate<A>): <S>(sa: Optional<S, A>) => Optional<S, A>;};combinators 2.3.0
function findFirst
findFirst: { <A, B extends A>(refinement: Refinement<A, B>): <S>( sa: Optional<S, readonly A[]> ) => Optional<S, B>; <A>(predicate: Predicate<A>): <S>( sa: Optional<S, readonly A[]> ) => Optional<S, A>;};combinators 2.3.2
function findFirstNonEmpty
findFirstNonEmpty: { <A, B extends A>(refinement: Refinement<A, B>): <S>( sa: Optional<S, ReadonlyNonEmptyArray<A>> ) => Optional<S, B>; <A>(predicate: Predicate<A>): <S>( sa: Optional<S, ReadonlyNonEmptyArray<A>> ) => Optional<S, A>;};combinators 2.3.8
function fromNullable
fromNullable: <S, A>(sa: Optional<S, A>) => Optional<S, NonNullable<A>>;Return an
Optionalfrom aOptionalfocused on a nullable value.combinators 2.3.3
function id
id: <S>() => Optional<S, S>;constructors 2.3.0
function imap
imap: <A, B>( f: (a: A) => B, g: (b: B) => A) => <E>(fa: Optional<E, A>) => Optional<E, B>;Invariant 2.3.0
function index
index: (i: number) => <S, A>(sa: Optional<S, readonly A[]>) => Optional<S, A>;Return a
Optionalfrom aOptionalfocused on an index of aReadonlyArray.combinators 2.3.0
function indexNonEmpty
indexNonEmpty: ( i: number) => <S, A>(sa: Optional<S, ReadonlyNonEmptyArray<A>>) => Optional<S, A>;Return a
Optionalfrom aOptionalfocused on an index of aReadonlyNonEmptyArray.combinators 2.3.8
function key
key: ( key: string) => <S, A>(sa: Optional<S, ReadonlyRecord<string, A>>) => Optional<S, A>;Return a
Optionalfrom aOptionalfocused on a key of aReadonlyRecord.combinators 2.3.0
function left
left: <S, E, A>(sea: Optional<S, Either<E, A>>) => Optional<S, E>;Return a
Optionalfrom aOptionalfocused on theLeftof aEithertype.combinators 2.3.0
function modify
modify: <A, B extends A = A>( f: (a: A) => B) => <S>(optional: Optional<S, A>) => (s: S) => S;combinators 2.3.0
function modifyF
modifyF: { <F extends URIS3>(F: Applicative3<F>): <A, R, E>( f: (a: A) => Kind3<F, R, E, A> ) => <S>(sa: Optional<S, A>) => (s: S) => Kind3<F, R, E, S>; <F extends URIS2>(F: Applicative2<F>): <A, E>( f: (a: A) => Kind2<F, E, A> ) => <S>(sa: Optional<S, A>) => (s: S) => Kind2<F, E, S>; <F extends URIS>(F: Applicative1<F>): <A>( f: (a: A) => Kind<F, A> ) => <S>(sa: Optional<S, A>) => (s: S) => Kind<F, S>; <F>(F: Applicative<F>): <A>( f: (a: A) => HKT<F, A> ) => <S>(sa: Optional<S, A>) => (s: S) => HKT<F, S>;};combinators 2.3.5
function modifyOption
modifyOption: <A, B extends A = A>( f: (a: A) => B) => <S>(optional: Optional<S, A>) => (s: S) => Option<S>;combinators 2.3.0
function optional
optional: <S, A>( getOption: (s: S) => Option<A>, set: (a: A) => (s: S) => S) => Optional<S, A>;constructors 2.3.8
function prop
prop: <A, P extends keyof A>( prop: P) => <S>(sa: Optional<S, A>) => Optional<S, A[P]>;Return a
Optionalfrom aOptionaland a prop.combinators 2.3.0
function props
props: <A, P extends keyof A>( props_0: P, props_1: P, ...props_2: P[]) => <S>(sa: Optional<S, A>) => Optional<S, { [K in P]: A[K] }>;Return a
Optionalfrom aOptionaland a list of props.combinators 2.3.0
function right
right: <S, E, A>(sea: Optional<S, Either<E, A>>) => Optional<S, A>;Return a
Optionalfrom aOptionalfocused on theRightof aEithertype.combinators 2.3.0
function setOption
setOption: <A>(a: A) => <S>(optional: Optional<S, A>) => (s: S) => O.Option<S>;combinators 2.3.7
function some
some: <S, A>(soa: Optional<S, Option<A>>) => Optional<S, A>;Return a
Optionalfrom aOptionalfocused on theSomeof aOptiontype.combinators 2.3.0
function traverse
traverse: <T extends URIS>( T: Traversable1<T>) => <S, A>(sta: Optional<S, Kind<T, A>>) => Traversal<S, A>;Return a
Traversalfrom aOptionalfocused on aTraversable.combinators 2.3.0
interface Optional
interface Optional<S, A> {}model 2.3.0
type URI
type URI = typeof URI;instances 2.3.0
namespace prism
module 'lib/Prism.d.ts' {}**This module is experimental**
Experimental features are published in order to get early feedback from the community.
A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
A
Prismis an optic used to select part of a sum type.Laws:
1.
pipe(getOption(s), fold(() => s, reverseGet)) = s2.getOption(reverseGet(a)) = some(a)2.3.0
variable Category
const Category: Category2<'monocle-ts/Prism'>;instances 2.3.0
variable fromPredicate
const fromPredicate: { <S, A extends S>(refinement: Refinement<S, A>): Prism<S, A>; <A>(predicate: Predicate<A>): Prism<A, A>;};constructors 2.3.0
variable Invariant
const Invariant: Invariant2<'monocle-ts/Prism'>;instances 2.3.0
variable Semigroupoid
const Semigroupoid: Semigroupoid2<'monocle-ts/Prism'>;instances 2.3.8
variable URI
const URI: string;instances 2.3.0
function asOptional
asOptional: <S, A>(sa: Prism<S, A>) => Optional<S, A>;View a
Prismas aOptional.converters 2.3.0
function asTraversal
asTraversal: <S, A>(sa: Prism<S, A>) => Traversal<S, A>;View a
Prismas aTraversal.converters 2.3.0
function atKey
atKey: ( key: string) => <S, A>(sa: Prism<S, Readonly<Record<string, A>>>) => Optional<S, O.Option<A>>;Return a
Optionalfrom aPrismfocused on a required key of aReadonlyRecord.combinators 2.3.0
function component
component: <A extends readonly unknown[], P extends keyof A>( prop: P) => <S>(sa: Prism<S, A>) => Optional<S, A[P]>;Return a
Optionalfrom aPrismfocused on a component of a tuple.combinators 2.3.0
function compose
compose: <A, B>(ab: Prism<A, B>) => <S>(sa: Prism<S, A>) => Prism<S, B>;Compose a
Prismwith aPrism.compositions 2.3.0
function composeIso
composeIso: <A, B>(ab: Iso<A, B>) => <S>(sa: Prism<S, A>) => Prism<S, B>;Compose a
Prismwith aIso.compositions 2.3.8
function composeLens
composeLens: <A, B>(ab: Lens<A, B>) => <S>(sa: Prism<S, A>) => Optional<S, B>;Compose a
Prismwith aLens.compositions 2.3.0
function composeOptional
composeOptional: <A, B>( ab: Optional<A, B>) => <S>(sa: Prism<S, A>) => Optional<S, B>;Compose a
Prismwith anOptional.compositions 2.3.0
function composePrism
composePrism: <A, B>(ab: Prism<A, B>) => <S>(sa: Prism<S, A>) => Prism<S, B>;Alias of
compose.compositions 2.3.8
function composeTraversal
composeTraversal: <A, B>( ab: Traversal<A, B>) => <S>(sa: Prism<S, A>) => Traversal<S, B>;Compose a
Prismwith anTraversal.compositions 2.3.8
function filter
filter: { <A, B extends A>(refinement: Refinement<A, B>): <S>( sa: Prism<S, A> ) => Prism<S, B>; <A>(predicate: Predicate<A>): <S>(sa: Prism<S, A>) => Prism<S, A>;};combinators 2.3.0
function findFirst
findFirst: { <A, B extends A>(refinement: Refinement<A, B>): <S>( sa: Prism<S, readonly A[]> ) => Optional<S, B>; <A>(predicate: Predicate<A>): <S>(sa: Prism<S, readonly A[]>) => Optional<S, A>;};combinators 2.3.2
function findFirstNonEmpty
findFirstNonEmpty: { <A, B extends A>(refinement: Refinement<A, B>): <S>( sa: Prism<S, ReadonlyNonEmptyArray<A>> ) => Optional<S, B>; <A>(predicate: Predicate<A>): <S>( sa: Prism<S, ReadonlyNonEmptyArray<A>> ) => Optional<S, A>;};combinators 2.3.8
function fromNullable
fromNullable: <S, A>(sa: Prism<S, A>) => Prism<S, NonNullable<A>>;Return a
Prismfrom aPrismfocused on a nullable value.combinators 2.3.3
function id
id: <S>() => Prism<S, S>;constructors 2.3.0
function imap
imap: <A, B>( f: (a: A) => B, g: (b: B) => A) => <E>(sa: Prism<E, A>) => Prism<E, B>;Invariant 2.3.0
function index
index: (i: number) => <S, A>(sa: Prism<S, readonly A[]>) => Optional<S, A>;Return a
Optionalfrom aPrismfocused on an index of aReadonlyArray.combinators 2.3.0
function indexNonEmpty
indexNonEmpty: ( i: number) => <S, A>(sa: Prism<S, ReadonlyNonEmptyArray<A>>) => Optional<S, A>;Return a
Optionalfrom aPrismfocused on an index of aReadonlyNonEmptyArray.combinators 2.3.8
function key
key: ( key: string) => <S, A>(sa: Prism<S, Readonly<Record<string, A>>>) => Optional<S, A>;Return a
Optionalfrom aPrismfocused on a key of aReadonlyRecord.combinators 2.3.0
function left
left: <S, E, A>(sea: Prism<S, Either<E, A>>) => Prism<S, E>;Return a
Prismfrom aPrismfocused on theLeftof aEithertype.combinators 2.3.0
function modify
modify: <A, B extends A = A>( f: (a: A) => B) => <S>(sa: Prism<S, A>) => (s: S) => S;combinators 2.3.0
function modifyF
modifyF: { <F extends URIS3>(F: Applicative3<F>): <A, R, E>( f: (a: A) => Kind3<F, R, E, A> ) => <S>(sa: Prism<S, A>) => (s: S) => Kind3<F, R, E, S>; <F extends URIS2>(F: Applicative2<F>): <A, E>( f: (a: A) => Kind2<F, E, A> ) => <S>(sa: Prism<S, A>) => (s: S) => Kind2<F, E, S>; <F extends URIS>(F: Applicative1<F>): <A>( f: (a: A) => Kind<F, A> ) => <S>(sa: Prism<S, A>) => (s: S) => Kind<F, S>; <F>(F: Applicative<F>): <A>( f: (a: A) => HKT<F, A> ) => <S>(sa: Prism<S, A>) => (s: S) => HKT<F, S>;};combinators 2.3.5
function modifyOption
modifyOption: <A, B extends A = A>( f: (a: A) => B) => <S>(sa: Prism<S, A>) => (s: S) => Option<S>;combinators 2.3.0
function prism
prism: <S, A>( getOption: (s: S) => Option<A>, reverseGet: (a: A) => S) => Prism<S, A>;constructors 2.3.8
function prop
prop: <A, P extends keyof A>( prop: P) => <S>(sa: Prism<S, A>) => Optional<S, A[P]>;Return a
Optionalfrom aPrismand a prop.combinators 2.3.0
function props
props: <A, P extends keyof A>( props_0: P, props_1: P, ...props_2: P[]) => <S>(sa: Prism<S, A>) => Optional<S, { [K in P]: A[K] }>;Return a
Optionalfrom aPrismand a list of props.combinators 2.3.0
function right
right: <S, E, A>(sea: Prism<S, Either<E, A>>) => Prism<S, A>;Return a
Prismfrom aPrismfocused on theRightof aEithertype.combinators 2.3.0
function set
set: <A>(a: A) => <S>(sa: Prism<S, A>) => (s: S) => S;combinators 2.3.0
function some
some: <S, A>(soa: Prism<S, Option<A>>) => Prism<S, A>;Return a
Prismfrom aPrismfocused on theSomeof aOptiontype.combinators 2.3.0
function traverse
traverse: <T extends URIS>( T: Traversable1<T>) => <S, A>(sta: Prism<S, Kind<T, A>>) => Traversal<S, A>;Return a
Traversalfrom aPrismfocused on aTraversable.combinators 2.3.0
interface Prism
interface Prism<S, A> {}model 2.3.0
property getOption
readonly getOption: (s: S) => Option<A>;property reverseGet
readonly reverseGet: (a: A) => S;type URI
type URI = typeof URI;instances 2.3.0
namespace traversal
module 'lib/Traversal.d.ts' {}**This module is experimental**
Experimental features are published in order to get early feedback from the community.
A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
A
Traversalis the generalisation of anOptionalto several targets. In other word, aTraversalallows to focus from a typeSinto0tonvalues of typeA.The most common example of a
Traversalwould be to focus into all elements inside of a container (e.g.ReadonlyArray,Option). To do this we will use the relation between the typeclassTraversableandTraversal.2.3.0
variable Category
const Category: Category2<'monocle-ts/Traversal'>;instances 2.3.0
variable fromTraversable
const fromTraversable: { <T extends URIS3>(T: Traversable3<T>): <R, E, A>() => Traversal< Kind3<T, R, E, A>, A >; <T extends URIS2>(T: Traversable2<T>): <E, A>() => Traversal<Kind2<T, E, A>, A>; <T extends URIS>(T: Traversable1<T>): <A>() => Traversal<Kind<T, A>, A>; <T>(T: Traversable<T>): <A>() => Traversal<HKT<T, A>, A>;};Create a
Traversalfrom aTraversable.constructor 2.3.0
variable Semigroupoid
const Semigroupoid: Semigroupoid2<'monocle-ts/Traversal'>;instances 2.3.8
variable URI
const URI: string;instances 2.3.0
function atKey
atKey: ( key: string) => <S, A>( sa: Traversal<S, Readonly<Record<string, A>>>) => Traversal<S, Option<A>>;Return a
Traversalfrom aTraversalfocused on a required key of aReadonlyRecord.combinators 2.3.0
function component
component: <A extends readonly unknown[], P extends keyof A>( prop: P) => <S>(sa: Traversal<S, A>) => Traversal<S, A[P]>;Return a
Traversalfrom aTraversalfocused on a component of a tuple.combinators 2.3.0
function compose
compose: <A, B>( ab: Traversal<A, B>) => <S>(sa: Traversal<S, A>) => Traversal<S, B>;Compose a
Traversalwith aTraversal.compositions 2.3.0
function composeIso
composeIso: <A, B>(ab: Iso<A, B>) => <S>(sa: Traversal<S, A>) => Traversal<S, B>;Compose a
Traversalwith aIso.compositions 2.3.8
function composeLens
composeLens: <A, B>( ab: Lens<A, B>) => <S>(sa: Traversal<S, A>) => Traversal<S, B>;Compose a
Traversalwith aLens.compositions 2.3.8
function composeOptional
composeOptional: <A, B>( ab: Optional<A, B>) => <S>(sa: Traversal<S, A>) => Traversal<S, B>;Compose a
Traversalwith aOptional.compositions 2.3.8
function composePrism
composePrism: <A, B>( ab: Prism<A, B>) => <S>(sa: Traversal<S, A>) => Traversal<S, B>;Compose a
Traversalwith aPrism.compositions 2.3.8
function composeTraversal
composeTraversal: <A, B>( ab: Traversal<A, B>) => <S>(sa: Traversal<S, A>) => Traversal<S, B>;Alias of
compose.compositions 2.3.8
function filter
filter: { <A, B extends A>(refinement: Refinement<A, B>): <S>( sa: Traversal<S, A> ) => Traversal<S, B>; <A>(predicate: Predicate<A>): <S>(sa: Traversal<S, A>) => Traversal<S, A>;};combinators 2.3.0
function findFirst
findFirst: { <A, B extends A>(refinement: Refinement<A, B>): <S>( sa: Traversal<S, readonly A[]> ) => Traversal<S, B>; <A>(predicate: Predicate<A>): <S>( sa: Traversal<S, readonly A[]> ) => Traversal<S, A>;};combinators 2.3.8
function findFirstNonEmpty
findFirstNonEmpty: { <A, B extends A>(refinement: Refinement<A, B>): <S>( sa: Traversal<S, ReadonlyNonEmptyArray<A>> ) => Traversal<S, B>; <A>(predicate: Predicate<A>): <S>( sa: Traversal<S, ReadonlyNonEmptyArray<A>> ) => Traversal<S, A>;};combinators 2.3.8
function fold
fold: <A>(M: Monoid<A>) => <S>(sa: Traversal<S, A>) => (s: S) => A;Map each target to a
Monoidand combine the results.combinators 2.3.0
function foldMap
foldMap: <M>( M: Monoid<M>) => <A>(f: (a: A) => M) => <S>(sa: Traversal<S, A>) => (s: S) => M;Map each target to a
Monoidand combine the results.combinators 2.3.0
function fromNullable
fromNullable: <S, A>(sa: Traversal<S, A>) => Traversal<S, NonNullable<A>>;Return a
Traversalfrom aTraversalfocused on a nullable value.combinators 2.3.0
function getAll
getAll: <S>(s: S) => <A>(sa: Traversal<S, A>) => readonly A[];Get all the targets of a
Traversal.combinators 2.3.0
function id
id: <S>() => Traversal<S, S>;constructors 2.3.0
function index
index: (i: number) => <S, A>(sa: Traversal<S, readonly A[]>) => Traversal<S, A>;Return a
Traversalfrom aTraversalfocused on an index of aReadonlyArray.combinators 2.3.0
function indexNonEmpty
indexNonEmpty: ( i: number) => <S, A>(sa: Traversal<S, ReadonlyNonEmptyArray<A>>) => Traversal<S, A>;combinators 2.3.8
function key
key: ( key: string) => <S, A>(sa: Traversal<S, Readonly<Record<string, A>>>) => Traversal<S, A>;Return a
Traversalfrom aTraversalfocused on a key of aReadonlyRecord.combinators 2.3.0
function left
left: <S, E, A>(sea: Traversal<S, Either<E, A>>) => Traversal<S, E>;Return a
Traversalfrom aTraversalfocused on theLeftof aEithertype.combinators 2.3.0
function modify
modify: <A, B extends A = A>( f: (a: A) => B) => <S>(sa: Traversal<S, A>) => (s: S) => S;combinators 2.3.0
function prop
prop: <A, P extends keyof A>( prop: P) => <S>(sa: Traversal<S, A>) => Traversal<S, A[P]>;Return a
Traversalfrom aTraversaland a prop.combinators 2.3.0
function props
props: <A, P extends keyof A>( props_0: P, props_1: P, ...props_2: P[]) => <S>(sa: Traversal<S, A>) => Traversal<S, { [K in P]: A[K] }>;Return a
Traversalfrom aTraversaland a list of props.combinators 2.3.0
function right
right: <S, E, A>(sea: Traversal<S, Either<E, A>>) => Traversal<S, A>;Return a
Traversalfrom aTraversalfocused on theRightof aEithertype.combinators 2.3.0
function set
set: <A>(a: A) => <S>(sa: Traversal<S, A>) => (s: S) => S;combinators 2.3.0
function some
some: <S, A>(soa: Traversal<S, Option<A>>) => Traversal<S, A>;Return a
Traversalfrom aTraversalfocused on theSomeof aOptiontype.combinators 2.3.0
function traversal
traversal: <S, A>(modifyF: ModifyF<S, A>) => Traversal<S, A>;constructors 2.3.8
function traverse
traverse: <T extends URIS>( T: Traversable1<T>) => <S, A>(sta: Traversal<S, Kind<T, A>>) => Traversal<S, A>;Return a
Traversalfrom aTraversalfocused on aTraversable.combinators 2.3.0
interface ModifyF
interface ModifyF<S, A> {}model 2.3.0
call signature
<F extends URIS3>(F: Applicative3<F>): <R, E>( f: (a: A) => Kind3<F, R, E, A>) => (s: S) => Kind3<F, R, E, S>;call signature
<F extends URIS2>(F: Applicative2<F>): <E>( f: (a: A) => Kind2<F, E, A>) => (s: S) => Kind2<F, E, S>;call signature
<F extends URIS2, E>(F: Applicative2C<F, E>): ( f: (a: A) => Kind2<F, E, A>) => (s: S) => Kind2<F, E, S>;call signature
<F extends URIS>(F: Applicative1<F>): ( f: (a: A) => Kind<F, A>) => (s: S) => Kind<F, S>;call signature
<F>(F: Applicative<F>): (f: (a: A) => HKT<F, A>) => (s: S) => HKT<F, S>;interface Traversal
interface Traversal<S, A> {}model 2.3.0
property modifyF
readonly modifyF: ModifyF<S, A>;type URI
type URI = typeof URI;instances 2.3.0
Package Files (8)
Dependencies (0)
No dependencies.
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (1)
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/monocle-ts.
- Markdown[](https://www.jsdocs.io/package/monocle-ts)
- HTML<a href="https://www.jsdocs.io/package/monocle-ts"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 9408 ms. - Missing or incorrect documentation? Open an issue for this package.
