typelevel / algebra
1
package algebra
2
package lattice
3

4
import scala.{specialized => sp}
5

6
/**
7
 * A join-semilattice (or upper semilattice) is a semilattice whose
8
 * operation is called "join", and which can be thought of as a least
9
 * upper bound.
10
 */
11
trait JoinSemilattice[@sp(Int, Long, Float, Double) A] extends Any with Serializable { self =>
12
  def join(lhs: A, rhs: A): A
13

14
  def joinSemilattice: Semilattice[A] =
15 0
    new Semilattice[A] {
16 0
      def combine(x: A, y: A): A = self.join(x, y)
17
    }
18

19
  def joinPartialOrder(implicit ev: Eq[A]): PartialOrder[A] =
20 0
    joinSemilattice.asJoinPartialOrder
21
}
22

23
trait JoinSemilatticeFunctions[J[A] <: JoinSemilattice[A]] {
24
  def join[@sp(Int, Long, Float, Double) A](x: A, y: A)(implicit ev: J[A]): A =
25 0
    ev.join(x, y)
26
}
27

28
object JoinSemilattice extends JoinSemilatticeFunctions[JoinSemilattice] {
29

30
  /**
31
   * Access an implicit `JoinSemilattice[A]`.
32
   */
33
  @inline final def apply[@sp(Int, Long, Float, Double) A](implicit ev: JoinSemilattice[A]): JoinSemilattice[A] = ev
34

35
}

Read our documentation on viewing source code .

Loading