File: lashable.py

package info (click to toggle)
python-returns 0.26.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,652 kB
  • sloc: python: 11,000; makefile: 18
file content (50 lines) | stat: -rw-r--r-- 1,420 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from abc import abstractmethod
from collections.abc import Callable
from typing import Generic, TypeVar

from typing_extensions import Never

from returns.primitives.hkt import KindN

_FirstType = TypeVar('_FirstType')
_SecondType = TypeVar('_SecondType')
_ThirdType = TypeVar('_ThirdType')
_UpdatedType = TypeVar('_UpdatedType')

_LashableType = TypeVar('_LashableType', bound='LashableN')


class LashableN(Generic[_FirstType, _SecondType, _ThirdType]):
    """
    Represents a "context" in which calculations can be executed.

    ``Rescueable`` allows you to bind together
    a series of calculations while maintaining
    the context of that specific container.

    In contrast to :class:`returns.interfaces.bindable.BinbdaleN`,
    works with the second type value.
    """

    __slots__ = ()

    @abstractmethod
    def lash(
        self: _LashableType,
        function: Callable[
            [_SecondType],
            KindN[_LashableType, _FirstType, _UpdatedType, _ThirdType],
        ],
    ) -> KindN[_LashableType, _FirstType, _UpdatedType, _ThirdType]:
        """
        Applies 'function' to the result of a previous calculation.

        And returns a new container.
        """


#: Type alias for kinds with two type arguments.
Lashable2 = LashableN[_FirstType, _SecondType, Never]

#: Type alias for kinds with three type arguments.
Lashable3 = LashableN[_FirstType, _SecondType, _ThirdType]