use crate::simulation::parameter::*;
use dvcompute_utils::grc::Grc;
#[must_use = "computations are lazy and do nothing unless to be run"]
#[derive(Clone)]
pub struct ParameterFn<T> where T: 'static {
gen: Grc<Box<dyn Fn() -> ParameterBox<T>>>
}
impl<T> ParameterFn<T> {
#[inline]
pub fn new<F, M>(f: F) -> Self
where F: Fn() -> M + 'static,
M: Parameter<Item = T> + 'static
{
ParameterFn {
gen: Grc::new(Box::new(move || { f().into_boxed() }))
}
}
#[inline]
pub fn next(&self) -> ParameterBox<T> {
(self.gen)()
}
}