Skip to content

A macro to write nested for loop

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

TOETOE55/for_ch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

for_ch named "for_each", "for_chain"(or even "4ch"), the crate provides a macro to flatten the nested for-loop and if-let.

Example

for_ch! {
    for x in 0..10;                         // forall x in 0..10,
    // you can add a label before `for`
    for y in x..10, for _ in 0..5;          // forall y in x..x+5, 
    // zipping
    if let Some(z) = foo(x, y).await?;      // exists z. Some(z) = foo(x, y).await?
    // if let guard
    if x - y < z;                           // satisfies x - y < z
    // guard
    println!("x = {}, y = {}, z = {}", x, y, z);
}

would expend to

for x in 0..10 {
    for y in (x..10).zip(0..5) {
        if let Some(z) = foo(x, y).await? {
            if x - y < z {
                println!("x = {}, y = {}, z = {}", x, y, z);
            }
        }
    }
}

About

A macro to write nested for loop

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages