Option

Option

Option module.

Contains a collection of static methods (functions) for operating on options. All functions takes the source as the last curried argument, i.e all functions returns a function that takes the source sequence as the only argument.

Nothing: expression.core.option.Nothing_[Any] = Nothing

Singleton Nothing object.

Since Nothing is a singleton it can be tested e.g using is:
>>> if xs is Nothing:
...     return True
exception Nothing_

The None option case class.

Do not use. Use the singleton Nothing instead. Since Nothing is a singleton it can be tested e.g using is:

>>> if xs is Nothing:
...     return True
bind(mapper: Callable[[expression.core.option._TSource], expression.core.option.Option[expression.core.option._TResult]]) expression.core.option.Option[expression.core.option._TResult]

Bind option.

Applies and returns the result of the mapper if the value is Some. If the value is Nothing then Nothing is returned.

Parameters

mapper – A function that takes the value of type TSource from an option and transforms it into an option containing a value of type TResult.

Returns

An option of the output type of the mapper.

default_value(value: expression.core.option._TSource) expression.core.option._TSource

Gets the value of the option if the option is Some, otherwise returns the specified default value.

dict() Union[expression.core.option._TSource, Dict[Any, Any]]

Returns a json string representation of the option.

filter(predicate: Callable[[expression.core.option._TSource], bool]) expression.core.option.Option[expression.core.option._TSource]

Returns the input if the predicate evaluates to true, otherwise returns Nothing

is_none() bool

Returns True.

is_some() bool

Returns False.

or_else(if_none: expression.core.option.Option[expression.core.option._TSource]) expression.core.option.Option[expression.core.option._TSource]

Returns if_none.

or_else_with(if_none: Callable[[], expression.core.option.Option[expression.core.option._TSource]]) expression.core.option.Option[expression.core.option._TSource]

Evaluates if_none and returns the result.

property value: expression.core.option._TSource

Returns the value wrapped by the option.

A ValueError is raised if the option is Nothing.

class Option

Option abstract base class.

abstract bind(mapper: Callable[[expression.core.option._TSource], expression.core.option.Option[expression.core.option._TResult]]) expression.core.option.Option[expression.core.option._TResult]

Bind option.

Applies and returns the result of the mapper if the value is Some. If the value is Nothing then Nothing is returned.

Parameters

mapper – A function that takes the value of type TSource from an option and transforms it into an option containing a value of type TResult.

Returns

An option of the output type of the mapper.

default_value(value: expression.core.option._TSource) expression.core.option._TSource

Get with default value.

Gets the value of the option if the option is Some, otherwise returns the specified default value.

abstract dict() Optional[expression.core.option._TSource]

Returns a json string representation of the option.

abstract filter(predicate: Callable[[expression.core.option._TSource], bool]) expression.core.option.Option[expression.core.option._TSource]

Returns the input if the predicate evaluates to true, otherwise returns Nothing

abstract is_none() bool

Returns true if the option is Nothing.

abstract is_some() bool

Returns true if the option is not Nothing.

classmethod of_obj(value: expression.core.option._TSource) expression.core.option.Option[expression.core.option._TSource]

Convert object to an option.

classmethod of_optional(value: Optional[expression.core.option._TSource]) expression.core.option.Option[expression.core.option._TSource]

Convert optional value to an option.

abstract or_else(if_none: expression.core.option.Option[expression.core.option._TSource]) expression.core.option.Option[expression.core.option._TSource]

Returns option if it is Some, otherwise returns if_one.

abstract or_else_with(if_none: Callable[[], expression.core.option.Option[expression.core.option._TSource]]) expression.core.option.Option[expression.core.option._TSource]

Returns option if it is Some, otherwise evaluates the given function and returns the result.

abstract property value: expression.core.option._TSource

Returns the value wrapped by the option.

A ValueError is raised if the option is Nothing.

class Some(value: expression.core.option._TSource)

The Some option case class.

bind(mapper: Callable[[expression.core.option._TSource], expression.core.option.Option[expression.core.option._TResult]]) expression.core.option.Option[expression.core.option._TResult]

Bind option.

Applies and returns the result of the mapper if the value is Some. If the value is Nothing then Nothing is returned.

Parameters

mapper – A function that takes the value of type TSource from an option and transforms it into an option containing a value of type TResult.

Returns

An option of the output type of the mapper.

default_value(value: expression.core.option._TSource) expression.core.option._TSource

Gets the value of the option if the option is Some, otherwise returns the specified default value.

dict() Optional[expression.core.option._TSource]

Returns a json string representation of the option.

filter(predicate: Callable[[expression.core.option._TSource], bool]) expression.core.option.Option[expression.core.option._TSource]

Returns the input if the predicate evaluates to true, otherwise returns Nothing

is_none() bool

Returns False.

is_some() bool

Returns True.

or_else(if_none: expression.core.option.Option[expression.core.option._TSource]) expression.core.option.Option[expression.core.option._TSource]

Returns self.

or_else_with(if_none: Callable[[], expression.core.option.Option[expression.core.option._TSource]]) expression.core.option.Option[expression.core.option._TSource]

Returns self.

property value: expression.core.option._TSource

Returns the value wrapped by the option.

A ValueError is raised if the option is Nothing.

bind(mapper: Callable[[expression.core.option._TSource], expression.core.option.Option[expression.core.option._TResult]]) Callable[[expression.core.option.Option[expression.core.option._TSource]], expression.core.option.Option[expression.core.option._TResult]]

Bind option.

Applies and returns the result of the mapper if the value is Some. If the value is Nothing then Nothing is returned.

Parameters

mapper – A function that takes the value of type _TSource from an option and transforms it into an option containing a value of type TResult.

Returns

A partially applied function that takes an option and returns an option of the output type of the mapper.

default_arg(value: expression.core.option.Option[expression.core.option._TSource], default_value: expression.core.option._TSource) expression.core.option._TSource

Specify default argument.

Used to specify a default value for an optional argument in the implementation of a function. Same as default_value, but “uncurried” and with the arguments swapped.

default_value(value: expression.core.option._TSource) Callable[[expression.core.option.Option[expression.core.option._TSource]], expression.core.option._TSource]

Gets the value of the option if the option is Some, otherwise returns the specified default value.

of_obj(value: Any) expression.core.option.Option[Any]

Convert object to an option.

Convert a value that could be None into an Option value.

Parameters

value – The input object.

Returns

The result option.

of_optional(value: Optional[expression.core.option._TSource]) expression.core.option.Option[expression.core.option._TSource]

Convert an optional value to an option.

Convert a value that could be None into an Option value. Same as of_obj but with typed values.

Parameters

value – The input optional value.

Returns

The result option.

or_else(if_none: expression.core.option.Option[expression.core.option._TSource]) Callable[[expression.core.option.Option[expression.core.option._TSource]], expression.core.option.Option[expression.core.option._TSource]]

Returns option if it is Some, otherwise returns ifNone.