rosefromthedead / effing-mad

Algebraic effects for Rust
578 stars 19 forks source link

Ergonomics of `effing_mad::run` and composition of effect handlers #14

Open teohhanhui opened 3 months ago

teohhanhui commented 3 months ago

Currently:

fn main() {
    let console_handler = handler!(Console {
        print(s, _) => println!("{s}"),
    });
    let with_console = handle_group(do_command(), console_handler);
    let cli_options_handler = handler!(CliOptions {
        read() => options().run(),
    });
    let with_cli_options = handle_group(with_console, cli_options_handler);

    effing_mad::run(with_cli_options);
}

What if:

fn main() {
    let console_handler = handler!(Console {
        print(s, _) => println!("{s}"),
    });
    let cli_options_handler = handler!(CliOptions {
        read() => options().run(),
    });

    effing_mad::run!(
        do_command()
        |> handle_group(console_handler)
        |> handle_group(cli_options_handler)
    );
}

And mainly because naming is hard... There is nothing special about with_cli_options in the previous code other than it just happens to be the last in the chain?

teohhanhui commented 3 months ago

Uhh, I guess it's just https://github.com/rust-lang/rfcs/pull/2656

Which I was already following anyway...