Option#

class council.utils.Option(some: T | None)[source]#

Bases: Generic[T]

Convenient class to manage optional values.

__init__(some: T | None) None[source]#

Initialize a new instance

Parameters:

some (Optional[T]) – some value, if any. Otherwise, None

as_optional() T | None[source]#

Returns this instance as an optional

is_none() bool[source]#

Returns True is this instance does not contain any value

is_some() bool[source]#

Returns True is this instance contains some value

map_or(map_func: Callable[[T], R], default: R) R[source]#

returns the result of the give map function on wrap value if some, or the provided default

Parameters:
  • map_func (Callable[[T], R]) – map function applies on the value if some

  • default (R) – default value

Return type:

R

static none() Option[T][source]#

Create a new instance with none

Returns:

a new instance

Return type:

Option[T]

static some(some: T) Option[T][source]#

Create a new instance with some value.

Parameters:

some (T) – the value to be wrapped by this instance

Returns:

a new instance

Return type:

Option[T]

unwrap(message: str | None = None) T[source]#

unwrap the value in the instance.

Parameters:
  • message (Optional(str)) – error message to be set on the OptionException

  • unwrap (if there is no value to) –

Returns:

the value

Return type:

T

Raises:

OptionException – there is no value wrapped by this instance

unwrap_or(default: T) T[source]#

returns the wrap value if some, or the provided default

Parameters:

default (T) – default value

Return type:

T