Hyperlinkv0.8.0-beta.28

Optic

Optic.nonefunctioneffect/Optic.ts:1594
<A>(): Prism<Option.Option<A>, undefined>

Prism that focuses on Option.None, exposing undefined.

When to use

Use when you want to match or construct None values within an optic chain.

Details

  • getResult succeeds with undefined when the option is None.
  • getResult fails when the option is Some.
  • set(undefined) produces Option.none().

Example (Matching None)

import { Optic, Option, Result } from "effect"

const _none = Optic.id<Option.Option<number>>().compose(Optic.none())

console.log(Result.isSuccess(_none.getResult(Option.none())))
// Output: true

console.log(Result.isFailure(_none.getResult(Option.some(1))))
// Output: true
Source effect/Optic.ts:159411 lines
export function none<A>(): Prism<Option.Option<A>, undefined> {
  const run = runRefinement(Option.isNone, { expected: "a None value" })
  return makePrism(
    (s) =>
      Result.mapBoth(run(s), {
        onFailure: String,
        onSuccess: () => undefined
      }),
    () => Option.none()
  )
}