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