Skip to content

Commit 719e4a3

Browse files
committed
Removes monad refernce
1 parent 88a42ec commit 719e4a3

File tree

5 files changed

+37
-29
lines changed

5 files changed

+37
-29
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
We follow Semantic Versions since the `0.1.0` release.
44

55

6+
## WIP
7+
8+
### Misc
9+
10+
- Changes how `str()` function works for container types
11+
- Total rename to "container" in the source code
12+
13+
614
## Version 0.6.0
715

816
### Features

returns/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def is_successful(container):
2424

2525
def safe(function): # noqa: C901
2626
"""
27-
Decorator to covert exception throwing function to 'Result' monad.
27+
Decorator to covert exception throwing function to 'Result' container.
2828
2929
Show be used with care, since it only catches 'Exception' subclasses.
3030
It does not catch 'BaseException' subclasses.

returns/primitives/container.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ def __init__(self, inner_value):
2323
object.__setattr__(self, '_inner_value', inner_value)
2424

2525
def __setattr__(self, attr_name, attr_value):
26-
"""Makes inner state of the monads immutable."""
26+
"""Makes inner state of the containers immutable."""
2727
raise ImmutableStateError()
2828

2929
def __delattr__(self, attr_name): # noqa: Z434
30-
"""Makes inner state of the monads immutable."""
30+
"""Makes inner state of the containers immutable."""
3131
raise ImmutableStateError()
3232

3333
def __str__(self):
3434
"""Converts to string."""
35-
return '{0}: {1}'.format(
35+
return '<{0}: {1}>'.format(
3636
self.__class__.__qualname__,
3737
str(self._inner_value),
3838
)
@@ -52,9 +52,9 @@ class Container(_BaseContainer, metaclass=ABCMeta):
5252
5353
You won't create 'Container' instances directly.
5454
Instead, sub-classes implement specific contexts.
55-
Monads allow you to bind together
55+
containers allow you to bind together
5656
a series of calculations while maintaining
57-
the context of that specific monad.
57+
the context of that specific container.
5858
5959
This is an abstract class with the API declaration.
6060
@@ -69,7 +69,7 @@ def map(self, function): # pragma: no cover
6969
Applies 'function' to the contents of the functor.
7070
7171
And returns a new functor value.
72-
Works for monads that represent success.
72+
Works for containers that represent success.
7373
Is the opposite of :meth:`~fix`.
7474
"""
7575
raise NotImplementedError()
@@ -79,8 +79,8 @@ def bind(self, function): # pragma: no cover
7979
"""
8080
Applies 'function' to the result of a previous calculation.
8181
82-
And returns a new monad.
83-
Works for monads that represent success.
82+
And returns a new container.
83+
Works for containers that represent success.
8484
Is the opposite of :meth:`~rescue`.
8585
"""
8686
raise NotImplementedError()
@@ -91,7 +91,7 @@ def fix(self, function): # pragma: no cover
9191
Applies 'function' to the contents of the functor.
9292
9393
And returns a new functor value.
94-
Works for monads that represent failure.
94+
Works for containers that represent failure.
9595
Is the opposite of :meth:`~map`.
9696
"""
9797
raise NotImplementedError()
@@ -101,21 +101,21 @@ def rescue(self, function): # pragma: no cover
101101
"""
102102
Applies 'function' to the result of a previous calculation.
103103
104-
And returns a new monad.
105-
Works for monads that represent failure.
104+
And returns a new container.
105+
Works for containers that represent failure.
106106
Is the opposite of :meth:`~bind`.
107107
"""
108108
raise NotImplementedError()
109109

110110
@abstractmethod
111111
def value_or(self, default_value): # pragma: no cover
112-
"""Forces to unwrap value from monad or return a default."""
112+
"""Forces to unwrap value from container or return a default."""
113113
raise NotImplementedError()
114114

115115
@abstractmethod
116116
def unwrap(self): # pragma: no cover
117117
"""
118-
Custom magic method to unwrap inner value from monad.
118+
Custom magic method to unwrap inner value from container.
119119
120120
Should be redefined for ones that actually have values.
121121
And for ones that raise an exception for no values.
@@ -127,7 +127,7 @@ def unwrap(self): # pragma: no cover
127127
@abstractmethod
128128
def failure(self): # pragma: no cover
129129
"""
130-
Custom magic method to unwrap inner value from the failed monad.
130+
Custom magic method to unwrap inner value from the failed container.
131131
132132
This method is the opposite of :meth:`~unwrap`.
133133
"""
@@ -136,7 +136,7 @@ def failure(self): # pragma: no cover
136136

