Skip to content

Commit

Permalink
docs: Update do example in README
Browse files Browse the repository at this point in the history
  • Loading branch information
francium committed Dec 23, 2023
1 parent 4218d17 commit 21c942a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,10 @@ Instead of `x <- Ok(1)` we write `for x in Ok(1)`. Since the syntax is
generator-based, the final result must be the first line, not the last.

``` python
final_result: Result[float, int] = do(
Ok(len(x) + int(y) + 0.5)
for x in Ok("hello")
for y in Ok(True)
final_result: Result[int, str] = do(
Ok(x + y)
for x in Ok(1)
for y in Ok(2)
)
```

Expand All @@ -368,9 +368,9 @@ macro](https://docs.rs/do-notation/latest/do_notation/):
``` rust
use do_notation::m;
let r = m! {
x <- Some("Hello, world!");
y <- Some(3);
Some(x.len() * y)
x <- Some(1);
y <- Some(2);
Some(x + y)
};
```

Expand All @@ -390,11 +390,11 @@ my_result: Result[int, str] = do(
You can use `do()` with awaited values as follows:

``` python
async def process_data(data) -> Result[float, int]:
async def process_data(data) -> Result[int, str]:
res1 = await get_result_1(data)
res2 = await get_result_2(data)
return do(
Ok(len(x) + int(y) + 0.5)
Ok(x + y)
for x in res1
for y in res2
)
Expand All @@ -404,9 +404,9 @@ However, if you want to await something inside the expression, use
`do_async()`:

``` python
async def process_data(data) -> Result[float, int]:
async def process_data(data) -> Result[int, str]:
return do_async(
Ok(len(x) + int(y) + 0.5)
Ok(x + y)
for x in await get_result_1(data)
for y in await get_result_2(data)
)
Expand Down
2 changes: 1 addition & 1 deletion src/result/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
"do",
"do_async",
]
__version__ = "0.16.0.dev0"
__version__ = "0.16.0"

0 comments on commit 21c942a

Please sign in to comment.