util: Add variant-generator utility
This commit is contained in:
parent
a8bc18d39a
commit
be6a0b8b78
2 changed files with 24 additions and 3 deletions
|
@ -1,3 +1 @@
|
||||||
#[test]
|
pub mod variants;
|
||||||
fn it_works() {
|
|
||||||
}
|
|
||||||
|
|
23
libimagutil/src/variants.rs
Normal file
23
libimagutil/src/variants.rs
Normal file
|
@ -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<A, B, C, F>(base: A, modders: Vec<B>, f: &F)
|
||||||
|
-> Vec<C>
|
||||||
|
where
|
||||||
|
F: Fn(&A, B) -> C
|
||||||
|
{
|
||||||
|
modders.into_iter().map(|m| f(&base, m)).collect()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue