Skip to content
Snippets Groups Projects
Select Git revision
  • f29e88834301de61909122fa739b0ebba706b562
  • main default protected
  • add_export_route
  • add_route_assignments
  • 4.1.0-dev
  • 4.0.0
  • 3.5.3
  • 3.5.3-dev
  • 3.5.2
  • 3.5.2-dev
  • 3.5.1
  • 3.5.1-dev
  • 3.5.0
  • 3.4.2
  • 3.4.1
  • 3.4.0
  • 3.3.0
  • 3.2.0
  • 3.1.3
  • 3.1.2
  • 3.1.1
  • 3.1.0
  • 3.0.1
  • 3.0.0
24 results

AssignmentRoutes.ts

Blame
  • Forked from Dojo Project (HES-SO) / Projects / Backend / DojoBackendAPI
    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