typelevel / algebra
 1 ```package algebra ``` 2 ```package lattice ``` 3 4 ```import scala.{specialized => sp} ``` 5 6 ```/** ``` 7 ``` * A distributive lattice a lattice where join and meet distribute: ``` 8 ``` * ``` 9 ``` * - a ∨ (b ∧ c) = (a ∨ b) ∧ (a ∨ c) ``` 10 ``` * - a ∧ (b ∨ c) = (a ∧ b) ∨ (a ∧ c) ``` 11 ``` */ ``` 12 ```trait DistributiveLattice[@sp(Int, Long, Float, Double) A] extends Any with Lattice[A] ``` 13 14 ```object DistributiveLattice extends JoinSemilatticeFunctions[DistributiveLattice] with MeetSemilatticeFunctions[DistributiveLattice] { ``` 15 16 ``` /** ``` 17 ``` * Access an implicit `Lattice[A]`. ``` 18 ``` */ ``` 19 ``` @inline final def apply[@sp(Int, Long, Float, Double) A](implicit ev: DistributiveLattice[A]): DistributiveLattice[A] = ev ``` 20 21 ``` def minMax[@sp(Int, Long, Float, Double) A: Order]: DistributiveLattice[A] = ``` 22 2 ``` new MinMaxLattice[A] ``` 23 ```} ``` 24 25 ```class MinMaxLattice[@sp(Int, Long, Float, Double) A](implicit order: Order[A]) extends DistributiveLattice[A] { ``` 26 2 ``` def join(x: A, y: A): A = order.max(x, y) ``` 27 2 ``` def meet(x: A, y: A): A = order.min(x, y) ``` 28 ```} ```

Read our documentation on viewing source code .