Skip to main content

Class: None

Implements

Constructors

new None()

new None(): None

Returns

None

Methods

[iterator]()

[iterator](): Generator<never, any, unknown>

Returns an iterator over the possibly contained value.

The iterator yields one value if the result is Some, otherwise none.

Returns

Generator<never, any, unknown>

Implementation of

IOption . [iterator]

Examples

const x = some(7);
for (const value of x) {
console.log(value);
}
// Logs 7
const x = none;
for (const value of x) {
console.log(value);
}
// Doesn't log

See

Source

projects/utilities/packages/result/src/lib/Option/None.ts:164


and()

and(option: Option<any>): this

Returns None if the option is None, otherwise returns option.

Parameters

ParameterTypeDescription
optionOption<any>The option.

Returns

this

Implementation of

IOption . and

Examples

const x: Option<number> = some(2);
const y: Option<string> = none;
assert.equal(x.and(y), none);
const x: Option<number> = none;
const y: Option<string> = some('foo');
assert.equal(x.and(y), none);
const x: Option<number> = some(2);
const y: Option<string> = some('foo');
assert.equal(x.and(y), some('foo'));
const x: Option<number> = none;
const y: Option<string> = none;
assert.equal(x.and(y), none);

See

https://doc.rust-lang.org/std/option/enum.Option.html#method.and

Source

projects/utilities/packages/result/src/lib/Option/None.ts:85


andThen()

andThen(cb: (value: never) => Option<any>): this

Calls cb if the result is Ok, otherwise returns the Err value of self.

This function can be used for control flow based on Result values.

Parameters

ParameterTypeDescription
cb(value: never) => Option<any>The predicate.

Returns

this

Implementation of

IOption . andThen

Example

function fractionOf4(value: number) {
return value === 0 ? none : some(4 / value);
}

assert.equal(some(2).andThen(fractionOf4), some(4));
assert.equal(some(0).andThen(fractionOf4), none);
assert.equal(none.andThen(fractionOf4), none);

See

https://doc.rust-lang.org/std/result/enum.Result.html#method.and_then

Source

projects/utilities/packages/result/src/lib/Option/None.ts:90


contains()

contains(value?: any): false

Returns true if the option is a Some value containing the given value.

Parameters

ParameterTypeDescription
value?anyThe value to compare.

Returns

false

Implementation of

IOption . contains

Examples

const x: Option<number> = some(2);
assert.equal(x.contains(2), true);
const x: Option<number> = some(3);
assert.equal(x.contains(2), false);
const x: Option<number> = none;
assert.equal(x.contains(2), false);

See

https://doc.rust-lang.org/std/option/enum.Option.html#method.contains

Source

projects/utilities/packages/result/src/lib/Option/None.ts:115


eq()

eq(other)

eq(other: None): true

Checks whether or not other equals with self.

Parameters
ParameterTypeDescription
otherNoneThe other option to compare.
Returns

true

Implementation of

IOption . eq

See

https://doc.rust-lang.org/std/cmp/trait.PartialEq.html#tymethod.eq

Source

projects/utilities/packages/result/src/lib/Option/None.ts:146

eq(other)

eq(other: Some<any>): false

Parameters
ParameterType
otherSome<any>
Returns

false

Implementation of

IOption.eq

Source

projects/utilities/packages/result/src/lib/Option/None.ts:147

eq(other)

eq(other: Option<any>): boolean

Parameters
ParameterType
otherOption<any>
Returns

boolean

Implementation of

IOption.eq

Source

projects/utilities/packages/result/src/lib/Option/None.ts:148


expect()

expect(message: string): never

Returns the contained Some value.

Parameters

ParameterTypeDescription
messagestringThe message for the error. If the value is an Err, it throws an OptionError with the given message.

Returns

never

Implementation of

IOption . expect

Examples

const x: Option<string> = some(2);
assert.equal(x.expect('Whoops!'), 2);
const x: Option<string> = none;
assert.throws(() => x.expect('Whoops!'), {
name: 'OptionError',
message: 'Whoops'
});

