File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff 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
3358This module is heavily based on:
You can’t perform that action at this time.
0 commit comments