Struct prop_check_rs::rng::RNG
source · pub struct RNG { /* private fields */ }Implementations§
source§impl RNG
impl RNG
pub fn new_with_seed(seed: u64) -> Self
pub fn f32_i32(&self) -> ((f32, i32), Self)
pub fn f32_3(&self) -> ((f32, f32, f32), Self)
pub fn i32s(self, count: u32) -> (Vec<i32>, Self)
sourcepub fn unit<A>(a: A) -> Box<dyn FnMut(RNG) -> (A, RNG)>where
A: Clone + 'static,
pub fn unit<A>(a: A) -> Box<dyn FnMut(RNG) -> (A, RNG)>where
A: Clone + 'static,
Examples found in repository?
src/rng.rs (line 228)
224 225 226 227 228 229 230 231 232 233 234 235 236
pub fn sequence<A, F>(fs: Vec<F>) -> BoxRand<Vec<A>>
where
A: Clone + 'static,
F: FnMut(RNG) -> (A, RNG) + 'static, {
let unit = Self::unit(Vec::<A>::new());
let result = fs.into_iter().fold(unit, |acc, e| {
Self::map2(acc, e, |mut a, b| {
a.push(b);
a
})
});
result
}pub fn sequence<A, F>(fs: Vec<F>) -> Box<dyn FnMut(RNG) -> (Vec<A>, RNG)>where
A: Clone + 'static,
F: FnMut(RNG) -> (A, RNG) + 'static,
pub fn map<A, B, F1, F2>(s: F1, f: F2) -> Box<dyn FnMut(RNG) -> (B, RNG)>where
F1: FnMut(RNG) -> (A, RNG) + 'static,
F2: FnMut(A) -> B + 'static,
sourcepub fn map2<F1, F2, F3, A, B, C>(
ra: F1,
rb: F2,
f: F3
) -> Box<dyn FnMut(RNG) -> (C, RNG)>where
F1: FnMut(RNG) -> (A, RNG) + 'static,
F2: FnMut(RNG) -> (B, RNG) + 'static,
F3: FnMut(A, B) -> C + 'static,
pub fn map2<F1, F2, F3, A, B, C>(
ra: F1,
rb: F2,
f: F3
) -> Box<dyn FnMut(RNG) -> (C, RNG)>where
F1: FnMut(RNG) -> (A, RNG) + 'static,
F2: FnMut(RNG) -> (B, RNG) + 'static,
F3: FnMut(A, B) -> C + 'static,
Examples found in repository?
src/rng.rs (lines 230-233)
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
pub fn sequence<A, F>(fs: Vec<F>) -> BoxRand<Vec<A>>
where
A: Clone + 'static,
F: FnMut(RNG) -> (A, RNG) + 'static, {
let unit = Self::unit(Vec::<A>::new());
let result = fs.into_iter().fold(unit, |acc, e| {
Self::map2(acc, e, |mut a, b| {
a.push(b);
a
})
});
result
}
pub fn int_value() -> BoxRand<i32> {
Box::new(move |rng| rng.next_i32())
}
pub fn double_value() -> BoxRand<f32> {
Box::new(move |rng| rng.next_f32())
}
pub fn map<A, B, F1, F2>(mut s: F1, mut f: F2) -> BoxRand<B>
where
F1: FnMut(RNG) -> (A, RNG) + 'static,
F2: FnMut(A) -> B + 'static, {
Box::new(move |rng| {
let (a, rng2) = s(rng);
(f(a), rng2)
})
}
pub fn map2<F1, F2, F3, A, B, C>(mut ra: F1, mut rb: F2, mut f: F3) -> BoxRand<C>
where
F1: FnMut(RNG) -> (A, RNG) + 'static,
F2: FnMut(RNG) -> (B, RNG) + 'static,
F3: FnMut(A, B) -> C + 'static, {
Box::new(move |rng| {
let (a, r1) = ra(rng);
let (b, r2) = rb(r1);
(f(a, b), r2)
})
}
pub fn both<F1, F2, A, B>(ra: F1, rb: F2) -> BoxRand<(A, B)>
where
F1: FnMut(RNG) -> (A, RNG) + 'static,
F2: FnMut(RNG) -> (B, RNG) + 'static, {
Self::map2(ra, rb, |a, b| (a, b))
}