See

https://doc.rust-lang.org/std/option/enum.Option.html#method.expect

Source

projects/utilities/packages/result/src/lib/Option/None.ts:23


filter()

filter(predicate: (value: never) => boolean): None

Returns None if the option is None, otherwise calls predicate with the wrapped value and returns:

  • Some(t) if predicate returns true (where t is the wrapped value), and
  • None if predicate returns false.

Parameters

ParameterTypeDescription
predicate(value: never) => booleanThe predicate.

Returns

None

Implementation of

IOption . filter

Example

function isEven(value: number) {
return n % 2 === 0;
}

assert.equal(none.filter(isEven), none);
assert.equal(some(3).filter(isEven), none);
assert.equal(some(4).filter(isEven), some(4));

See

https://doc.rust-lang.org/std/option/enum.Option.html#method.filter

Source

projects/utilities/packages/result/src/lib/Option/None.ts:110


flatten()

flatten(): None

Converts from Result<Result<T, E>, E> to Result<T, E>.

Returns

None

Implementation of

IOption . flatten

Examples

const x: Option<Option<number>> = some(some(6));
assert.equal(x.flatten(), some(6));
const x: Option<Option<number>> = some(none);
assert.equal(x.flatten(), none);
const x: Option<Option<number>> = none;
assert.equal(x.flatten(), none);

See

https://doc.rust-lang.org/std/result/enum.Result.html#method.flatten

Source

projects/utilities/packages/result/src/lib/Option/None.ts:138


inspect()

inspect(cb?: (value: never) => void): this

Calls the provided closure with a reference to the contained value (if Some).

Parameters

ParameterTypeDescription
cb?(value: never) => voidThe predicate.

Returns

this

Implementation of

IOption . inspect

Seealso

inspectAsync for the awaitable version.

Examples

some(2).inspect(console.log);
// Logs: 2
none.inspect(console.log);
// Doesn't log

See

https://doc.rust-lang.org/std/option/enum.Option.html#method.inspect

Source

projects/utilities/packages/result/src/lib/Option/None.ts:63


inspectAsync()

inspectAsync(cb?: (value: never) => unknown): Promise <None>

Calls the provided closure with a reference to the contained value (if Some).

Parameters

ParameterTypeDescription
cb?(value: never) => unknownThe predicate.

Returns

Promise <None>

Implementation of

IOption . inspectAsync

Seealso

inspect for the sync version.

Examples

await some(2).inspectAsync(console.log);
// Logs: 2
await none.inspectAsync(console.log);
// Doesn't log

Note

This is an extension not supported in Rust

Source

projects/utilities/packages/result/src/lib/Option/None.ts:68


intoPromise()

intoPromise(): Promise <None>

Returns a Promise object with the awaited value (if Some).

Returns

Promise <None>

Implementation of

IOption . intoPromise

Example

let x = some(Promise.resolve(3));
assert.equal(await x.intoPromise(), some(3));

Note

This is an extension not supported in Rust

Source

projects/utilities/packages/result/src/lib/Option/None.ts:142


isNone()

isNone(): this is None

Returns true if the option is a None value.

Returns

this is None

Implementation of

IOption . isNone

Examples

const x: Option<number> = some(2);
assert.equal(x.isNone(), false);
const x: Option<number> = none;
assert.equal(x.isNone(), true);

See

https://doc.rust-lang.org/std/option/enum.Option.html#method.is_none

Source

projects/utilities/packages/result/src/lib/Option/None.ts:19


isSome()

isSome(): false

Returns true if the option is a Some value.

Returns

false

Implementation of

IOption . isSome

Examples

const x: Option<number> = some(2);
assert.equal(x.isSome(), true);
const x: Option<number> = none;
assert.equal(x.isSome(), false);

See

https://doc.rust-lang.org/std/option/enum.Option.html#method.is_some

Source

