From 4fe6301bf8ab190968628444676372e4018e24b0 Mon Sep 17 00:00:00 2001 From: marat0n Date: Sat, 14 Sep 2024 19:52:22 +0300 Subject: [PATCH] update README.md (more info about examples) --- README.md | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8f10953..c8cc2ae 100644 --- a/README.md +++ b/README.md @@ -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 yerevan.rs\'s computation expressions. +1. Firstly define the struct which is implementing all the neccessary functions for yerevan.rs\'s computation expressions. +Like this: +```rust +struct SimpleBinder {} +impl SimpleBinder { + pub fn bind(val: Option, f: &dyn Fn(T) -> Option) -> Option { + match val { + Some(v) => f(v), + None => SimpleBinder::zero(), + } + } + pub fn ret(val: T) -> Option { + Some(val) + } + pub fn zero() -> Option { + None + } +} +``` +2. And then use your struct as computation expression type in `yer!` macro. Like this: ```rust yer! { - MyOption => + SimpleBinder => let! ... let ... ret ... @@ -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