mirror of
https://github.com/adoyle0/leptos-use.git
synced 2025-03-14 01:19:50 -04:00
32 lines
1,009 B
Rust
32 lines
1,009 B
Rust
|
use crate::math::shared::use_partial_cmp;
|
||
|
use leptos::*;
|
||
|
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
|
||
|
///
|
||
|
/// ```
|
||
|
/// # use leptos::*;
|
||
|
/// # use leptos_use::math::use_min;
|
||
|
/// #
|
||
|
/// # #[component]
|
||
|
/// # fn Demo(cx: Scope) -> impl IntoView {
|
||
|
/// let (values, set_values) = create_signal(cx, vec![1.0, 2.0, 3.0, f32::NAN, 4.0, 5.0]);
|
||
|
/// let result = use_min::<Vec<f32>, _, _>(cx, values); // Some(1.0)
|
||
|
/// #
|
||
|
/// # assert_eq!(result.get(), Some(1.0));
|
||
|
/// # view! { cx, }
|
||
|
/// # }
|
||
|
/// ```
|
||
|
use_min,
|
||
|
Ordering::Greater
|
||
|
);
|