projects/utilities/packages/result/src/lib/Option/None.ts:10


isSomeAnd()

isSomeAnd(cb?: (value: never) => boolean): false

Returns true if the option is a Some and the value inside of it matches a predicate.

Parameters

ParameterTypeDescription
cb?(value: never) => booleanThe predicate.

Returns

false

Implementation of

IOption . isSomeAnd

Examples

const x: Option<number> = some(2);
assert.equal(x.isSomeAnd((x) => x > 1), true);
const x: Option<number> = some(0);
assert.equal(x.isSomeAnd((x) => x > 1), false);
const x: Option<number> = none;
assert.equal(x.isSomeAnd((x) => x > 1), false);

See

https://doc.rust-lang.org/std/option/enum.Option.html#method.is_some_and

Source

projects/utilities/packages/result/src/lib/Option/None.ts:14


iter()

iter(): Generator<never, any, unknown>

Returns an iterator over the possibly contained value.

The iterator yields one value if the result is Some, otherwise none.

Returns

Generator<never, any, unknown>

Implementation of

IOption . iter

Examples

const x = some(7);
for (const value of x) {
console.log(value);
}
// Logs 7
const x = none;
for (const value of x) {
console.log(value);
}
// Doesn't log

See

Source

projects/utilities/packages/result/src/lib/Option/None.ts:81


map()

map(cb: (value: never) => any): this

Maps an Option<T> to Option<U> by applying a function to a contained value.

Parameters

ParameterTypeDescription
cb(value: never) => anyThe predicate.

Returns

this

Implementation of

IOption . map

Example

const maybeSomeString = some('Hello, world!');
const maybeSomeLength = maybeSomeString.map((value) => value.length);

assert.equal(maybeSomeLength, some(13));

See

https://doc.rust-lang.org/std/option/enum.Option.html#method.map

Source

projects/utilities/packages/result/src/lib/Option/None.ts:39


mapInto()

mapInto(cb: (value: never) => Option<any>): this

Maps a Some<T> to the returned Option<U> by applying a function to a contained value, leaving None untouched.

Parameters

ParameterTypeDescription
cb(value: never) => Option<any>The predicate.

Returns

this

Implementation of

IOption . mapInto

Examples

const input: Option<string> = some('Hello, world!');
const result = input.mapInto((value) => some(value.length));

assert.equal(result, some(13));
const input: Option<string> = none;
const result = input.mapInto((value) => some(value.length));

assert.equal(result, none);

Note

This is an extension not supported in Rust

Source

projects/utilities/packages/result/src/lib/Option/None.ts:44


mapNoneInto()

mapNoneInto<R>(cb: () => R): R

Maps a None to the returned Option<U> by applying a function to a contained value, leaving Some<T> untouched.

Type parameters

Type parameter
R extends Option<any>

Parameters

ParameterTypeDescription
cb() => RThe predicate.

Returns

R

Implementation of

IOption . mapNoneInto

Examples

const input: Option<string> = some('Hello, world!');
const result = input.mapNoneInto(() => some(13));

assert.equal(result, some('Hello, world!'));
const input: Option<string> = none;
const result = input.mapNoneInto(() => some(13));

assert.equal(result, some(13));

Note

This is an extension not supported in Rust

Source

projects/utilities/packages/result/src/lib/Option/None.ts:59


mapOr()

mapOr<R>(defaultValue: R, cb?: (value: never) => R): R

Returns the provided default result (if none), or applies a function to the contained value (if any).

Arguments passed to mapOr are eagerly evaluated; if you are passing the result of a function call, it is recommended to use mapOrElse, which is lazily evaluated.

Type parameters

Type parameter
R

Parameters

ParameterTypeDescription
defaultValueRThe default value.
cb?(value: never) => RThe predicate.

Returns

R

Implementation of

IOption . mapOr

Examples

const x: Option<string> = some('hello');
assert.equal(x.mapOr(42, (value) => value.length), 5);
const x: Option<string> = none;
assert.equal(x.mapOr(42, (value) => value.length), 42);

