Skip to main content

Class: Some<T>

Type Parameters

Type Parameter
T

Implements

Constructors

new Some()

new Some<T>(value: T): Some<T>

Parameters

ParameterType
valueT

Returns

Some<T>

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:12

Methods

[iterator]()

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

Returns an iterator over the possibly contained value.

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

Returns

Generator<T, any, unknown>

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

Implementation of

IOption.[iterator]

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:181


and()

and<R>(option: R): R

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

Type Parameters

Type Parameter
R extends Option<any>

Parameters

ParameterTypeDescription
optionRThe option.

Returns

R

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

Implementation of

IOption.and

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:92


andThen()

andThen<R>(cb: (value: T) => 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(value: T) => RThe predicate.

Returns

R

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

Implementation of

IOption.andThen

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:96


contains()

contains(value: T): boolean

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

Parameters

ParameterTypeDescription
valueTThe value to compare.

Returns

boolean

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

Implementation of

IOption.contains

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:124


eq()

eq(other)

eq(other: None): false

Checks whether or not other equals with self.

Parameters
ParameterTypeDescription
otherNoneThe other option to compare.
Returns

false

See

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

Implementation of

IOption.eq

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:165

eq(other)

eq(other: Option<T>): boolean

Checks whether or not other equals with self.

Parameters
ParameterTypeDescription
otherOption<T>The other option to compare.
Returns

boolean

See

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

Implementation of

IOption.eq

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:166


expect()

expect(message: string): T

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

T

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

Implementation of

IOption.expect

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:28


filter()

filter(predicate)

filter(predicate: (value: T) => true): this

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: T) => trueThe predicate.
Returns

this

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

Implementation of

IOption.filter

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:117

filter(predicate)

filter(predicate: (value: T) => false): 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: T) => falseThe predicate.
Returns

None

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

Implementation of

IOption.filter

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:118

filter(predicate)

filter(predicate: (value: T) => boolean): Some<T> | 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: T) => booleanThe predicate.
Returns

Some<T> | None

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

Implementation of

IOption.filter

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:119


flatten()

flatten<Inner>(this: Some<Inner>): Inner

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

Type Parameters

Type Parameter
Inner extends Option<any>

Parameters

ParameterType
thisSome<Inner>

Returns

Inner

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

Implementation of

IOption.flatten

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:157


inspect()

inspect(cb: (value: T) => void): this

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

Parameters

ParameterTypeDescription
cb(value: T) => voidThe predicate.

Returns

this

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

Implementation of

IOption.inspect

Defined in

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


inspectAsync()

inspectAsync(cb: (value: T) => unknown): Promise<Some<T>>

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

Parameters

ParameterTypeDescription
cb(value: T) => unknownThe predicate.

Returns

Promise<Some<T>>

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

Implementation of

IOption.inspectAsync

Defined in

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


intoPromise()

intoPromise(): Promise<Some<Awaited<T>>>

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

Returns

Promise<Some<Awaited<T>>>

Example

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

Note

This is an extension not supported in Rust

Implementation of

IOption.intoPromise

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:161


isNone()

isNone(): false

Returns true if the option is a None value.

Returns

false

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

Implementation of

IOption.isNone

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:24


isSome()

isSome(): this is Some<T>

Returns true if the option is a Some value.

Returns

this is Some<T>

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

Implementation of

IOption.isSome

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:16


isSomeAnd()

isSomeAnd<R>(cb: (value: T) => R): R

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

Type Parameters

Type Parameter
R extends boolean

Parameters

ParameterTypeDescription
cb(value: T) => RThe predicate.

Returns

R

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

Implementation of

IOption.isSomeAnd

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:20


iter()

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

Returns an iterator over the possibly contained value.

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

Returns

Generator<T, any, unknown>

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

Implementation of

IOption.iter

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:88


map()

map<U>(cb: (value: T) => U): Some<U>

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

Type Parameters

Type Parameter
U

Parameters

ParameterTypeDescription
cb(value: T) => UThe predicate.

Returns

Some<U>

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

Implementation of

IOption.map

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:47


mapInto()

mapInto<R>(cb: (value: T) => R): R

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

Type Parameters

Type Parameter
R extends Option<any>

Parameters

ParameterTypeDescription
cb(value: T) => RThe predicate.

Returns

R

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

Implementation of

IOption.mapInto

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:51


mapNoneInto()

mapNoneInto(cb: () => Option<any>): this

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

Parameters

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

Returns

this

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

Implementation of

IOption.mapNoneInto

Defined in

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


mapOr()

mapOr<U>(_: U, cb: (value: T) => U): U

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
U

Parameters

ParameterTypeDescription
_U-
cb(value: T) => UThe predicate.

Returns

U

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

Implementation of

IOption.mapOr

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:55


mapOrElse()

mapOrElse<U>(_: () => U, cb: (value: T) => U): U

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

Type Parameters

Type Parameter
U

Parameters

ParameterTypeDescription
_() => U-
cb(value: T) => UThe predicate.

Returns

U

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

Implementation of

IOption.mapOrElse

Defined in

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


match()

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

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

SomeValue

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);

Implementation of

IOption.match

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:177


ne()

ne(other)

ne(other: None): true

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

Parameters
ParameterTypeDescription
otherNoneThe other option to compare.
Returns

true

See

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

Implementation of

