monocle-ts
- Version 2.3.13
- Published
- 368 kB
- No dependencies
- MIT license
Install
npm i monocle-ts
yarn add monocle-ts
pnpm add monocle-ts
Overview
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
Fold
from aFoldable
constructor 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
Traversal
from aTraversable
Example 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
At
using anIso
1.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
Fold
1.0.0
method compose
compose: <B>(ab: Fold<A, B>) => Fold<S, B>;
compose a
Fold
with aFold
1.0.0
method composeFold
composeFold: <B>(ab: Fold<A, B>) => Fold<S, B>;
Alias of
compose
1.0.0
method composeGetter
composeGetter: <B>(ab: Getter<A, B>) => Fold<S, B>;
compose a
Fold
with aGetter
1.0.0
method composeIso
composeIso: <B>(ab: Iso<A, B>) => Fold<S, B>;
compose a
Fold
with aIso
1.0.0
method composeLens
composeLens: <B>(ab: Lens<A, B>) => Fold<S, B>;
compose a
Fold
with aLens
1.0.0
method composeOptional
composeOptional: <B>(ab: Optional<A, B>) => Fold<S, B>;
compose a
Fold
with aOptional
1.0.0
method composePrism
composePrism: <B>(ab: Prism<A, B>) => Fold<S, B>;
compose a
Fold
with aPrism
1.0.0
method composeTraversal
composeTraversal: <B>(ab: Traversal<A, B>) => Fold<S, B>;
compose a
Fold
with aTraversal
1.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
Fold
matching the predicate1.0.0
method headOption
headOption: (s: S) => Option<A>;
get the first target of a
Fold
1.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
Getter
as aFold
1.0.0
method compose
compose: <B>(ab: Getter<A, B>) => Getter<S, B>;
compose a
Getter
with aGetter
1.0.0
method composeFold
composeFold: <B>(ab: Fold<A, B>) => Fold<S, B>;
compose a
Getter
with aFold
1.0.0
method composeGetter
composeGetter: <B>(ab: Getter<A, B>) => Getter<S, B>;
Alias of
compose
1.0.0
method composeIso
composeIso: <B>(ab: Iso<A, B>) => Getter<S, B>;
compose a
Getter
with aIso
1.0.0
method composeLens
composeLens: <B>(ab: Lens<A, B>) => Getter<S, B>;
compose a
Getter
with aLens
1.0.0
method composeOptional
composeOptional: <B>(ab: Optional<A, B>) => Fold<S, B>;
compose a
Getter
with aOptional
1.0.0
method composePrism
composePrism: <B>(ab: Prism<A, B>) => Fold<S, B>;
compose a
Getter
with aPrism
1.0.0
method composeTraversal
composeTraversal: <B>(ab: Traversal<A, B>) => Fold<S, B>;
compose a
Getter
with aOptional
1.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
Index
using anIso
1.2.0
class Iso
class Iso<S, A> {}
Laws: 1.
reverseGet(get(s)) = s
2.get(reversetGet(a)) = a
constructor 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
Iso
as aFold
1.0.0
method asGetter
asGetter: () => Getter<S, A>;
view an
Iso
as aGetter
1.0.0
method asLens
asLens: () => Lens<S, A>;
view an
Iso
as aLens
1.0.0
method asOptional
asOptional: () => Optional<S, A>;
view an
Iso
as aOptional
1.0.0
method asPrism
asPrism: () => Prism<S, A>;
view an
Iso
as aPrism
1.0.0
method asSetter
asSetter: () => Setter<S, A>;
view an
Iso
as aSetter
1.0.0
method asTraversal
asTraversal: () => Traversal<S, A>;
view an
Iso
as aTraversal
1.0.0
method compose
compose: <B>(ab: Iso<A, B>) => Iso<S, B>;
compose an
Iso
with anIso
1.0.0
method composeFold
composeFold: <B>(ab: Fold<A, B>) => Fold<S, B>;
compose an
Iso
with aFold
1.0.0
method composeGetter
composeGetter: <B>(ab: Getter<A, B>) => Getter<S, B>;
compose an
Iso
with aGetter
1.0.0
method composeIso
composeIso: <B>(ab: Iso<A, B>) => Iso<S, B>;
Alias of
compose
1.0.0
method composeLens
composeLens: <B>(ab: Lens<A, B>) => Lens<S, B>;
compose an
Iso
with aLens
1.0.0
method composeOptional
composeOptional: <B>(ab: Optional<A, B>) => Optional<S, B>;
compose an
Iso
with anOptional
1.0.0
method composePrism
composePrism: <B>(ab: Prism<A, B>) => Prism<S, B>;
compose an
Iso
with aPrism
1.0.0
method composeSetter
composeSetter: <B>(ab: Setter<A, B>) => Setter<S, B>;
compose an
Iso
with aSetter
1.0.0
method composeTraversal
composeTraversal: <B>(ab: Traversal<A, B>) => Traversal<S, B>;
compose an
Iso
with aTraversal
1.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)) = a
2.set(get(s))(s) = s
3.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
Lens
as aFold
1.0.0
method asGetter
asGetter: () => Getter<S, A>;
view a
Lens
as aGetter
1.0.0
method asOptional
asOptional: () => Optional<S, A>;
view a
Lens
as a Optional1.0.0
method asSetter
asSetter: () => Setter<S, A>;
view a
Lens
as aSetter
1.0.0
method asTraversal
asTraversal: () => Traversal<S, A>;
view a
Lens
as aTraversal
1.0.0
method compose
compose: <B>(ab: Lens<A, B>) => Lens<S, B>;
compose a
Lens
with aLens
1.0.0
method composeFold
composeFold: <B>(ab: Fold<A, B>) => Fold<S, B>;
compose a
Lens
with aFold
1.0.0
method composeGetter
composeGetter: <B>(ab: Getter<A, B>) => Getter<S, B>;
compose a
Lens
with aGetter
1.0.0
method composeIso
composeIso: <B>(ab: Iso<A, B>) => Lens<S, B>;
compose a
Lens
with anIso
1.0.0
method composeLens
composeLens: <B>(ab: Lens<A, B>) => Lens<S, B>;
Alias of
compose
1.0.0
method composeOptional
composeOptional: <B>(ab: Optional<A, B>) => Optional<S, B>;
compose a
Lens
with anOptional
1.0.0
method composePrism
composePrism: <B>(ab: Prism<A, B>) => Optional<S, B>;
compose a
Lens
with aPrism
1.0.0
method composeSetter
composeSetter: <B>(ab: Setter<A, B>) => Setter<S, B>;
compose a
Lens
with anSetter
1.0.0
method composeTraversal
composeTraversal: <B>(ab: Traversal<A, B>) => Traversal<S, B>;
compose a
Lens
with anTraversal
1.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
Lens
from 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
Lens
from 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
Lens
from 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))) = s
2.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
Optional
as aFold
1.0.0
method asSetter
asSetter: () => Setter<S, A>;
view an
Optional
as aSetter
1.0.0
method asTraversal
asTraversal: () => Traversal<S, A>;
view a
Optional
as aTraversal
1.0.0
method compose
compose: <B>(ab: Optional<A, B>) => Optional<S, B>;
compose a
Optional
with aOptional
1.0.0
method composeFold
composeFold: <B>(ab: Fold<A, B>) => Fold<S, B>;
compose an
Optional
with aFold
1.0.0
method composeGetter
composeGetter: <B>(ab: Getter<A, B>) => Fold<S, B>;
compose an
Optional
with aGetter
1.0.0
method composeIso
composeIso: <B>(ab: Iso<A, B>) => Optional<S, B>;
compose an
Optional
with aIso
1.0.0
method composeLens
composeLens: <B>(ab: Lens<A, B>) => Optional<S, B>;
compose an
Optional
with aLens
1.0.0
method composeOptional
composeOptional: <B>(ab: Optional<A, B>) => Optional<S, B>;
Alias of
compose
1.0.0
method composePrism
composePrism: <B>(ab: Prism<A, B>) => Optional<S, B>;
compose an
Optional
with aPrism
1.0.0
method composeSetter
composeSetter: <B>(ab: Setter<A, B>) => Setter<S, B>;
compose an
Optional
with aSetter
1.0.0
method composeTraversal
composeTraversal: <B>(ab: Traversal<A, B>) => Traversal<S, B>;
compose an
Optional
with aTraversal
1.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
Optional
from 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
Optional
from 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)) = s
2.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
Prism
as aFold
1.0.0
method asOptional
asOptional: () => Optional<S, A>;
view a
Prism
as aOptional
1.0.0
method asSetter
asSetter: () => Setter<S, A>;
view a
Prism
as aSetter
1.0.0
method asTraversal
asTraversal: () => Traversal<S, A>;
view a
Prism
as aTraversal
1.0.0
method compose
compose: <B>(ab: Prism<A, B>) => Prism<S, B>;
compose a
Prism
with aPrism
1.0.0
method composeFold
composeFold: <B>(ab: Fold<A, B>) => Fold<S, B>;
compose a
Prism
with aFold
1.0.0
method composeGetter
composeGetter: <B>(ab: Getter<A, B>) => Fold<S, B>;
compose a
Prism
with aGetter
1.0.0
method composeIso
composeIso: <B>(ab: Iso<A, B>) => Prism<S, B>;
compose a
Prism
with aIso
1.0.0
method composeLens
composeLens: <B>(ab: Lens<A, B>) => Optional<S, B>;
compose a
Prism
with aLens
1.0.0
method composeOptional
composeOptional: <B>(ab: Optional<A, B>) => Optional<S, B>;
compose a
Prism
with aOptional
1.0.0
method composePrism
composePrism: <B>(ab: Prism<A, B>) => Prism<S, B>;
Alias of
compose
1.0.0
method composeSetter
composeSetter: <B>(ab: Setter<A, B>) => Setter<S, B>;
compose a
Prism
with aSetter
1.0.0
method composeTraversal
composeTraversal: <B>(ab: Traversal<A, B>) => Traversal<S, B>;
compose a
Prism
with aTraversal
1.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
Prism
with 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
Setter
with aSetter
1.0.0
method composeIso
composeIso: <B>(ab: Iso<A, B>) => Setter<S, B>;
compose a
Setter
with aIso
1.0.0
method composeLens
composeLens: <B>(ab: Lens<A, B>) => Setter<S, B>;
compose a
Setter
with aLens
1.0.0
method composeOptional
composeOptional: <B>(ab: Optional<A, B>) => Setter<S, B>;
compose a
Setter
with aOptional
1.0.0
method composePrism
composePrism: <B>(ab: Prism<A, B>) => Setter<S, B>;
compose a
Setter
with aPrism
1.0.0
method composeSetter
composeSetter: <B>(ab: Setter<A, B>) => Setter<S, B>;
Alias of
compose
1.0.0
method composeTraversal
composeTraversal: <B>(ab: Traversal<A, B>) => Setter<S, B>;
compose a
Setter
with aTraversal
1.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
Traversal
as aFold
1.0.0
method asSetter
asSetter: () => Setter<S, A>;
view a
Traversal
as aSetter
1.0.0
method compose
compose: <B>(ab: Traversal<A, B>) => Traversal<S, B>;
compose a
Traversal
with aTraversal
1.0.0
method composeFold
composeFold: <B>(ab: Fold<A, B>) => Fold<S, B>;
compose a
Traversal
with aFold
1.0.0
method composeGetter
composeGetter: <B>(ab: Getter<A, B>) => Fold<S, B>;
compose a
Traversal
with aGetter
1.0.0
method composeIso
composeIso: <B>(ab: Iso<A, B>) => Traversal<S, B>;
compose a
Traversal
with aIso
1.0.0
method composeLens
composeLens: <B>(ab: Lens<A, B>) => Traversal<S, B>;
compose a
Traversal
with aLens
1.0.0
method composeOptional
composeOptional: <B>(ab: Optional<A, B>) => Traversal<S, B>;
compose a
Traversal
with aOptional
1.0.0
method composePrism
composePrism: <B>(ab: Prism<A, B>) => Traversal<S, B>;
compose a
Traversal
with aPrism
1.0.0
method composeSetter
composeSetter: <B>(ab: Setter<A, B>) => Setter<S, B>;
compose a
Traversal
with aSetter
1.0.0
method composeTraversal
composeTraversal: <B>(ab: Traversal<A, B>) => Traversal<S, B>;
Alias of
compose
1.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
traversal
to 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
atReadonlyRecord
instead.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
At
using 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
Index
using 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
indexReadonlyArray
instead.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
indexReadonlyRecord
instead.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
Iso
is an optic which converts elements of typeS
into elements of typeA
without loss.Laws:
1.
reverseGet(get(s)) = s
2.get(reversetGet(a)) = a
2.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
Iso
as aLens
.converters 2.3.0
function asOptional
asOptional: <S, A>(sa: Iso<S, A>) => Optional<S, A>;
View an
Iso
as aOptional
.converters 2.3.0
function asPrism
asPrism: <S, A>(sa: Iso<S, A>) => Prism<S, A>;
View an
Iso
as aPrism
.converters 2.3.0
function asTraversal
asTraversal: <S, A>(sa: Iso<S, A>) => Traversal<S, A>;
View an
Iso
as 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
Lens
from aIso
focused 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
Lens
from aIso
focused 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
Iso
with 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
Iso
with aLens
.compositions 2.3.8
function composeOptional
composeOptional: <A, B>( ab: Optional<A, B>) => <S>(sa: Iso<S, A>) => Optional<S, B>;
Compose an
Iso
with aOptional
.compositions 2.3.8
function composePrism
composePrism: <A, B>(ab: Prism<A, B>) => <S>(sa: Iso<S, A>) => Prism<S, B>;
Compose an
Iso
with aPrism
.compositions 2.3.8
function composeTraversal
composeTraversal: <A, B>( ab: Traversal<A, B>) => <S>(sa: Iso<S, A>) => Traversal<S, B>;
Compose an
Iso
with 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
Prism
from aIso
focused 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
Optional
from aIso
focused 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
Optional
from aIso
focused 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
Optional
from aIso
focused 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
Prism
from aIso
focused on theLeft
of aEither
type.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
Lens
from aIso
and 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
Lens
from aIso
and 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
Prism
from aIso
focused on theRight
of aEither
type.combinators 2.3.8
function some
some: <S, A>(soa: Iso<S, Option<A>>) => Prism<S, A>;
Return a
Prism
from aIso
focused on theSome
of aOption
type.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
Traversal
from aIso
focused 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
Lens
is an optic used to zoom inside a product.Lens
es have two type parameters generally calledS
andA
:Lens<S, A>
whereS
represents the product andA
an element inside ofS
.Laws:
1.
get(set(a)(s)) = a
2.set(get(s))(s) = s
3.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
Lens
as aOptional
.converters 2.3.0
function asTraversal
asTraversal: <S, A>(sa: Lens<S, A>) => Traversal<S, A>;
View a
Lens
as aTraversal
.converters 2.3.0
function atKey
atKey: ( key: string) => <S, A>(sa: Lens<S, ReadonlyRecord<string, A>>) => Lens<S, Option<A>>;
Return a
Lens
from aLens
focused 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
Lens
from aLens
focused 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
Lens
with aLens
.compositions 2.3.0
function composeIso
composeIso: <A, B>(ab: Iso<A, B>) => <S>(sa: Lens<S, A>) => Lens<S, B>;
Compose a
Lens
with 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
Lens
with anOptional
.compositions 2.3.0
function composePrism
composePrism: <A, B>(ab: Prism<A, B>) => <S>(sa: Lens<S, A>) => Optional<S, B>;
Compose a
Lens
with aPrism
.compositions 2.3.0
function composeTraversal
composeTraversal: <A, B>( ab: Traversal<A, B>) => <S>(sa: Lens<S, A>) => Traversal<S, B>;
Compose a
Lens
with 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
Optional
from aLens
focused 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
Optional
from aLens
focused 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
Optional
from aLens
focused 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
Optional
from aLens
focused 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
Optional
from aLens
focused on theLeft
of aEither
type.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
Lens
from aLens
and 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
Lens
from aLens
and 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
Optional
from aLens
focused on theRight
of aEither
type.combinators 2.3.0
function some
some: <S, A>(soa: Lens<S, Option<A>>) => Optional<S, A>;
Return a
Optional
from aLens
focused on theSome
of aOption
type.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
Traversal
from aLens
focused 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
Optional
is an optic used to zoom inside a product. Unlike theLens
, the element that theOptional
focuses on may not exist.Optional
s have two type parameters generally calledS
andA
:Optional<S, A>
whereS
represents the product andA
an optional element inside ofS
.Laws:
1.
pipe(getOption(s), fold(() => s, a => set(a)(s))) = s
2.getOption(set(a)(s)) = pipe(getOption(s), map(_ => a))
3.set(a)(set(a)(s)) = set(a)(s)
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
Optional
as 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
Optional
from aOptional
focused 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
Optional
from aOptional
focused 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
Optional
with aOptional
.compositions 2.3.0
function composeIso
composeIso: <A, B>(ab: Iso<A, B>) => <S>(sa: Optional<S, A>) => Optional<S, B>;
Compose a
Optional
with aIso
.compositions 2.3.8
function composeLens
composeLens: <A, B>(ab: Lens<A, B>) => <S>(sa: Optional<S, A>) => Optional<S, B>;
Compose a
Optional
with 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
Optional
with aPrism
.compositions 2.3.7
function composeTraversal
composeTraversal: <A, B>( ab: Traversal<A, B>) => <S>(sa: Optional<S, A>) => Traversal<S, B>;
Compose a
Optional
with 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
Optional
from aOptional
focused 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
Optional
from aOptional
focused 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
Optional
from aOptional
focused 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
Optional
from aOptional
focused 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
Optional
from aOptional
focused on theLeft
of aEither
type.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
Optional
from aOptional
and 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
Optional
from aOptional
and 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
Optional
from aOptional
focused on theRight
of aEither
type.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
Optional
from aOptional
focused on theSome
of aOption
type.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
Traversal
from aOptional
focused 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
Prism
is an optic used to select part of a sum type.Laws:
1.
pipe(getOption(s), fold(() => s, reverseGet)) = s
2.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
Prism
as aOptional
.converters 2.3.0
function asTraversal
asTraversal: <S, A>(sa: Prism<S, A>) => Traversal<S, A>;
View a
Prism
as 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
Optional
from aPrism
focused 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
Optional
from aPrism
focused 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
Prism
with aPrism
.compositions 2.3.0
function composeIso
composeIso: <A, B>(ab: Iso<A, B>) => <S>(sa: Prism<S, A>) => Prism<S, B>;
Compose a
Prism
with aIso
.compositions 2.3.8
function composeLens
composeLens: <A, B>(ab: Lens<A, B>) => <S>(sa: Prism<S, A>) => Optional<S, B>;
Compose a
Prism
with aLens
.compositions 2.3.0
function composeOptional
composeOptional: <A, B>( ab: Optional<A, B>) => <S>(sa: Prism<S, A>) => Optional<S, B>;
Compose a
Prism
with 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
Prism
with 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
Prism
from aPrism
focused 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
Optional
from aPrism
focused 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
Optional
from aPrism
focused 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
Optional
from aPrism
focused 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
Prism
from aPrism
focused on theLeft
of aEither
type.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
Optional
from aPrism
and 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
Optional
from aPrism
and 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
Prism
from aPrism
focused on theRight
of aEither
type.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
Prism
from aPrism
focused on theSome
of aOption
type.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
Traversal
from aPrism
focused 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
Traversal
is the generalisation of anOptional
to several targets. In other word, aTraversal
allows to focus from a typeS
into0
ton
values of typeA
.The most common example of a
Traversal
would be to focus into all elements inside of a container (e.g.ReadonlyArray
,Option
). To do this we will use the relation between the typeclassTraversable
andTraversal
.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
Traversal
from 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
Traversal
from aTraversal
focused 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
Traversal
from aTraversal
focused 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
Traversal
with aTraversal
.compositions 2.3.0
function composeIso
composeIso: <A, B>(ab: Iso<A, B>) => <S>(sa: Traversal<S, A>) => Traversal<S, B>;
Compose a
Traversal
with aIso
.compositions 2.3.8
function composeLens
composeLens: <A, B>( ab: Lens<A, B>) => <S>(sa: Traversal<S, A>) => Traversal<S, B>;
Compose a
Traversal
with aLens
.compositions 2.3.8
function composeOptional
composeOptional: <A, B>( ab: Optional<A, B>) => <S>(sa: Traversal<S, A>) => Traversal<S, B>;
Compose a
Traversal
with aOptional
.compositions 2.3.8
function composePrism
composePrism: <A, B>( ab: Prism<A, B>) => <S>(sa: Traversal<S, A>) => Traversal<S, B>;
Compose a
Traversal
with 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
Monoid
and 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
Monoid
and combine the results.combinators 2.3.0
function fromNullable
fromNullable: <S, A>(sa: Traversal<S, A>) => Traversal<S, NonNullable<A>>;
Return a
Traversal
from aTraversal
focused 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
Traversal
from aTraversal
focused 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
Traversal
from aTraversal
focused 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
Traversal
from aTraversal
focused on theLeft
of aEither
type.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
Traversal
from aTraversal
and 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
Traversal
from aTraversal
and 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
Traversal
from aTraversal
focused on theRight
of aEither
type.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
Traversal
from aTraversal
focused on theSome
of aOption
type.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
Traversal
from aTraversal
focused 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[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](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.