See

https://doc.rust-lang.org/std/option/enum.Option.html#method.map_or

Source

projects/utilities/packages/result/src/lib/Option/None.ts:49


mapOrElse()

mapOrElse<R>(defaultValue: () => R, cb?: (value: never) => R): R

Computes a default function result (if none), or applies a different function to the contained value (if any).

Type parameters

Type parameter
R

Parameters

ParameterTypeDescription
defaultValue() => RThe default value.
cb?(value: never) => RThe predicate.

Returns

R

Implementation of

IOption . mapOrElse

Examples

const x: Option<string> = some('hello');
assert.equal(x.mapOrElse(() => 42, (value) => value.length), 5);
const x: Option<string> = none;
assert.equal(x.mapOrElse(() => 42, (value) => value.length), 42);

See

https://doc.rust-lang.org/std/option/enum.Option.html#method.map_or_else

Source

projects/utilities/packages/result/src/lib/Option/None.ts:54


match()

match<SomeValue, NoneValue>(branches: object): NoneValue

Runs ok function if self is Ok, otherwise runs err function.

Type parameters

Type parameter
SomeValue
NoneValue

Parameters

ParameterTypeDescription
branchesobjectThe branches to match.
branches.none-
branches.some-

Returns

NoneValue

Implementation of

IOption . match

Examples

const option = some(4).match({
some: (v) => v,
none: () => 0
});
assert.equal(option, 4);
const option = none.match({
some: (v) => v,
none: () => 0
});
assert.equal(option, 0);

Source

projects/utilities/packages/result/src/lib/Option/None.ts:160


ne()

ne(other)

ne(other: None): false

Checks whether or not other doesn't equal with self.

Parameters
ParameterTypeDescription
otherNoneThe other option to compare.
Returns

false

Implementation of

IOption . ne

See

https://doc.rust-lang.org/std/cmp/trait.PartialEq.html#method.ne

Source

projects/utilities/packages/result/src/lib/Option/None.ts:153

ne(other)

ne(other: Some<any>): true

Parameters
ParameterType
otherSome<any>
Returns

true

Implementation of

IOption.ne

Source

projects/utilities/packages/result/src/lib/Option/None.ts:154

ne(other)

ne(other: Option<any>): boolean

Parameters
ParameterType
otherOption<any>
Returns

boolean

Implementation of

IOption.ne

Source

projects/utilities/packages/result/src/lib/Option/None.ts:155


okOr()

okOr<E>(error: E): Err<E>

Transforms the Option<T> into a Result<T, E>, mapping Some(v) to Ok(v) and None to Err(err).

Arguments passed to okOr are eagerly evaluated; if you are passing the result of a function call, it is recommended to use okOrElse, which is lazily evaluated.

Type parameters

Type parameter
E

Parameters

ParameterTypeDescription
errorEThe error to be used.

Returns

Err<E>

Implementation of

IOption . okOr

Examples

const x: Option<string> = some('hello');
assert.equal(x.okOr(0), ok('hello'));
const x: Option<string> = none;
assert.equal(x.okOr(0), err(0));

See

https://doc.rust-lang.org/std/option/enum.Option.html#method.ok_or

Source

projects/utilities/packages/result/src/lib/Option/None.ts:73


okOrElse()

okOrElse<E>(cb: () => E): Err<E>

Transforms the Option<T> into a Result<T, E>, mapping Some(v) to Ok(v) and None to Err(err()).

Type parameters

Type parameter
E

Parameters

ParameterTypeDescription
cb() => EThe error to be used.

Returns

Err<E>

Implementation of

IOption . okOrElse

Examples

const x: Option<string> = some('hello');
assert.equal(x.okOrElse(() => 0), ok('hello'));
const x: Option<string> = none;
assert.equal(x.okOrElse(() => 0), err(0));

See

https://doc.rust-lang.org/std/option/enum.Option.html#method.ok_or_else

