wrap¶
Module wrap
Wrap objects in ways to make them “immutable.”
Class
Wrap: wrap an objectClass
HWrap: wrap a hashable object
- class pythonic_fp.gadgets.wrap.Wrap¶
Bases:
GenericWrap object
Immutablely wrap exactly one value of a given type.
Wrapobjects can be used in Python match statements.- __init__(item: T) None¶
Initializer
Initialize
Wrapwith 1 required item.- Parameters:
item – Item to be wrapped.
- __bool__() bool¶
Bool
Truthiness same as wrapped object.
- __iter__() Iterator¶
Iter
Iterable, iterates wrapped item.
- __str__() str¶
User string
Construct string ‘Box(item_str)’ where
item_str = str(item)for the currently contained item.- Returns:
A string to reproduce the current state of the
Box.
- __eq__(other: object) bool¶
Equality comparison
Efficiently compare
Wrapto another object.- Parameters:
other – The object to be compared with,
- Returns:
Trueifotheris of type Wrap and wraps an object which compares as equal to the wrapped object, otherwiseFalse.
- class pythonic_fp.gadgets.wrap.HWrap¶
Bases:
Hashable,GenericWrap hashable object
Immutablely wrap exactly one value of a given hashable type.
HWrapobjects can be used in Python match statements.Tip
HWrapobjects are hashable.- __init__(item: T) None¶
- __hash__() int¶
Return hash(self).
- __bool__() bool¶
Bool
Truthiness same as wrapped object.
- __iter__() Iterator¶
Iter
Iterable, iterates wrapped item.
- __repr__() str¶
Return repr(self).
- __eq__(other: object) bool¶
Equality comparison
Efficiently compare to another object.
- Parameters:
other – Object to be compared
- Returns:
Trueifotheris of type HWrap and wraps an object which compares as equal to the wrapped object, otherwiseFalse.