137137
class GenericContainerOneSlot(Generic[_ValueType], Container):
138138
"""
139-
Base class for monads with one typed slot.
139+
Base class for containers with one typed slot.
140140
141141
Use this type for generic inheritance only.
142142
Use :class:`~Container` as a general type for polymorphism.
@@ -145,7 +145,7 @@ class GenericContainerOneSlot(Generic[_ValueType], Container):
145145

146146
class GenericContainerTwoSlots(Generic[_ValueType, _ErrorType], Container):
147147
"""
148-
Base class for monads with two typed slot.
148+
Base class for containers with two typed slot.
149149
150150
Use this type for generic inheritance only.
151151
Use :class:`~Container` as a general type for polymorphism.

returns/result.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ def fix(self, function):
3939
4040
Applies 'function' to the contents of the 'Success' instance
4141
and returns a new 'Success' object containing the result.
42-
'function' should accept a single "normal" (non-monad) argument
43-
and return a non-monad result.
42+
'function' should accept a single "normal" (non-container) argument
43+
and return a non-container result.
4444
"""
4545
return Success(function(self._inner_value))
4646

4747
def rescue(self, function):
4848
"""
4949
Applies 'function' to the result of a previous calculation.
5050
51-
'function' should accept a single "normal" (non-monad) argument
51+
'function' should accept a single "normal" (non-container) argument
5252
and return Result a 'Failure' or 'Success' type object.
5353
"""
5454
return function(self._inner_value)
@@ -65,7 +65,7 @@ def unwrap(self):
6565
raise UnwrapFailedError(self)
6666

6767
def failure(self):
68-
"""Unwraps inner error value from failed monad."""
68+
"""Unwraps inner error value from failed container."""
6969
return self._inner_value
7070

7171

@@ -82,16 +82,16 @@ def map(self, function): # noqa: A003
8282
8383
Applies 'function' to the contents of the 'Success' instance
8484
and returns a new 'Success' object containing the result.
85-
'function' should accept a single "normal" (non-monad) argument
86-
and return a non-monad result.
85+
'function' should accept a single "normal" (non-container) argument
86+
and return a non-container result.
8787
"""
8888
return Success(function(self._inner_value))
8989

9090
def bind(self, function):
9191
"""
9292
Applies 'function' to the result of a previous calculation.
9393
94-
'function' should accept a single "normal" (non-monad) argument
94+
'function' should accept a single "normal" (non-container) argument
9595
and return Result a 'Failure' or 'Success' type object.
9696
"""
9797
return function(self._inner_value)
@@ -109,7 +109,7 @@ def value_or(self, default_value):
109109
return self._inner_value
110110

111111
def unwrap(self):
112-
"""Returns the unwrapped value from the inside of this monad."""
112+
"""Returns the unwrapped value from the inside of this container."""
113113
return self._inner_value
114114

115115
def failure(self):

tests/test_result/test_result_bind.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def factory(inner_value: int) -> Success[int]:
1212
bound = Success(input_value).bind(factory)
1313

1414
assert bound == factory(input_value)
15-
assert str(bound) == 'Success: 10'
15+
assert str(bound) == '<Success: 10>'
1616

1717

1818
def test_left_identity_failure():
@@ -24,7 +24,7 @@ def factory(inner_value: int) -> Failure[TypeError]:
2424
bound = Failure(input_value).bind(factory)
2525

2626
assert bound == Failure(input_value)
27-
assert str(bound) == 'Failure: 5'
27+
assert str(bound) == '<Failure: 5>'
2828

2929

3030
def test_rescue_success():
@@ -35,7 +35,7 @@ def factory(inner_value: int) -> Success[int]:
3535
bound = Success(5).rescue(factory)
3636

3737
assert bound == Success(5)
38-
assert str(bound) == 'Success: 5'
38+
assert str(bound) == '<Success: 5>'
3939

4040

4141
def test_rescue_failure():
@@ -47,4 +47,4 @@ def factory(inner_value: int) -> Failure[float]:
4747
bound = Failure(5).rescue(factory)
4848

4949
assert bound == Failure(expected)
50-
assert str(bound) == 'Failure: 6.0'
50+
assert str(bound) == '<Failure: 6.0>'

0 commit comments

Comments
 (0)