Options
All
  • Public
  • Public/Protected
  • All
Menu

Class None<A>

Class None<A> represents non-existent values of type A.

const s: None<any> = new None<any>()
const t: None<any> = Option.none
const u: None<any> = Option(null)
const v: None<any> = Option(undefined)
const w: None<any> = Option.some(null)
const x: None<any> = Option.some(undefined)
const y: None<any> = Option.apply(null)
const z: None<any> = Option.apply(undefined)

Type parameters

  • A

Hierarchy

  • None

Implements

Index

Properties

exists

exists: has = this.has

isDefined

isDefined: boolean = this.isSome

isSome is a convenience shortcut to isSome

isEmpty

isEmpty: boolean = this.isNone

isEmpty is a convenience shortcut to isNone

isNone

isNone: boolean = true

Returns true if the option is None, false otherwise.

isSome

isSome: boolean = false

Returns true if the option is an instance of Some, false otherwise.

Readonly type

type: string = "None"

Methods

ap

filter

  • filter(p: (a: A) => boolean): Option<A>
  • Parameters

    • p: (a: A) => boolean
        • (a: A): boolean
        • Parameters

          • a: A

          Returns boolean

    Returns Option<A>

flatMap

  • Returns the result of applying $f to this Option's value if this Option is nonempty. Returns None if this Option is empty. Slightly different from map in that $f is expected to return an Option (which could be None).

    const f = (x:number) => Option(undefined);
    const o = Option<number>(5)
    const result = o.flatMap(f).getOrElse(-1) // -1
    see

    map

    see

    forEach

    Type parameters

    • B

    Parameters

    • f: (a: A) => Option<B>

      the function to apply

    Returns Option<B>

    Returns None in all cases

flatten

forEach

  • forEach(fn: (a: A) => any): void
  • Parameters

    • fn: (a: A) => any
        • (a: A): any
        • Parameters

          • a: A

          Returns any

    Returns void

get

  • get(): A

getOrElse

  • getOrElse(x: A): A

has

  • has(p: (a: A) => boolean): boolean
  • Parameters

    • p: (a: A) => boolean
        • (a: A): boolean
        • Parameters

          • a: A

          Returns boolean

    Returns boolean

map

  • map<B>(f: (a: A) => B): Option<B>
  • Returns a Some containing the result of applying $f to this $option's value if this $option is nonempty. Otherwise return $none.

     const f = (x:number): number => x * 2;
     const o = Option<number>(5)
     const result = o.map(f).getOrElse(-1) // 10
    note

    This is similar to flatMap except here, $f does not need to wrap its result in an $option.

    see

    flatMap

    see

    forEach

    Type parameters

    • B

    Parameters

    • f: (a: A) => B
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    Returns Option<B>

orElse

toList

  • toList(): A[]

Generated using TypeDoc