Down α reverses the ordering of α.
If $a \leq b$ in α, then $\text{Down}(b) \leq \text{Down}(a)$.
Useful for sorting in descending order without custom comparators.
$$\text{compare}_{\text{Down}}(x, y) = \text{compare}(y, x)$$
- getDown : α
Unwrap the reversed-order value.
Instances For
Equations
- Data.instReprDown.repr x✝ prec✝ = Std.Format.bracket "{ " (Std.Format.nil ++ Std.Format.text "getDown" ++ Std.Format.text " := " ++ (Std.Format.nest 11 (repr x✝.getDown)).group) " }"
Instances For
Equations
- Data.instReprDown = { reprPrec := Data.instReprDown.repr }
Equations
Compare two values by first applying a projection function. $$\text{comparing}(f, x, y) = \text{compare}(f(x), f(y))$$
Useful with sorting: list.mergeSort (comparing SomeStruct.field)
Equations
- Data.comparing f x y = compare (f x) (f y)
Instances For
Clamp a value to the interval $[\text{lo}, \text{hi}]$.
Returns a subtype proving the result lies within bounds: $$\text{clamp}(x, lo, hi) = \begin{cases} lo & \text{if } x \leq lo \\ hi & \text{if } x \geq hi \\ x & \text{otherwise} \end{cases}$$
Precondition: lo ≤ hi (provided as proof).
Guarantee: The returned value y satisfies lo ≤ y ∧ y ≤ hi.