jivago.lang.nullable module

exception jivago.lang.nullable.EmptyNullableException[source]

Bases: Exception

class jivago.lang.nullable.Nullable(nullable: Optional[T])[source]

Bases: typing.Generic

Nullable class which wraps Optional types.

Parameters:nullable (Optional) – Item which can be None.
static empty() → jivago.lang.nullable.Nullable[source]
filter(predicate: Union[Callable[[T], bool], Callable[[...], bool]]) → jivago.lang.nullable.Nullable[~T][T][source]

Filters item given a criterion.

Parameters:predicate (Callable) – Invoked with a non-nil parameter. Should return a boolean.
get() → Optional[T][source]

Gets the item if present.

Raises:EmptyNullableException – Attempting to get a missing item.
ifPresent(consumer: Union[Callable[[T], None], Callable[[...], None]]) → jivago.lang.nullable.Nullable[~T][T][source]

Invoke function if value is present; otherwise does nothing.

Parameters:consumer (Callable) – Function to be invoked with a non-nil parameter.
isPresent() → bool[source]

Returns True if item is not None.

map(callable: Union[Callable[[T], S], Callable[[...], S]]) → jivago.lang.nullable.Nullable[~S][S][source]

Maps the item when present.

Parameters:callable (Callable) – Invoked with a non-nil parameter.
orElse(default_value: T) → T[source]

Returns the item if present, else return the supplied default value.

Parameters:default_value – Value to return instead of a None value.
orElseFetch(supplier: Callable[[], T]) → T[source]

Returns if present, invoke callable if missing.

Parameters:supplier (Callable) – Supplied return value will be return in place of a None value. Should not require parameters.
orElseThrow(exception: Union[Exception, Callable[[], Exception]]) → T[source]

Returns if present, raises exception if missing.

Parameters:exception – Either an exception, or a callable which returns an exception.