use lubeck::common::reader::Reader; use lubeck::common::transformer::optiont::OptionT; use lubeck::prelude::Applicative; use lubeck::prelude::Functor; use lubeck::prelude::Monad; #[derive(Clone)] pub struct Config { is_on: bool, } #[derive(Debug)] pub struct Voltage(pub f32); type ConfigMaybe<'a, T> = OptionT, T>; fn main() { { // very simplistic example let create_configurable_volt_calculation_pipeline = || { let configurable_one_volt = ConfigMaybe::::pure(Voltage(1.0)); let configurable_three_volt = configurable_one_volt.fmap(|Voltage(v)| Voltage(v + 2.0)); let double_if_on = move |Voltage(v)| -> ConfigMaybe { let reader_opt_f = move |config: Config| { if config.is_on { Some(Voltage(v * 2.0)) } else { None } }; ConfigMaybe::new(reader_opt_f) }; configurable_three_volt.bind(double_if_on) }; println!( "With switch disabled: {:?}", create_configurable_volt_calculation_pipeline().run(Config { is_on: false }) ); println!( "With switch enabled: {:?}", create_configurable_volt_calculation_pipeline().run(Config { is_on: true }) ); } }