Source

projects/utilities/packages/result/src/lib/Option/None.ts:77


or()

or<R>(option: R): R

Returns the option if it contains a value, otherwise returns option.

Type parameters

Type parameter
R extends Option<any>

Parameters

ParameterTypeDescription
optionRThe option.

Returns

R

Implementation of

IOption . or

Examples

const x: Option<number> = some(2);
const y: Option<number> = none;
assert.equal(x.or(y), some(2));
const x: Option<number> = none;
const y: Option<number> = some(100);
assert.equal(x.or(y), some(100));
const x: Option<number> = some(2);
const y: Option<number> = some(100);
assert.equal(x.or(y), some(2));
const x: Option<number> = none;
const y: Option<number> = none;
assert.equal(x.or(y), none);

See

https://doc.rust-lang.org/std/option/enum.Option.html#method.or

Source

projects/utilities/packages/result/src/lib/Option/None.ts:95


orElse()

orElse<R>(cb: () => R): R

Calls cb if the result is Ok, otherwise returns the Err value of self.

This function can be used for control flow based on Result values.

Type parameters

Type parameter
R extends Option<any>

Parameters

ParameterTypeDescription
cb() => RThe predicate.

Returns

R

Implementation of

IOption . orElse

Example

const nobody = (): Option<string> => none;
const vikings = (): Option<string> => some('vikings');

assert.equal(some('barbarians').orElse(vikings), some('barbarians'));
assert.equal(none.orElse(vikings), some('vikings'));
assert.equal(none.orElse(nobody), none);

See

https://doc.rust-lang.org/std/option/enum.Option.html#method.or_else

Source

projects/utilities/packages/result/src/lib/Option/None.ts:99


transpose()

transpose(): Ok <None>

Transposes an Option of a Result into a Result of an Option.

none will be mapped to ok(none). some(ok(v)) and some(err(e)) will be mapped to ok(some(v)) and err(e).

Returns

Ok <None>

Implementation of

IOption . transpose

Example

const x: Option<Result<number, Error>> = some(ok(5));
const y: Result<Option<number>, Error> = ok(some(5));
assert.equal(x.transpose(), y);

See

https://doc.rust-lang.org/std/option/enum.Option.html#method.transpose

Source

projects/utilities/packages/result/src/lib/Option/None.ts:134


unwrap()

unwrap(): never

Returns the contained Some value.

If the value is an Err, it throws an OptionError with the message.

Returns

never

Implementation of

IOption . unwrap

Seealso

unwrapOr

Seealso

unwrapOrElse

Examples

const x: Option<string> = some(2);
assert.equal(x.unwrap(), 2);
const x: Option<string> = none;
assert.throws(() => x.unwrap(), {
name: 'OptionError',
message: 'Unwrap failed'
});

See

https://doc.rust-lang.org/std/option/enum.Option.html#method.unwrap

Source

projects/utilities/packages/result/src/lib/Option/None.ts:27


unwrapOr()

unwrapOr<R>(defaultValue: R): R

Returns the contained Some value or a provided default.

Arguments passed to unwrapOr are eagerly evaluated; if you are passing the result of a function call, it is recommended to use unwrapOrElse, which is lazily evaluated.

Type parameters

Type parameter
R

Parameters

ParameterType
defaultValueR

Returns

R

Implementation of

IOption . unwrapOr

Examples

assert.equal(some(2).unwrapOr(0), 2);
assert.equal(none.unwrapOr(0), 0);

See

https://doc.rust-lang.org/std/option/enum.Option.html#method.unwrap_or

Source

projects/utilities/packages/result/src/lib/Option/None.ts:31


unwrapOrElse()

unwrapOrElse<R>(cb: () => R): R

Returns the contained Some value or computes it from a closure.

Type parameters

Type parameter
R

Parameters

ParameterType
cb() => R

Returns

R

Implementation of

IOption . unwrapOrElse

Examples

