combinatory

Crates.iocombinatory
lib.rscombinatory
version
sourcesrc
created_at2024-10-23 08:55:40.617622
updated_at2024-10-23 08:55:40.617622
descriptionCreate every combination possible of values of 2D collections / iterators.
homepage
repositoryhttps://github.com/JorgeRicoVivas/combinatory
max_upload_size
id1419852
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Jorge Rico Vivas (JorgeRicoVivas)

documentation

README

Combinatory

crates.io docs.rs GitHub Actions Workflow Status GitHub last commit GitHub License

You are reading the documentation for combinatory version 1.0.0

Allows to combinate values of two dimensional iterators / collections.

For example, the combinations of each value [1, 2] with the values [a, b] are:

  • (1,a).
  • (1,b).
  • (2,a).
  • (2,b).

The following code shows every combination of a menu-deal composed of a main, a side, and a dessert, having two options for each:

use combinatory::Combinatory;

const SIDES: &[&'static str] = &["Soup", "Bread and butter"];
const MAIN: &[&'static str] = &["Chicken", "Burger with fries"];
const DESSERTS: &[&'static str] = &["Vanilla ice cream", "Souffle"];

let possible_menus = Combinatory::new([SIDES, MAIN, DESSERTS])
    .ref_combinations()
    .enumerate()
    .map(|(menu_index, possible_menu)| {
        format!("{} - {}", menu_index + 1, possible_menu
            .map(|string|string.to_string()).collect::<Vec<_>>().join(", "))
    })
    .collect::<Vec<_>>()
    .join("\n");

println!("{possible_menus}");

assert_eq!(possible_menus,
"1 - Soup, Chicken, Vanilla ice cream
2 - Soup, Chicken, Souffle
3 - Soup, Burger with fries, Vanilla ice cream
4 - Soup, Burger with fries, Souffle
5 - Bread and butter, Chicken, Vanilla ice cream
6 - Bread and butter, Chicken, Souffle
7 - Bread and butter, Burger with fries, Vanilla ice cream
8 - Bread and butter, Burger with fries, Souffle");

This code will print:

1 - Soup, Chicken, Vanilla ice cream
2 - Bread and butter, Chicken, Vanilla ice cream
3 - Soup, Fillet with fries, Vanilla ice cream
4 - Bread and butter, Fillet with fries, Vanilla ice cream
5 - Soup, Chicken, Souffle
6 - Bread and butter, Chicken, Souffle
7 - Soup, Fillet with fries, Souffle
8 - Bread and butter, Fillet with fries, Souffle
Commit count: 3

cargo fmt