Module garoupa.misc.identity

Some shortcuts to the null operand and to ease creating elements

Classes

class Identity (version, etype_inducer='ordered')
Expand source code
class Identity(Hosh):
    """
    Identity element

    An Identity object is an innocuous identifier that represents a real world process that does nothing,
    or an empty data structure.
    It is also useful as a shortcut to coerce some Python values directly to a Hosh object through multiplication.

    Parameters
    ----------
    version
        UT40_4, UT64.4 or other group changes the number of digits and robustness against collisions/ambiguity
    etype_inducer
        Element type of a future multiplication by a raw Python value: 'unordered', 'ordered', 'hybrid'
    """

    _u, _h = None, None

    def __init__(self, version, etype_inducer="ordered"):
        super().__init__([0, 0, 0, 0, 0, 0], version=version)
        self._etype_inducer = etype_inducer

    @property
    def u(self):
        """Shortcut to induce etype=unordered in the next operand, when it is not a ready Hosh object.
        default=Ordered, h=Hybrid and u=Unordered

        Usage:

        >>> from garoupa import ø, Hosh
        >>> a = ø.u * b"654"
        >>> print(a)
        9_6a78c0056_____________________________
        >>> Hosh(b"654", "unordered") == a
        True
        """
        if self._u is None:
            self._u = Identity(self.version, etype_inducer="unordered")
        return self._u

    @property
    def h(self):
        """Shortcut to induce etype=hybrid in the next operand, when it is given as a bytes object.
        default=Ordered, h=Hybrid and u=Unordered

        Usage:

        >>> from garoupa import Hosh, ø
        >>> a = ø.h * b"654"
        >>> print(a)
        eW_aebeb57cf1455dccdc1bd990950a03b0f2e29
        >>> Hosh(b"654", "hybrid") == a
        True
        """
        if self._h is None:
            self._h = Identity(self.version, etype_inducer="hybrid")
        return self._h

Identity element

An Identity object is an innocuous identifier that represents a real world process that does nothing, or an empty data structure. It is also useful as a shortcut to coerce some Python values directly to a Hosh object through multiplication.

Parameters

version
UT40_4, UT64.4 or other group changes the number of digits and robustness against collisions/ambiguity
etype_inducer
Element type of a future multiplication by a raw Python value: 'unordered', 'ordered', 'hybrid'

Ancestors

  • garoupa.hosh.Hosh

Subclasses

Instance variables

prop h
Expand source code
@property
def h(self):
    """Shortcut to induce etype=hybrid in the next operand, when it is given as a bytes object.
    default=Ordered, h=Hybrid and u=Unordered

    Usage:

    >>> from garoupa import Hosh, ø
    >>> a = ø.h * b"654"
    >>> print(a)
    eW_aebeb57cf1455dccdc1bd990950a03b0f2e29
    >>> Hosh(b"654", "hybrid") == a
    True
    """
    if self._h is None:
        self._h = Identity(self.version, etype_inducer="hybrid")
    return self._h

Shortcut to induce etype=hybrid in the next operand, when it is given as a bytes object. default=Ordered, h=Hybrid and u=Unordered

Usage:

>>> from garoupa import Hosh, ø
>>> a = ø.h * b"654"
>>> print(a)
eW_aebeb57cf1455dccdc1bd990950a03b0f2e29
>>> Hosh(b"654", "hybrid") == a
True
prop u
Expand source code
@property
def u(self):
    """Shortcut to induce etype=unordered in the next operand, when it is not a ready Hosh object.
    default=Ordered, h=Hybrid and u=Unordered

    Usage:

    >>> from garoupa import ø, Hosh
    >>> a = ø.u * b"654"
    >>> print(a)
    9_6a78c0056_____________________________
    >>> Hosh(b"654", "unordered") == a
    True
    """
    if self._u is None:
        self._u = Identity(self.version, etype_inducer="unordered")
    return self._u

Shortcut to induce etype=unordered in the next operand, when it is not a ready Hosh object. default=Ordered, h=Hybrid and u=Unordered

Usage:

>>> from garoupa import ø, Hosh
>>> a = ø.u * b"654"
>>> print(a)
9_6a78c0056_____________________________
>>> Hosh(b"654", "unordered") == a
True
class ø (etype_inducer='ordered')
Expand source code
class ø(Identity):
    """
    40-digit identity element

    An Identity object is an innocuous identifier that represents a real world process that does nothing,
    or an empty data structure.
    It is also useful as a shortcut to coerce some Python values directly to a Hosh object through multiplication.

    Normal usage (as an already instantiated object:

    >>> from garoupa import ø
    >>> ø.id
    '0000000000000000000000000000000000000000'
    >>> print(ø * 872696823986235926596245)
    00_dea47151b84085dfcc8b00000000000000000

    Parameters
    ----------
    etype_inducer
        Element type of a future multiplication by a raw Python value: 'unordered', 'ordered', 'hybrid'
    """

    def __init__(self, etype_inducer="ordered"):
        super().__init__(UT40_4, etype_inducer)

40-digit identity element

An Identity object is an innocuous identifier that represents a real world process that does nothing, or an empty data structure. It is also useful as a shortcut to coerce some Python values directly to a Hosh object through multiplication.

Normal usage (as an already instantiated object:

>>> from garoupa import ø
>>> ø.id
'0000000000000000000000000000000000000000'
>>> print(ø * 872696823986235926596245)
00_dea47151b84085dfcc8b00000000000000000

Parameters

etype_inducer
Element type of a future multiplication by a raw Python value: 'unordered', 'ordered', 'hybrid'

Ancestors

Inherited members