Skip to content

Commit e8c6f6f

Browse files
committed
Fixes #83
1 parent 6ae2810 commit e8c6f6f

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,24 +181,22 @@ class FetchUserProfile(object):
181181
"""Single responsibility callable object that fetches user profile."""
182182

183183
@pipeline
184-
def __call__(self, user_id: int) -> Result[IO['UserProfile'], Exception]:
184+
def __call__(self, user_id: int) -> IO[Result['UserProfile', Exception]]:
185185
"""Fetches UserProfile dict from foreign API."""
186-
response = self._make_request(user_id).unwrap()
187-
return self._parse_json(response)
186+
return self._make_request(user_id).map(
187+
lambda response: self._parse_json(response.unwrap())
188+
)
188189

189-
@safe
190190
@impure
191+
@safe
191192
def _make_request(self, user_id: int) -> requests.Response:
192193
response = requests.get('/api/users/{0}'.format(user_id))
193194
response.raise_for_status()
194195
return response
195196

196197
@safe
197-
def _parse_json(
198-
self,
199-
io_response: IO[requests.Response],
200-
) -> IO['UserProfile']:
201-
return io_response.map(lambda response: response.json())
198+
def _parse_json(self,response: requests.Response) -> 'UserProfile':
199+
return response.json()
202200
```
203201

204202
Now we have explicit markers where the `IO` did happen

docs/pages/container.rst

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ Container is a concept that allows you
77
to write code around the existing wrapped values
88
while maintaining the execution context.
99

10-
We will show you its simple API of one attribute and several simple methods.
10+
List of supported containers:
11+
12+
- :class:`IO <returns.io.IO>` to mark explicit ``IO`` actions
13+
- :class:`Result <returns.result.Result>` to handle possible exceptions
14+
15+
We will show you container's simple API of one attribute
16+
and several simple methods.
1117

1218

1319
Basics
@@ -268,6 +274,19 @@ You can have a look at the suggested ``mypy``
268274
in our own repository.
269275

270276

277+
Composition
278+
-----------
279+
280+
You can and should compose different containers together.
281+
Here's the full table of compositions that make sense:
282+
283+
- ``IO[Result[A, B]]`` ✅
284+
- ``IO[IO[A]]`` 🚫
285+
- ``Result[IO[A], B]`` 🚫
286+
- ``Result[A, IO[A]]`` 🚫
287+
- ``Result[Result[A, B], C]`` 🚫
288+
- ``Result[A, Result[B, C]]`` 🚫
289+
271290
API Reference
272291
-------------
273292

0 commit comments

Comments
 (0)