Skip to content

Commit

Permalink
Add missing factories similar to existing factories (#2889)
Browse files Browse the repository at this point in the history
Fixes #2887
  • Loading branch information
morgen-peschke authored and kailuowang committed Jul 1, 2019
1 parent b663604 commit 6d29f7b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 0 deletions.
7 changes: 7 additions & 0 deletions kernel/src/main/scala/cats/kernel/Band.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@ object Band extends SemigroupFunctions[Band] {
* Access an implicit `Band[A]`.
*/
@inline final def apply[@sp(Int, Long, Float, Double) A](implicit ev: Band[A]): Band[A] = ev

/**
* Create a `Band` instance from the given function.
*/
@inline def instance[A](cmb: (A, A) => A): Band[A] = new Band[A] {
override def combine(x: A, y: A): A = cmb(x, y)
}
}
9 changes: 9 additions & 0 deletions kernel/src/main/scala/cats/kernel/BoundedSemilattice.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,13 @@ object BoundedSemilattice extends SemilatticeFunctions[BoundedSemilattice] {
*/
@inline final def apply[@sp(Int, Long, Float, Double) A](implicit ev: BoundedSemilattice[A]): BoundedSemilattice[A] =
ev

/**
* Create a `BoundedSemilattice` instance from the given function and empty value.
*/
@inline def instance[A](emptyValue: A, cmb: (A, A) => A): BoundedSemilattice[A] = new BoundedSemilattice[A] {
override val empty: A = emptyValue

override def combine(x: A, y: A): A = cmb(x, y)
}
}
9 changes: 9 additions & 0 deletions kernel/src/main/scala/cats/kernel/CommutativeMonoid.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,13 @@ object CommutativeMonoid extends MonoidFunctions[CommutativeMonoid] {
* Access an implicit `CommutativeMonoid[A]`.
*/
@inline final def apply[A](implicit ev: CommutativeMonoid[A]): CommutativeMonoid[A] = ev

/**
* Create a `CommutativeMonoid` instance from the given function and empty value.
*/
@inline def instance[A](emptyValue: A, cmb: (A, A) => A): CommutativeMonoid[A] = new CommutativeMonoid[A] {
override val empty: A = emptyValue

override def combine(x: A, y: A): A = cmb(x, y)
}
}
7 changes: 7 additions & 0 deletions kernel/src/main/scala/cats/kernel/CommutativeSemigroup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ object CommutativeSemigroup extends SemigroupFunctions[CommutativeSemigroup] {
* Access an implicit `CommutativeSemigroup[A]`.
*/
@inline final def apply[A](implicit ev: CommutativeSemigroup[A]): CommutativeSemigroup[A] = ev

/**
* Create a `CommutativeSemigroup` instance from the given function.
*/
@inline def instance[A](cmb: (A, A) => A): CommutativeSemigroup[A] = new CommutativeSemigroup[A] {
override def combine(x: A, y: A): A = cmb(x, y)
}
}
9 changes: 9 additions & 0 deletions kernel/src/main/scala/cats/kernel/Monoid.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,13 @@ object Monoid extends MonoidFunctions[Monoid] {
* Access an implicit `Monoid[A]`.
*/
@inline final def apply[A](implicit ev: Monoid[A]): Monoid[A] = ev

/**
* Create a `Monoid` instance from the given function and empty value.
*/
@inline def instance[A](emptyValue: A, cmb: (A, A) => A): Monoid[A] = new Monoid[A] {
override val empty: A = emptyValue

override def combine(x: A, y: A): A = cmb(x, y)
}
}
7 changes: 7 additions & 0 deletions kernel/src/main/scala/cats/kernel/Semilattice.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,11 @@ object Semilattice extends SemilatticeFunctions[Semilattice] {
* Access an implicit `Semilattice[A]`.
*/
@inline final def apply[@sp(Int, Long, Float, Double) A](implicit ev: Semilattice[A]): Semilattice[A] = ev

/**
* Create a `Semilattice` instance from the given function.
*/
@inline def instance[A](cmb: (A, A) => A): Semilattice[A] = new Semilattice[A] {
override def combine(x: A, y: A): A = cmb(x, y)
}
}

0 comments on commit 6d29f7b

Please sign in to comment.