towhee.functional.option.Some

class towhee.functional.option.Some(x: A)[source]

Bases: Option[A]

Some value for Option

Methods

empty

Return an empty value

flat_map

Apply boxed version of callable

get

Return unboxed value

get_or_else

Return unboxed value, or default is the value is empty.

is_empty

Return True if the value is empty.

is_some

Return True if the value is boxed value.

map

Apply function to value

of

Return a boxed value

__init__(x: A) None[source]
__repr__() str[source]

Return repr(self).

static empty()

Return an empty value

Returns:

empty value

Return type:

Empty

flat_map(f: Callable[[A], Option[B]]) Option[B][source]

Apply boxed version of callable

Parameters:

f (Callable[[A], Option[B]]) – boxed version of callable

Returns:

boxed value

Return type:

Option[B]

Examples:

>>> Option.of(1).flat_map(lambda x: x+1)
2
>>> Option.empty().flat_map(lambda x: x+1)
Empty()
get()[source]

Return unboxed value

get_or_else(default)

Return unboxed value, or default is the value is empty.

Examples:

>>> Option.of(0).get_or_else(1)
0
>>> Option.empty().get_or_else(1)
1
is_empty()

Return True if the value is empty.

is_some()

Return True if the value is boxed value.

map(f: Callable[[A], B]) Option[B]

Apply function to value

Parameters:

f (Callable[[A], B]) – unboxed function

Returns:

boxed return value

Return type:

Option[B]

static of(x: T)

Return a boxed value

Parameters:

x (T) – input value

Returns:

boxed value

Return type:

Some(T)