Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Update do-notation examples in README #170

Merged
merged 1 commit into from
Dec 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading