-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
e88eb0e
commit 069ae69
Showing
7 changed files
with
247 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package schemes | ||
|
||
import cats.{ ~>, Monad, Traverse } | ||
import cats.free.Cofree | ||
|
||
/* Check that usages of extension methods compile */ | ||
object SyntaxSpec { | ||
def mock[A]: A = ??? | ||
|
||
def testAnySyntax[F[_]: Traverse, M[_]: Monad, A, B]: Unit = { | ||
val a = mock[A] | ||
val coalgebra = mock[A => F[A]] | ||
val coalgebraM = mock[A => M[F[A]]] | ||
val algebra = mock[F[B] => B] | ||
val algebraM = mock[F[B] => M[B]] | ||
val natTrans = mock[F ~> F] | ||
val elgotCoalgebra = mock[A => Either[B, F[A]]] | ||
val elgotAlgebra = mock[(A, () => F[B]) => B] | ||
val rCoalgebra = mock[A => F[Either[Fix[F], A]]] | ||
a.ana(coalgebra) | ||
a.anaM(coalgebraM) | ||
a.hylo(coalgebra, algebra) | ||
a.hyloM(coalgebraM, algebraM) | ||
a.postpro(coalgebra, natTrans) | ||
a.elgot(elgotCoalgebra, algebra) | ||
a.coelgot(coalgebra, elgotAlgebra) | ||
a.apo(rCoalgebra) | ||
() | ||
} | ||
|
||
def testFixSyntax[F[_]: Traverse, M[_]: Monad, A, B]: Unit = { | ||
val fix = mock[Fix[F]] | ||
val algebra = mock[F[B] => B] | ||
val algebraM = mock[F[B] => M[B]] | ||
val natTrans = mock[F ~> F] | ||
val cvAlgebra = mock[F[Cofree[F, A]] => A] | ||
fix.unfix | ||
fix.cata(algebra) | ||
fix.cataM(algebraM) | ||
fix.prepro(natTrans, algebra) | ||
fix.histo(cvAlgebra) | ||
() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package schemes | ||
package data | ||
|
||
import cats.laws.discipline._ | ||
import cats.tests.CatsSuite | ||
import org.scalacheck.{ Arbitrary, Gen } | ||
import org.scalacheck.Arbitrary.arbitrary | ||
|
||
class ListFSpec extends CatsSuite { | ||
implicit def arbListF[A, B](implicit A: Arbitrary[A], B: Arbitrary[B]): Arbitrary[ListF[A, B]] = | ||
Arbitrary(Gen.oneOf( | ||
Gen.const(NilF[A, B]()), | ||
for { | ||
a <- arbitrary[A] | ||
b <- arbitrary[B] | ||
} yield ConsF(a, b))) | ||
|
||
checkAll("ListF[Int, Int]", TraverseTests[ListF[Int, ?]].traverse[Int, Int, Int, Set[Int], Option, Option]) | ||
|
||
val list = List(1, 2, 3, 4, 5) | ||
val listF = ListF(1 to 5: _*) | ||
|
||
test("ListF.apply") { | ||
listF shouldBe ListF.cons(1, ListF.cons(2, ListF.cons(3, ListF.cons(4, ListF.cons(5, ListF.nil[Int]))))) | ||
} | ||
|
||
test("ListF.toList") { | ||
ListF.toList(listF) shouldBe list | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This is the API documentation for [[https://davidgregory084.github.io/schemes/ schemes]], a Scala library which provides utilities for working with recursion schemes. | ||
|
||
Please refer to the [[https://davidgregory084.github.io/schemes/ documentation]] for further explanation and usage examples. |