wrap

class pythonic_fp.gadgets.wrap.Wrap

Bases: Generic

Wrap

Immutablely wrap exactly one item.

Tip

Wrap objects are matchable.

__init__(item: T) None

init

Initialize Wrap with 1 required item.

param item:

Item to be wrapped.

__bool__() bool

bool

Truthiness same as wrapped object.

__len__() int

len

Wrapped items always contain just one item.

returns:

1

__iter__() Iterator

iter

yields:

A reference to the wrapped item.

__eq__(other: object) bool

equality comparison

Compare Wrap to another object.

param other:

Object to be compared.

returns:

True if other is of type Wrap and wraps an item which compares as equal to the wrapped item, otherwise False.

__repr__() str

repr string

Construct string ‘Wrap(item_str)’ where item_str = repr(item) for the contained item.

returns:

A string to reproduce of the wrapped item.

__str__() str

user string

Construct string ‘Wrap(item_str)’ where item_str = str(item) for the contained item.

returns:

A string meaningful to an end user.

map(f: Callable[[T], U]) Wrap

map

Map function f over contents.

param f:

Mapping function.

returns:

New instance.

bind(f: Callable[[T], Wrap]) Wrap

bind

Flatmap wrapped object with function f.

param f:

Binding function.

returns:

New instance.

class pythonic_fp.gadgets.wrap.HWrap

Bases: Hashable, Generic

HWrap

Immutablely wrap exactly one hashable item.

Tip

HWrap objects are hashable and matchable.

__init__(item: T) None

init

Initialize HWrap with 1 required item.

param item:

Item to be wrapped.

__hash__() int

Return hash(self).

__bool__() bool

bool

Truthiness same as wrapped object.

__len__() int

len

HWrapped items always contain just one item.

returns:

1

__iter__() Iterator

iter

yields:

A reference to the wrapped item.

__eq__(other: object) bool

equality comparison

Compare HWrap to another object.

param other:

Object to be compared.

returns:

True if other is of type HWrap and wraps an item which compares as equal to the wrapped item, otherwise False.

__repr__() str

repr string

Construct string ‘HWrap(item_str)’ where item_str = repr(item) for the contained item.

returns:

A string to reproduce of the wrapped object.

__str__() str

user string

Construct string ‘HWrap(item_str)’ where item_str = str(item) for the contained item.

returns:

A string meaningful to an end user.

map(f: Callable[[T], U]) HWrap

map

Map function f over wrapped the wrapped object returning a new HWrap instance.

param f:

Mapping function.

returns:

New instance.

bind(f: Callable[[T], HWrap]) HWrap

bind

Flatmap Box with function f.

param f:

Binding function.

returns:

New instance.