-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathCatsSyntaxTest.scala
46 lines (39 loc) · 1.2 KB
/
CatsSyntaxTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.olegpy.bm4
import cats.Monad
import org.scalatest.freespec.AnyFreeSpec
import cats.implicits._
class CatsSyntaxTest extends AnyFreeSpec {
implicit val mcCatsInstance: cats.FlatMap[MapCheck] = new cats.FlatMap[MapCheck] {
def flatMap[A, B](fa: MapCheck[A])(f: A => MapCheck[B]): MapCheck[B] = {
fa.flatMap(f)
}
def tailRecM[A, B](a: A)(f: A => MapCheck[Either[A, B]]): MapCheck[B] = {
fail()
}
def map[A, B](fa: MapCheck[A])(f: A => B): MapCheck[B] = fa.map(f)
}
case class ImplicitTest(id: String)
def typed[A](a: A) = ()
"works in generic context with extension methods of cats" in {
import cats.syntax.all._
def sillyTest[F[_]: cats.FlatMap](fa: F[Int], fb: F[Int]) =
for {
_ <- fa
b <- fb
} yield b
sillyTest(new MapCheck(11), new MapCheck(42))
}
"supports implicit0 in F-parametric methods" - {
"in = bindings" in {
def f[F[_]: Monad] =
for {
x <- 42.pure[F]
_ <- "dummy".pure[F]
implicit0(it: ImplicitTest) = ImplicitTest("eggs")
str = "dummy"
_ = typed[String](str)
} yield assert(it eq implicitly[ImplicitTest])
f[Option]
}
}
}