Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,15 @@ class Tests extends TestsConfig with DisciplineSuite {
checkAll("BoundedEnumerable[Int]", BoundedEnumerableTests[Int].boundedEnumerable)
checkAll("BoundedEnumerable[Char]", BoundedEnumerableTests[Char].boundedEnumerable)
checkAll("BoundedEnumerable[Long]", BoundedEnumerableTests[Long].boundedEnumerable)
checkAll("BoundedEnumerable.reverse(BoundedEnumerable[Int])",
BoundedEnumerableTests(BoundedEnumerable.reverse(BoundedEnumerable[Int])).boundedEnumerable
)
checkAll(
"BoundedEnumerable.reverse(BoundedEnumerable.reverse(BoundedEnumerable[Int]))",
BoundedEnumerableTests(
BoundedEnumerable.reverse(BoundedEnumerable.reverse(BoundedEnumerable[Int]))
).boundedEnumerable
)

checkAll("Monoid[String]", MonoidTests[String].monoid)
checkAll("Monoid[String]", SerializableTests.serializable(Monoid[String]))
Expand Down
15 changes: 15 additions & 0 deletions kernel/src/main/scala/cats/kernel/Enumerable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ object BoundedEnumerable {
cats.kernel.instances.char.catsKernelStdOrderForChar

@inline def apply[A](implicit e: BoundedEnumerable[A]): BoundedEnumerable[A] = e

/**
* Defines a `BoundedEnumerable[A]` from the given enumerable such that
* all arrows / successor functions switch direction.
*/
def reverse[@sp A](e: BoundedEnumerable[A]): BoundedEnumerable[A] =
new BoundedEnumerable[A] {
override def order: Order[A] = Order.reverse(e.order)

override def partialNext(a: A): Option[A] = e.partialPrevious(a)
override def partialPrevious(a: A): Option[A] = e.partialNext(a)

override def minBound: A = e.maxBound
override def maxBound: A = e.minBound
}
}

trait LowerBoundedEnumerable[@sp A] extends PartialNextLowerBounded[A] with Next[A] {
Expand Down