diff --git a/libimagutil/src/lib.rs b/libimagutil/src/lib.rs index a93251b6..0797cbab 100644 --- a/libimagutil/src/lib.rs +++ b/libimagutil/src/lib.rs @@ -1,3 +1 @@ -#[test] -fn it_works() { -} +pub mod variants; diff --git a/libimagutil/src/variants.rs b/libimagutil/src/variants.rs new file mode 100644 index 00000000..0ec53830 --- /dev/null +++ b/libimagutil/src/variants.rs @@ -0,0 +1,23 @@ +/** + * Generate variants of a base value by applying parts + * + * Example: + * + * ```ignore + * generate_variants(path, vec!["foo", "bar", "baz"], |b, v| { + * let b = b.clone(); + * b.push(v); + * b + * }) + * + * ``` + * + */ +pub fn generate_variants(base: A, modders: Vec, f: &F) + -> Vec + where + F: Fn(&A, B) -> C +{ + modders.into_iter().map(|m| f(&base, m)).collect() +} +