Skip to content
Snippets Groups Projects
Select Git revision
  • 88d10ca5d2084f94f70c51664b210156139fb8da
  • main default protected
  • add_export_route
  • add_route_assignments
  • add_route_user
  • 4.1.0-dev
  • Pre-alpha
  • 4.0.1
  • Latest
  • 4.0.0
  • 3.5.0
  • 3.4.2
  • 3.4.1
  • 3.3.0
  • 3.2.3
  • 3.2.2
  • 3.2.0
  • 3.1.2
  • 3.1.1
  • 3.1.0
  • 3.0.1
  • 3.0.0
  • 2.2.0
  • 2.1.0
  • 2.0.0
25 results

CommanderApp.ts

Blame
  • Forked from Dojo Project (HES-SO) / Projects / UI / DojoCLI
    Source project has a limited visibility.
    binary_operator.rs 1.71 KiB
    // ANCHOR: binary_operator
    pub type BinaryOperator<T> = fn(T, T) -> T;
    // ANCHOR_END: binary_operator
    
    /// Returns a closure that computes the minimum
    /// between two elements of type T.
    /// # Example
    ///
    /// ```
    /// # use part08::binary_operator::{minimum_operator};
    /// # fn main() {
    /// let f = minimum_operator();
    /// assert!(f(1,2) == 1);
    /// # }
    /// ```
    // ANCHOR: minimum_operator
    pub fn minimum_operator<T: PartialOrd>() -> BinaryOperator<T> {
        |x: T, y: T| if x <= y { x } else { y }
    }
    // ANCHOR_END: minimum_operator
    
    /// Returns a closure that computes the maximum
    /// between two elements of type T.
    /// # Example
    ///
    /// ```
    /// # use part08::binary_operator::{maximum_operator};
    /// # fn main() {
    /// let f = maximum_operator();
    /// assert!(f(1,2) == 2);
    /// # }
    /// ```
    // ANCHOR: maximum_operator
    pub fn maximum_operator<T: PartialOrd>() -> BinaryOperator<T> {
        |x: T, y: T| if x >= y { x } else { y }
    }
    // ANCHOR_END: maximum_operator
    
    /// Returns a closure that computes the sum
    /// of two elements of type T.
    /// # Example
    ///
    /// ```
    /// # use part08::binary_operator::{sum_operator};
    /// # fn main() {
    /// let f = sum_operator();
    /// assert!(f(1,2) == 3);
    /// # }
    /// ```
    // ANCHOR: sum_operator
    pub fn sum_operator<T: std::ops::Add<Output = T>>() -> BinaryOperator<T> {
        |x: T, y: T| x + y
    }
    // ANCHOR_END: sum_operator
    
    /// Returns a closure that computes the product
    /// of two elements of type T.
    /// # Example
    ///
    /// ```
    /// # use part08::binary_operator::{mul_operator};
    /// # fn main() {
    /// let f = mul_operator();
    /// assert!(f(1,2) == 2);
    /// # }
    /// ```
    // ANCHOR: mul_operator
    pub fn mul_operator<T: std::ops::Mul<Output = T>>() -> BinaryOperator<T> {
        |x: T, y: T| x * y
    }
    // ANCHOR_END: mul_operator