Link Search Menu Expand Document

Iso overview

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 type S into elements of type A without loss.

Laws:

  1. reverseGet(get(s)) = s
  2. get(reversetGet(a)) = a

Added in v2.3.0


Table of contents


Invariant

imap

Signature

export declare const imap: <A, B>(f: (a: A) => B, g: (b: B) => A) => <S>(sa: Iso<S, A>) => Iso<S, B>

Added in v2.3.0

combinators

atKey

Return a Lens from a Iso focused on a required key of a ReadonlyRecord.

Signature

export declare const atKey: (key: string) => <S, A>(sa: Iso<S, Readonly<Record<string, A>>>) => Lens<S, Option<A>>

Added in v2.3.8

component

Return a Lens from a Iso focused on a component of a tuple.

Signature

export declare const component: <A extends readonly unknown[], P extends keyof A>(
  prop: P
) => <S>(sa: Iso<S, A>) => Lens<S, A[P]>

Added in v2.3.8

filter

Signature

export declare function filter<A, B extends A>(refinement: Refinement<A, B>): <S>(sa: Iso<S, A>) => Prism<S, B>
export declare function filter<A>(predicate: Predicate<A>): <S>(sa: Iso<S, A>) => Prism<S, A>

Added in v2.3.8

findFirst

Signature

export declare function findFirst<A, B extends A>(
  refinement: Refinement<A, B>
): <S>(sa: Iso<S, ReadonlyArray<A>>) => Optional<S, B>
export declare function findFirst<A>(predicate: Predicate<A>): <S>(sa: Iso<S, ReadonlyArray<A>>) => Optional<S, A>

Added in v2.3.8

findFirstNonEmpty

Signature

export declare function findFirstNonEmpty<A, B extends A>(
  refinement: Refinement<A, B>
): <S>(sa: Iso<S, ReadonlyNonEmptyArray<A>>) => Optional<S, B>
export declare function findFirstNonEmpty<A>(
  predicate: Predicate<A>
): <S>(sa: Iso<S, ReadonlyNonEmptyArray<A>>) => Optional<S, A>

Added in v2.3.8

fromNullable

Return a Prism from a Iso focused on a nullable value.

Signature

export declare const fromNullable: <S, A>(sa: Iso<S, A>) => Prism<S, NonNullable<A>>

Added in v2.3.8

index

Return a Optional from a Iso focused on an index of a ReadonlyArray.

Signature

export declare const index: (i: number) => <S, A>(sa: Iso<S, readonly A[]>) => Optional<S, A>

Added in v2.3.8

indexNonEmpty

Return a Optional from a Iso focused on an index of a ReadonlyNonEmptyArray.

Signature

export declare const indexNonEmpty: (i: number) => <S, A>(sa: Iso<S, ReadonlyNonEmptyArray<A>>) => Optional<S, A>

Added in v2.3.8

key

Return a Optional from a Iso focused on a key of a ReadonlyRecord.

Signature

export declare const key: (key: string) => <S, A>(sa: Iso<S, Readonly<Record<string, A>>>) => Optional<S, A>

Added in v2.3.8

left

Return a Prism from a Iso focused on the Left of a Either type.

Signature

export declare const left: <S, E, A>(sea: Iso<S, Either<E, A>>) => Prism<S, E>

Added in v2.3.8

modify

Signature

export declare const modify: <A>(f: (a: A) => A) => <S>(sa: Iso<S, A>) => (s: S) => S

Added in v2.3.0

modifyF

Signature

export declare function 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>
export declare function modifyF<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>
export declare function modifyF<F extends URIS>(
  F: Functor1<F>
): <A>(f: (a: A) => Kind<F, A>) => <S>(sa: Iso<S, A>) => (s: S) => Kind<F, S>
export declare function modifyF<F>(
  F: Functor<F>
): <A>(f: (a: A) => HKT<F, A>) => <S>(sa: Iso<S, A>) => (s: S) => HKT<F, S>

Added in v2.3.5

prop

Return a Lens from a Iso and a prop.

Signature

