leptos_use/math/
use_min.rs

1use crate::math::shared::use_partial_cmp;
2use leptos::prelude::*;
3use leptos::reactive::wrappers::read::Signal;
4use std::cmp::Ordering;
5
6use_partial_cmp!(
7    /// Reactive `min()`.
8    ///
9    /// Works with any container that implements `IntoIterator` (`Vec`, `HashSet`, ...)
10    /// with any elements that implement `PartialOrd` and `Clone` (floats, ints, strings, ...).
11    ///
12    /// If the container is empty or only contains non comparable values like `NaN`, it returns `None`.
13    /// Otherwise it returns the `Some(<smallest value>)` in the container.
14    ///
15    /// ## Usage
16    ///
17    /// ```
18    /// # use leptos::prelude::*;
19    /// # use leptos_use::math::use_min;
20    /// #
21    /// # #[component]
22    /// # fn Demo() -> impl IntoView {
23    /// let (values, set_values) = signal(vec![1.0, 2.0, 3.0, f32::NAN, 4.0, 5.0]);
24    /// let result = use_min::<Vec<f32>, _, _>(values); // Some(1.0)
25    /// #
26    /// # assert_eq!(result.get(), Some(1.0));
27    /// # view! { }
28    /// # }
29    /// ```
30    // #[doc(cfg(feature = "math"))]
31    use_min,
32    Ordering::Greater
33);