-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #676 from matwojcik/example-functor
Add map and functor instance for Example
- Loading branch information
Showing
6 changed files
with
47 additions
and
4 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
10 changes: 10 additions & 0 deletions
10
integrations/cats/src/main/scala/sttp/tapir/integ/cats/ExampleInstances.scala
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,10 @@ | ||
package sttp.tapir.integ.cats | ||
|
||
import cats.Functor | ||
import sttp.tapir.EndpointIO.Example | ||
|
||
trait ExampleInstances { | ||
implicit val exampleFunctor: Functor[Example] = new Functor[Example] { | ||
override def map[A, B](example: Example[A])(f: A => B): Example[B] = example.map(f) | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
integrations/cats/src/main/scala/sttp/tapir/integ/cats/instances.scala
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 @@ | ||
package sttp.tapir.integ.cats | ||
|
||
object instances extends ExampleInstances |
25 changes: 25 additions & 0 deletions
25
integrations/cats/src/test/scala/sttp/tapir/integ/cats/ExampleFunctorLawSpec.scala
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,25 @@ | ||
package sttp.tapir.integ.cats | ||
|
||
import cats.Eq | ||
import cats.laws.discipline.FunctorTests | ||
import org.scalacheck.Arbitrary | ||
import org.scalatest.funsuite.AnyFunSuite | ||
import org.scalatestplus.scalacheck.Checkers | ||
import org.typelevel.discipline.scalatest.FunSuiteDiscipline | ||
import sttp.tapir.EndpointIO.Example | ||
import sttp.tapir.integ.cats.instances._ | ||
|
||
class ExampleFunctorLawSpec extends AnyFunSuite with FunSuiteDiscipline with Checkers { | ||
implicit def exampleEq[A]: Eq[Example[A]] = Eq.fromUniversalEquals | ||
|
||
implicit def exampleArbitrary[T: Arbitrary]: Arbitrary[Example[T]] = Arbitrary { | ||
for { | ||
t <- Arbitrary.arbitrary[T] | ||
name <- Arbitrary.arbitrary[Option[String]] | ||
summary <- Arbitrary.arbitrary[Option[String]] | ||
} yield Example(t, name, summary) | ||
} | ||
|
||
checkAll("Example.FunctorLaws", FunctorTests[Example].functor[Int, Int, String]) | ||
} | ||
|
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