Skip to main content Link Search Menu Expand Document (external link)

Optional overview

Zoom into an object.

Added in v1.0.0


Table of contents


array

append

Signature

export declare const append: {
  <Self, A>(lens: Optional<Self, ReadonlyArray<A>> | Optional<Self, Array<A>>, self: Self, last: A): Self
  <Self, A>(
    lens: Optional<Self, ReadonlyArray<A>> | Optional<Self, Array<A>>
  ): { (self: Self, last: A): Self; (last: A): (self: Self) => Self }
}

Added in v1.0.0

appendAll

Signature

export declare const appendAll: {
  <Self, A>(lens: Optional<Self, ReadonlyArray<A>> | Optional<Self, Array<A>>, self: Self, that: ReadonlyArray<A>): Self
  <Self, A>(
    lens: Optional<Self, ReadonlyArray<A>> | Optional<Self, Array<A>>
  ): { (self: Self, that: ReadonlyArray<A>): Self; (that: ReadonlyArray<A>): (self: Self) => Self }
}

Added in v1.0.0

headNonEmpty

Signature

export declare const headNonEmpty: <Self, A>(
  lens: Optional<Self, Array.NonEmptyReadonlyArray<A>> | Optional<Self, Array.NonEmptyArray<A>>
) => Optional<Self, A>

Added in v1.0.0

combinators

filter

Signature

export declare const filter: {
  <A, B extends A, Self>(lens: Optional<Self, A>, refinement: Predicate.Refinement<A, B>): Optional<Self, B>
  <A, B extends A>(refinement: Predicate.Refinement<A, B>): <Self>(lens: Optional<Self, A>) => Optional<Self, B>
  <A, Self>(lens: Optional<Self, A>, predicate: Predicate.Predicate<A>): Optional<Self, A>
  <A>(predicate: Predicate.Predicate<A>): <Self>(lens: Optional<Self, A>) => Optional<Self, A>
}

Added in v1.0.0

composition

compose

Signature

export declare const compose: {
  <B, C>(that: Optional<B, C>): <A>(self: Optional<A, B>) => Optional<A, C>
  <A, B, C>(self: Optional<A, B>, that: Optional<B, C>): Optional<A, C>
}

Added in v1.0.0

composeLens

Signature

export declare const composeLens: {
  <B, C>(that: Lens.Lens<B, C>): <A>(self: Optional<A, B>) => Optional<A, C>
  <A, B, C>(self: Optional<A, B>, that: Lens.Lens<B, C>): Optional<A, C>
}

Added in v1.0.0

constructors

id

Signature

export declare const id: <Self>() => Optional<Self, Self>

Added in v1.0.0

make

Signature

export declare const make: <Self, Value>(
  get: (self: Self) => Option.Option<Value>,
  set: (self: Self, value: Value) => Self
) => Optional<Self, Value>

Added in v1.0.0

models

Optional (interface)

Signature

export interface Optional<Self, Value> extends Optional.Variance<Self, Value>, Pipeable.Pipeable {
  readonly getOption: (self: Self) => Option.Option<Value>
  readonly set: {
    (self: Self, value: Value): Self
    (value: Value): (self: Self) => Self
  }
}

Added in v1.0.0

Optional (namespace)

Added in v1.0.0

Variance (interface)

Signature

export interface Variance<Self, Value> {
  readonly [TypeId]: {
    readonly _Self: Types.Invariant<Self>
    readonly _Value: Types.Invariant<Value>
  }
}

Added in v1.0.0

Any (type alias)

Signature

export type Any = Optional<any, any>

Added in v1.0.0

option

some

Signature

export declare const some: <A, B>(optional: Optional<A, Option.Option<B>>) => Optional<A, B>

Added in v1.0.0

struct

extract

Signature

export declare const extract: {
  <Self, Value, const Tag extends keyof Value, const TagValues extends readonly [Value[Tag], ...Array<Value[Tag]>]>(
    lens: Optional<Self, Value>,
    tag: Tag,
    ...tagValues: TagValues
  ): Optional<Self, Extract<Value, { [K in Tag]: TagValues[number] }>>
  <Value, const Tag extends keyof Value, const TagValues extends readonly [Value[Tag], ...Array<Value[Tag]>]>(
    tag: Tag,
    ...tagValues: TagValues
  ): <Self>(lens: Optional<Self, Value>) => Optional<Self, Extract<Value, { [K in Tag]: TagValues[number] }>>
}

Added in v1.0.0

prop

Signature

export declare const prop: {
  <Value, A extends keyof Value>(prop: A): <Self>(lens: Optional<Self, Value>) => Optional<Self, Value[A]>
  <Value, A extends keyof Value, B extends keyof Value[A]>(
    a: A,
    b: B
  ): <Self>(lens: Optional<Self, Value>) => Optional<Self, Value[A][B]>
  <Value, A extends keyof Value, B extends keyof Value[A], C extends keyof Value[A][B]>(
    a: A,
    b: B,
    c: C
  ): <Self>(lens: Optional<Self, Value>) => Optional<Self, Value[A][B][C]>
  <Value, A extends keyof Value, B extends keyof Value[A], C extends keyof Value[A][B], D extends keyof Value[A][B][C]>(
    a: A,
    b: B,
    c: C,
    d: D
  ): <Self>(lens: Optional<Self, Value>) => Optional<Self, Value[A][B][C][D]>
  <
    Value,
    A extends keyof Value,
    B extends keyof Value[A],
    C extends keyof Value[A][B],
    D extends keyof Value[A][B][C],
    E extends keyof Value[A][B][C][D]
  >(
    a: A,
    b: B,
    c: C,
    d: D,
    e: E
  ): <Self>(lens: Optional<Self, Value>) => Optional<Self, Value[A][B][C][D][E]>
  <Self, Value, A extends keyof Value>(lens: Optional<Self, Value>, a: A): Optional<Self, Value[A]>
  <Self, Value, A extends keyof Value, B extends keyof Value[A]>(
    lens: Optional<Self, Value>,
    a: A,
    b: B
  ): Optional<Self, Value[A][B]>
  <Self, Value, A extends keyof Value, B extends keyof Value[A], C extends keyof Value[A][B]>(
    lens: Optional<Self, Value>,
    a: A,
    b: B,
    c: C
  ): Optional<Self, Value[A][B][C]>
  <
    Self,
    Value,
    A extends keyof Value,
    B extends keyof Value[A],
    C extends keyof Value[A][B],
    D extends keyof Value[A][B][C]
  >(
    lens: Optional<Self, Value>,
    a: A,
    b: B,
    c: C,
    d: D
  ): Optional<Self, Value[A][B][C][D]>
  <
    Self,
    Value,
    A extends keyof Value,
    B extends keyof Value[A],
    C extends keyof Value[A][B],
    D extends keyof Value[A][B][C],
    E extends keyof Value[A][B][C][D]
  >(
    lens: Optional<Self, Value>,
    a: A,
    b: B,
    c: C,
    d: D,
    e: E
  ): Optional<Self, Value[A][B][C][D][E]>
}

Added in v1.0.0

type id

TypeId

Signature

export declare const TypeId: typeof TypeId

Added in v1.0.0

TypeId (type alias)

Signature

export type TypeId = typeof TypeId

Added in v1.0.0