Skip to main content

when

Function when 

Source
pub fn when<T, F>(
    condition: &Behavior<bool>,
    then_value: F,
) -> Behavior<Option<T>>
where T: IntoGeometric + FromGeometric + Clone + Default + 'static, F: Fn() -> T + 'static,
Expand description

Conditional combinator - select between values based on a condition

Creates a behavior that follows the value of then_value when condition is true, otherwise it holds None.

ยงExample

use cliffy_core::{behavior, when};

let show_message = behavior(true);
let message = when(&show_message, || "Hello!".to_string());

assert_eq!(message.sample(), Some("Hello!".to_string()));

show_message.set(false);
assert_eq!(message.sample(), None);