/apply_conditionally

Chain and apply methods on objects conditionally.

Primary LanguageRustMIT LicenseMIT

Apply Conditionally

Chain and apply methods on objects conditionally.

Installation

  1. Using cargo:
cargo add apply_conditionally
  1. By updating Cargo.toml:
[dependencies]
apply_conditionally = "1.0.0"

Usage

// Bring the trait into scope to access the trait methods on objects
use apply_conditionally::ApplyConditionally;

fn foo<T>(value: T, condition: bool) {
    value
        .apply(bar)
        .apply_if(condition, baz)
        .some_other_method();
}

License

Licensed under the MIT License.