Function contrafact::lambda
source · pub fn lambda<'a, S, T>(
label: impl ToString,
state: S,
f: impl 'a + Send + Sync + Fn(&mut Generator<'a>, &mut S, T) -> Mutation<T>
) -> Lambda<'a, S, T>where
S: State,
T: Target<'a>,
Expand description
Create a fact from a bare function which specifies the mutation.
Can be quicker to experiment with ideas this way than to have to directly implement
the Fact
trait
use contrafact::*;
let mut g = utils::random_generator();
let mut fact = vec_of_length(
4,
lambda("geometric series", 2, move |g, s, mut v| {
g.set(&mut v, s, || "value is not geometrically increasing by 2")?;
*s *= 2;
Ok(v)
}),
);
let list = fact.clone().build(&mut g);
fact.check(&list).unwrap();
assert_eq!(list, vec![2, 4, 8, 16]);