Variable Option

Option: { fromUndefinable: (<T>(value: undefined | T) => Option<T>); fromNullable: (<T>(value: null | T) => Option<T>) }

The Option type. See the module level documentation for more.

In Rust

Type declaration

  • fromUndefinable: (<T>(value: undefined | T) => Option<T>)
      • <T>(value: undefined | T): Option<T>
      • Convert Option<T> to T | undefined value

        Example

        const x: string | undefined = 'foo';
        assert.deepEqual(Option.fromUndefinable(x), Some('foo'));

        const y: string | undefined = undefined;
        assert.deepEqual(Option.fromUndefinable(y), None);

        const z = 'bar';
        assert.deepEqual(Option.fromUndefinable(z), Some('bar'));

        This is not in Rust.

        Type Parameters

        • T

        Parameters

        • value: undefined | T

        Returns Option<T>

  • fromNullable: (<T>(value: null | T) => Option<T>)
      • <T>(value: null | T): Option<T>
      • Convert Option<T> to T | null value

        Example

        const x: string | null = 'foo';
        assert.deepEqual(Option.fromNullable(x), Some('foo'));

        const y: string | null = null;
        assert.deepEqual(Option.fromNullable(y), None);

        const z = 'bar';
        assert.deepEqual(Option.fromNullable(z), Some('bar'));

        This is not in Rust.

        Type Parameters

        • T

        Parameters

        • value: null | T

        Returns Option<T>

Generated using TypeDoc