IOption.ne

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:171

ne(other)

ne(other: Option<T>): boolean

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

Parameters
ParameterTypeDescription
otherOption<T>The other option to compare.
Returns

boolean

See

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

Implementation of

IOption.ne

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:172


okOr()

okOr(err?: any): Ok<T>

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.

Parameters

ParameterTypeDescription
err?anyThe error to be used.

Returns

Ok<T>

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

Implementation of

IOption.okOr

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:78


okOrElse()

okOrElse(cb: () => any): Ok<T>

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

Parameters

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

Returns

Ok<T>

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

Implementation of

IOption.okOrElse

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:83


or()

or(option: Option<any>): this

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

Parameters

ParameterTypeDescription
optionOption<any>The option.

Returns

this

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

Implementation of

IOption.or

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:100


orElse()

orElse(cb?: () => 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?() => Option<any>The predicate.

Returns

this

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

Implementation of

IOption.orElse

Defined in

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


transpose()

transpose(this)

transpose<Inner>(this: Some<Ok<Inner>>): Ok<Some<Inner>>

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).

Type Parameters
Type Parameter
Inner
Parameters
ParameterType
thisSome<Ok<Inner>>
Returns

Ok<Some<Inner>>

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

Implementation of

IOption.transpose

Defined in

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

transpose(this)

transpose<Inner>(this: Some<Err<Inner>>): Err<Some<Inner>>

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).

Type Parameters
Type Parameter
Inner
Parameters
ParameterType
thisSome<Err<Inner>>
Returns

Err<Some<Inner>>

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

Implementation of

IOption.transpose

Defined in

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

transpose(this)

transpose<IT, E>(this: Some<Result<IT, E>>): Result<Some<IT>, E>

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).

Type Parameters
Type Parameter
IT
E
Parameters
ParameterType
thisSome<Result<IT, E>>
Returns

Result<Some<IT>, E>

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

Implementation of

IOption.transpose

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:149


unwrap()

unwrap(): T

Returns the contained Some value.

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

Returns

T

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

Implementation of

IOption.unwrap

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:33


unwrapOr()

unwrapOr(defaultValue: unknown): T

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.

Parameters

ParameterType
defaultValueunknown

Returns

T

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

Implementation of

IOption.unwrapOr

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:37


unwrapOrElse()

unwrapOrElse(cb: () => unknown): T

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

Parameters

ParameterType
cb() => unknown

Returns

T

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

Implementation of

IOption.unwrapOrElse

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:42


unzip()

unzip<I, U>(this: Some<readonly [I, U]>): [Some<I>, Some<U>]

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.

Type Parameters

Type Parameter
I
U

Parameters

ParameterType
thisSome<readonly [I, U]>

Returns

[Some<I>, Some<U>]

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

Implementation of

IOption.unzip

Defined in

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


xor()

xor(option)

xor(option: Some<T>): None

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

Parameters
ParameterTypeDescription
optionSome<T>The option to compare.
Returns

None

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

Implementation of

IOption.xor

Defined in

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

xor(option)

xor(option: None): this

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

Parameters
ParameterTypeDescription
optionNoneThe option to compare.
Returns

this

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

Implementation of

IOption.xor

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:111

xor(option)

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

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

Parameters
ParameterTypeDescription
optionOption<T>The option to compare.
Returns

Some<T> | None

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

Implementation of

IOption.xor

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:112


zip()

zip(other)

zip(other: None): 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
otherNoneThe option to zip self with.
Returns

None

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

Implementation of

IOption.zip

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:128

zip(other)

zip<U>(other: Some<U>): Some<[T, U]>

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.

Type Parameters
Type Parameter
U
Parameters
ParameterTypeDescription
otherSome<U>The option to zip self with.
Returns

Some<[T, U]>

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

Implementation of

IOption.zip

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:129

zip(other)

zip<U>(other: Option<U>): Option<[T, U]>

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.

Type Parameters
Type Parameter
U
Parameters
ParameterTypeDescription
otherOption<U>The option to zip self with.
Returns

Option<[T, U]>

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

Implementation of

IOption.zip

Defined in

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


zipWith()

zipWith(other, f)

zipWith<U, R>(other: None, f: (s: T, o: U) => R): 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.

Type Parameters
Type Parameter
U
R
Parameters
ParameterTypeDescription
otherNoneThe option to zip self with.
f(s: T, o: U) => RThe function that computes the returned value.
Returns

None

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

Implementation of

IOption.zipWith

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:135

zipWith(other, f)

zipWith<U, R>(other: Some<U>, f: (s: T, o: U) => R): Some<R>

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.

Type Parameters
Type Parameter
U
R
Parameters
ParameterTypeDescription
otherSome<U>The option to zip self with.
f(s: T, o: U) => RThe function that computes the returned value.
Returns

Some<R>

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

Implementation of

IOption.zipWith

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:136

zipWith(other, f)

zipWith<U, R>(other: Option<U>, f: (s: T, o: U) => R): Option<R>

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.

Type Parameters
Type Parameter
U
R
Parameters
ParameterTypeDescription
otherOption<U>The option to zip self with.
f(s: T, o: U) => RThe function that computes the returned value.
Returns

Option<R>

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

Implementation of

IOption.zipWith

Defined in

projects/utilities/packages/result/src/lib/Option/Some.ts:137