Skip to content

Commit

Permalink
update README.md (more info about examples)
Browse files Browse the repository at this point in the history
  • Loading branch information
marat0n committed Sep 14, 2024
1 parent 4115dc3 commit 4fe6301
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,30 @@ inspired by F#'s CEs, but with changes and improvements in syntax-design.

# Docs

Firstly define the struct which is implementing all the neccessary functions for <span>yerevan.rs</span>\'s computation expressions.
1. Firstly define the struct which is implementing all the neccessary functions for <span>yerevan.rs</span>\'s computation expressions.
Like this:
```rust
struct SimpleBinder {}
impl SimpleBinder {
pub fn bind<T, U>(val: Option<T>, f: &dyn Fn(T) -> Option<U>) -> Option<U> {
match val {
Some(v) => f(v),
None => SimpleBinder::zero(),
}
}
pub fn ret<T>(val: T) -> Option<T> {
Some(val)
}
pub fn zero<T>() -> Option<T> {
None
}
}
```
2. And then use your struct as computation expression type in `yer!` macro.
Like this:
```rust
yer! {
MyOption =>
SimpleBinder =>
let! ...
let ...
ret ...
Expand All @@ -60,6 +79,6 @@ yer! {

# Examples

soon...
For now examples are available in `/tests` directory in repository. GH-link: https://github.com/marat0n/yerevan.rs/blob/dev/tests/common.rs


0 comments on commit 4fe6301

Please sign in to comment.