util: Add variant-generator utility

This commit is contained in:
Matthias Beyer 2016-01-17 20:08:27 +01:00
parent a8bc18d39a
commit be6a0b8b78
2 changed files with 24 additions and 3 deletions

View file

@ -1,3 +1 @@
#[test]
fn it_works() {
}
pub mod variants;

View 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()
}