-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cats | ||
package data | ||
|
||
import cats.arrow.Profunctor | ||
|
||
final case class Binested[F[_, _], G[_], H[_], A, B](value: F[G[A], H[B]]) | ||
|
||
object Binested { | ||
implicit def catsDataEqForBinested[F[_, _], G[_], H[_], A, B](implicit F: Eq[F[G[A], H[B]]]): Eq[Binested[F, G, H, A, B]] = | ||
Eq.by(_.value) | ||
|
||
implicit def catsDataBifunctorForBinested[F[_, _], G[_], H[_]]( | ||
implicit F: Bifunctor[F], G: Functor[G], H: Functor[H]) = | ||
new Bifunctor[λ[(ɑ, β) => Binested[F, G, H, ɑ, β]]] { | ||
def bimap[A, B, C, D](fab: Binested[F, G, H, A, B])(f: A => C, g: B => D): Binested[F, G, H, C, D] = | ||
Binested(F.bimap(fab.value)(G.map(_)(f), H.map(_)(g))) | ||
} | ||
|
||
implicit def catsDataProfunctorForBinested[F[_, _], G[_], H[_]]( | ||
implicit F: Profunctor[F], G: Functor[G], H: Functor[H]) = | ||
new Profunctor[λ[(ɑ, β) => Binested[F, G, H, ɑ, β]]] { | ||
def dimap[A, B, C, D](fab: Binested[F, G, H, A, B])(f: C => A)(g: B => D): Binested[F, G, H, C, D] = | ||
Binested(F.dimap(fab.value)(G.map(_: G[C])(f))(H.map(_)(g))) | ||
} | ||
} |
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,31 @@ | ||
package cats | ||
package tests | ||
|
||
import cats.arrow.Profunctor | ||
import cats.data.Binested | ||
|
||
import cats.laws.discipline._ | ||
import cats.laws.discipline.arbitrary._ | ||
import cats.laws.discipline.eq._ | ||
|
||
class BinestedSuite extends CatsSuite { | ||
// we have a lot of generated lists of lists in these tests. We have to tell | ||
// Scalacheck to calm down a bit so we don't hit memory and test duration | ||
// issues. | ||
implicit override val generatorDrivenConfig: PropertyCheckConfiguration = | ||
PropertyCheckConfiguration(minSuccessful = 20, sizeRange = 5) | ||
|
||
{ | ||
// Bifunctor + Functor + Functor = Bifunctor | ||
implicit val instance = ListWrapper.functor | ||
checkAll("Binested[Either, ListWrapper, Option, ?, ?]", BifunctorTests[Binested[Either, ListWrapper, Option, ?, ?]].bifunctor[Int, Int, Int, String, String, String]) | ||
checkAll("Bifunctor[Binested[Either, ListWrapper, Option, ?, ?]]", SerializableTests.serializable(Bifunctor[Binested[Either, ListWrapper, Option, ?, ?]])) | ||
} | ||
|
||
{ | ||
// Profunctor + Functor + Functor = Profunctor | ||
implicit val instance = ListWrapper.functor | ||
checkAll("Binested[Function1, ListWrapper, Option, ?, ?]", ProfunctorTests[Binested[Function1, ListWrapper, Option, ?, ?]].profunctor[Int, Int, Int, String, String, String]) | ||
checkAll("Profunctor[Binested[Function1, ListWrapper, Option, ?, ?]]", SerializableTests.serializable(Profunctor[Binested[Function1, ListWrapper, Option, ?, ?]])) | ||
} | ||
} |