Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing factories similar to existing factories #2889

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -101,4 +101,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)
}
}