leptos-use/src/math/use_min.rs

34 lines
1.1 KiB
Rust
Raw Normal View History

2023-06-03 14:58:30 +01:00
use crate::math::shared::use_partial_cmp;
2024-05-07 12:41:44 +01:00
use leptos::prelude::*;
2024-09-02 14:39:22 +01:00
use leptos::reactive_graph::wrappers::read::Signal;
2023-06-03 14:58:30 +01:00
use std::cmp::Ordering;
use_partial_cmp!(
/// Reactive `min()`.
///
/// Works with any container that implements `IntoIterator` (`Vec`, `HashSet`, ...)
/// with any elements that implement `PartialOrd` and `Clone` (floats, ints, strings, ...).
///
/// If the container is empty or only contains non comparable values like `NaN`, it returns `None`.
/// Otherwise it returns the `Some(<smallest value>)` in the container.
///
/// ## Usage
///
/// ```
2024-05-07 12:41:44 +01:00
/// # use leptos::prelude::*;
2023-06-03 14:58:30 +01:00
/// # use leptos_use::math::use_min;
/// #
/// # #[component]
2023-07-27 18:06:36 +01:00
/// # fn Demo() -> impl IntoView {
2024-05-07 12:41:44 +01:00
/// let (values, set_values) = signal(vec![1.0, 2.0, 3.0, f32::NAN, 4.0, 5.0]);
2023-07-27 18:06:36 +01:00
/// let result = use_min::<Vec<f32>, _, _>(values); // Some(1.0)
2023-06-03 14:58:30 +01:00
/// #
/// # assert_eq!(result.get(), Some(1.0));
2023-07-27 18:06:36 +01:00
/// # view! { }
2023-06-03 14:58:30 +01:00
/// # }
/// ```
// #[doc(cfg(feature = "math"))]
2023-06-03 14:58:30 +01:00
use_min,
Ordering::Greater
);