assert.equal(some(2).unwrapOrElse(() => 0), 2);
assert.equal(none.unwrapOrElse(() => 0), 0);

See

https://doc.rust-lang.org/std/option/enum.Option.html#method.unwrap_or_else

Source

projects/utilities/packages/result/src/lib/Option/None.ts:35


unzip()

unzip(): [None, None]

Unzips an option containing a tuple of two options.

If self is Some((a, b)) this method returns [Some(a), Some(b)]. Otherwise, [None, None] is returned.

Returns

[None, None]

Implementation of

IOption . unzip

Examples

const x: Option<[number, string]> = some([1, 'hi']);
assert.equal(x.unzip(), [some(1), some('hi')]);
const x: Option<[number, string]> = none;
assert.equal(x.unzip(), [none, none]);

See

https://doc.rust-lang.org/std/option/enum.Option.html#method.unzip

Source

projects/utilities/packages/result/src/lib/Option/None.ts:130


xor()

xor(option)

xor<T>(option: None): None

Returns Some if exactly one of self or option is Some, otherwise returns None.

Type parameters
Type parameter
T
Parameters
ParameterTypeDescription
optionNoneThe option to compare.
Returns

None

Implementation of

IOption . xor

Examples
const x: Option<number> = some(2);
const y: Option<number> = none;
assert.equal(x.xor(y), some(2));
const x: Option<number> = none;
const y: Option<number> = some(2);
assert.equal(x.xor(y), some(2));
const x: Option<number> = some(2);
const y: Option<number> = some(2);
assert.equal(x.xor(y), none);
const x: Option<number> = none;
const y: Option<number> = none;
assert.equal(x.xor(y), none);
See

https://doc.rust-lang.org/std/option/enum.Option.html#method.xor

Source

projects/utilities/packages/result/src/lib/Option/None.ts:103

xor(option)

xor<T>(option: Some<T>): Some<T>

Type parameters
Type parameter
T
Parameters
ParameterType
optionSome<T>
Returns

Some<T>

Implementation of

IOption.xor

Source

projects/utilities/packages/result/src/lib/Option/None.ts:104

xor(option)

xor<T>(option: Option<T>): None | Some<T>

Type parameters
Type parameter
T
Parameters
ParameterType
optionOption<T>
Returns

None | Some<T>

Implementation of

IOption.xor

Source

projects/utilities/packages/result/src/lib/Option/None.ts:105


zip()

zip(other: Option<any>): None

Zips self with another Option.

If self is Some(s) and other is Some(o), this method returns Some([s, o]). Otherwise, None is returned.

Parameters

ParameterTypeDescription
otherOption<any>The option to zip self with.

Returns

None

Implementation of

IOption . zip

Example

const x = some(1);
const y = some('hi');
const z = none;

assert.equal(x.zip(y), some([1, 'hi']));
assert.equal(x.zip(z), none);

See

https://doc.rust-lang.org/std/option/enum.Option.html#method.zip

Source

projects/utilities/packages/result/src/lib/Option/None.ts:120


zipWith()

zipWith(other: Option<any>, f: (s: never, o: never) => any): None

Zips self and another Option with function f.

If self is Some(s) and other is Some(o), this method returns Some(f(s, o)). Otherwise, None is returned.

Parameters

ParameterTypeDescription
otherOption<any>The option to zip self with.
f(s: never, o: never) => anyThe function that computes the returned value.

Returns

None

Implementation of

IOption . zipWith

Example

class Point {
public readonly x: number;
public readonly y: number;

public constructor(x: number, y: number) {
this.x = x;
this.y = y;
}
}

const x = some(17.5);
const y = some(42.7);

assert.equal(x.zipWith(y, (s, o) => new Point(s, o)), some(new Point(17.5, 42.7)));
assert.equal(x.zipWith(none, (s, o) => new Point(s, o)), none);

See

https://doc.rust-lang.org/std/option/enum.Option.html#method.zip_with

Source

projects/utilities/packages/result/src/lib/Option/None.ts:125