Interface: Nothing<T>
A Nothing instance is the absent variant instance of the Maybe type, representing the presence of a value which may be absent. For a full discussion, see the module docs.
Extends
Omit<MaybeImpl<T>,"value">
Type Parameters
T
T extends object
The type which would be wrapped in a Just variant of the Maybe.
Properties
isJust
isJust:
false
Overrides
Omit.isJust
isNothing
isNothing:
true
Is the Maybe a Nothing?
Overrides
Omit.isNothing
variant
readonlyvariant:"Nothing"
Distinguish between the Just and Nothing variants.
Overrides
Omit.variant
Methods
and()
and<
U>(mAnd):Maybe<U>
Method variant for and
Type Parameters
U
U extends object
Parameters
mAnd
Maybe<U>
Returns
Maybe<U>
Inherited from
Omit.and
andThen()
Call Signature
andThen<
U>(andThenFn):Maybe<U>
Method variant for andThen
Type Parameters
U
U extends object
Parameters
andThenFn
(t) => Maybe<U>
Returns
Maybe<U>
Inherited from
Omit.andThen
Call Signature
andThen<
R>(andThenFn):Maybe<ValueFor<R>>
Method variant for andThen
Type Parameters
R
R extends AnyMaybe
Parameters
andThenFn
(t) => R
Returns
Maybe<ValueFor<R>>
Inherited from
Omit.andThen
ap()
ap<
A,B>(this,val):Maybe<B>
Method variant for ap
Type Parameters
A
A extends object
B
B extends object
Parameters
this
Maybe<(val) => B>
val
Maybe<A>
Returns
Maybe<B>
Inherited from
Omit.ap
equals()
equals(
comparison):boolean
Method variant for equals
Parameters
comparison
Maybe<T>
Returns
boolean
Inherited from
Omit.equals
flatten()
flatten<
A>(this):Maybe<A>
Given a nested Maybe, remove one layer of nesting.
For example, given a Maybe<Maybe<string>>, the resulting type after using this method will be Maybe<string>.
Note
This method only works when the value wrapped in Maybe is another Maybe. If you have a Maybe<string> or Maybe<number>, this method won't work. If you have a Maybe<Maybe<string>>, then you can call .flatten() to get back a Maybe<string>.
Examples
import * as maybe from 'true-myth/maybe';
const nested = maybe.just(maybe.just('hello'));
const flattened = nested.flatten(); // Maybe<string>
console.log(flattened); // Just('hello')
const nestedNothing = maybe.just(maybe.nothing<string>());
const flattenedNothing = nestedNothing.flatten(); // Maybe<string>
console.log(flattenedNothing); // Nothing
const nothingNested = maybe.nothing<Maybe<string>>();
const flattenedOuter = nothingNested.flatten(); // Maybe<string>
console.log(flattenedOuter); // NothingType Parameters
A
A extends object
Parameters
this
Returns
Maybe<A>
Inherited from
Omit.flatten
get()
get<
K>(key):Maybe<NonNullable<T[K]>>
Method variant for get
If you have a Maybe of an object type, you can do thatMaybe.get('a key') to look up the next layer down in the object.
type DeepOptionalType = {
something?: {
with?: {
deeperKeys?: string;
}
}
};
const fullySet: DeepType = {
something: {
with: {
deeperKeys: 'like this'
}
}
};
const deepJust = Maybe.of(fullySet)
.get('something')
.get('with')
.get('deeperKeys');
console.log(deepJust); // Just('like this');
const partiallyUnset: DeepType = { something: { } };
const deepEmpty = Maybe.of(partiallyUnset)
.get('something')
.get('with')
.get('deeperKeys');
console.log(deepEmpty); // NothingType Parameters
K
K extends string | number | symbol
Parameters
key
K
Returns
Maybe<NonNullable<T[K]>>
Inherited from
Omit.get
map()
map<
U>(mapFn):Maybe<U>
Method variant for map
Type Parameters
U
U extends object
Parameters
mapFn
(t) => U
Returns
Maybe<U>
Inherited from
Omit.map
mapOr()
mapOr<
U>(orU,mapFn):U
Method variant for `mapOr`
Type Parameters
U
U
Parameters
orU
U
mapFn
(t) => U
Returns
U
Inherited from
Omit.mapOr
mapOrElse()
mapOrElse<
U>(orElseFn,mapFn):U
Method variant for mapOrElse
Type Parameters
U
U
Parameters
orElseFn
() => U
mapFn
(t) => U
Returns
U
Inherited from
Omit.mapOrElse
match()
match<
U>(matcher):U
Method variant for match
Type Parameters
U
U
Parameters
matcher
Matcher<T, U>
Returns
U
Inherited from
Omit.match
or()
or(
mOr):Maybe<T>
Method variant for or
Parameters
mOr
Maybe<T>
Returns
Maybe<T>
Inherited from
Omit.or
orElse()
Call Signature
orElse(
orElseFn):Maybe<T>
Method variant for orElse
Parameters
orElseFn
() => Maybe<T>
Returns
Maybe<T>
Inherited from
Omit.orElse
Call Signature
orElse<
R>(orElseFn):Maybe<ValueFor<R>>
Method variant for orElse
Type Parameters
R
R extends AnyMaybe
Parameters
orElseFn
() => R
Returns
Maybe<ValueFor<R>>
Inherited from
Omit.orElse
toJSON()
toJSON():
Serialized<T>
Method variant for toJSON
Returns
Serialized<T>
Inherited from
Omit.toJSON
toString()
toString():
string
Method variant for toString
Returns
string
Inherited from
Omit.toString
unwrapOr()
unwrapOr<
U>(defaultValue):T|U
Method variant for unwrapOr
Type Parameters
U
U
Parameters
defaultValue
U
Returns
T | U
Inherited from
Omit.unwrapOr
unwrapOrElse()
unwrapOrElse<
U>(elseFn):T|U
Method variant for unwrapOrElse
Type Parameters
U
U
Parameters
elseFn
() => U
Returns
T | U
Inherited from
Omit.unwrapOrElse