export declare const prop: <A, P extends keyof A>(prop: P) => <S>(sa: Iso<S, A>) => Lens<S, A[P]>

Added in v2.3.8

props

Return a Lens from a Iso and a list of props.

Signature

export declare const 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] }>

Added in v2.3.8

Return a Prism from a Iso focused on the Right of a Either type.

Signature

export declare const right: <S, E, A>(sea: Iso<S, Either<E, A>>) => Prism<S, A>

Added in v2.3.8

some

Return a Prism from a Iso focused on the Some of a Option type.

Signature

export declare const some: <S, A>(soa: Iso<S, Option<A>>) => Prism<S, A>

Added in v2.3.8

traverse

Return a Traversal from a Iso focused on a Traversable.

Signature

export declare function traverse<T extends URIS>(T: Traversable1<T>): <S, A>(sta: Iso<S, Kind<T, A>>) => Traversal<S, A>

Added in v2.3.8

compositions

compose

Compose an Iso with an Iso.

Signature

export declare const compose: <A, B>(ab: Iso<A, B>) => <S>(sa: Iso<S, A>) => Iso<S, B>

Added in v2.3.0

composeIso

Alias of compose.

Signature

export declare const composeIso: <A, B>(ab: Iso<A, B>) => <S>(sa: Iso<S, A>) => Iso<S, B>

Added in v2.3.8

composeLens

Compose an Iso with a Lens.

Signature

export declare const composeLens: <A, B>(ab: Lens<A, B>) => <S>(sa: Iso<S, A>) => Lens<S, B>

Added in v2.3.8

composeOptional

Compose an Iso with a Optional.

Signature

export declare const composeOptional: <A, B>(ab: Optional<A, B>) => <S>(sa: Iso<S, A>) => Optional<S, B>

Added in v2.3.8

composePrism

Compose an Iso with a Prism.

Signature

export declare const composePrism: <A, B>(ab: Prism<A, B>) => <S>(sa: Iso<S, A>) => Prism<S, B>

Added in v2.3.8

composeTraversal

Compose an Iso with a Traversal.

Signature

export declare const composeTraversal: <A, B>(ab: Traversal<A, B>) => <S>(sa: Iso<S, A>) => Traversal<S, B>

Added in v2.3.8

constructors

id

Signature

export declare const id: <S>() => Iso<S, S>

Added in v2.3.0

iso

Signature

export declare const iso: <S, A>(get: (s: S) => A, reverseGet: (a: A) => S) => Iso<S, A>

Added in v2.3.8

reverse

Signature

export declare const reverse: <S, A>(sa: Iso<S, A>) => Iso<A, S>

Added in v2.3.0

converters

asLens

View an Iso as a Lens.

Signature

export declare const asLens: <S, A>(sa: Iso<S, A>) => Lens<S, A>

Added in v2.3.0

asOptional

View an Iso as a Optional.

Signature

export declare const asOptional: <S, A>(sa: Iso<S, A>) => Optional<S, A>

Added in v2.3.0

asPrism

View an Iso as a Prism.

Signature

export declare const asPrism: <S, A>(sa: Iso<S, A>) => Prism<S, A>

Added in v2.3.0

asTraversal

View an Iso as a Traversal.

Signature

export declare const asTraversal: <S, A>(sa: Iso<S, A>) => Traversal<S, A>

Added in v2.3.0

instances

Category

Signature

export declare const Category: Category2<'monocle-ts/Iso'>

Added in v2.3.0

Invariant

Signature

export declare const Invariant: Invariant2<'monocle-ts/Iso'>

Added in v2.3.0

Semigroupoid

Signature

export declare const Semigroupoid: Semigroupoid2<'monocle-ts/Iso'>

Added in v2.3.8

URI

Signature

export declare const URI: 'monocle-ts/Iso'

Added in v2.3.0

URI (type alias)

Signature

export type URI = typeof URI

Added in v2.3.0

model

Iso (interface)

Signature

export interface Iso<S, A> {
  readonly get: (s: S) => A
  readonly reverseGet: (a: A) => S
}

Added in v2.3.0