Skip to content

Commit abc3223

Browse files
committed
Adds example to the docs
1 parent d1c93ae commit abc3223

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,31 @@ so we have included some useful features to make your life easier:
2828
- [Do notation](https://dry-monads.readthedocs.io/en/latest/pages/do-notation.html)
2929

3030

31+
## Example
32+
33+
34+
```python
35+
from dry_monads.do_notation import do_notation
36+
from dry_monads.either import Result, Success, Failure
37+
38+
class CreateAccountAndUser(object):
39+
"""Creates new Account-User pair."""
40+
41+
@do_notation
42+
def __call__(self, username: str, email: str) -> Result['User', str]:
43+
"""Can return a Success(user) or Failure(str_reason)."""
44+
user_schema = self._validate_user(username, email).unwrap()
45+
account = self._create_account(user_schema).unwrap()
46+
return self._create_user(account)
47+
48+
# Protected methods
49+
# def _validate_user()
50+
# ...
51+
52+
```
53+
54+
We are [covering what's going on in this example](https://dry-monads.readthedocs.io/en/latest/pages/do-notation.html) in the docs.
55+
3156
## Inspirations
3257

3358
This module is heavily based on:

0 commit comments

Comments
 (0)