Welcome! Got a question? Do you have -Ypartial-unification turned on? Other FAQs: http://typelevel.org/cats/faq.html
private val middleware: HttpRoutes[F] => HttpRoutes[F] = {
{ http: HttpRoutes[F] =>
AutoSlash(http) // removes trailing slashes
} andThen { http: HttpRoutes[F] =>
CORS(http, CORS.DefaultCORSConfig)
} andThen { http: HttpRoutes[F] =>
Timeout(60.seconds)(http)
}
}
private val loggers: HttpApp[F] => HttpApp[F] = {
{ http: HttpApp[F] =>
RequestLogger.httpApp(true, true)(http)
} andThen { http: HttpApp[F] =>
ResponseLogger.httpApp(true, true)(http)
}
}
val httpApp: HttpApp[F] = loggers(middleware(routes).orNotFound)
Eq
instance for a parameterized type: https://scastie.scala-lang.org/UknDiddWSLul5NTLoMr7zAimport cats.Eq
final case class Thing[A](a: A)
object Thing {
implicit def eqThing[I: Eq]: Eq[Thing[I]] = Eq.fromUniversalEquals
}
parameter value evidence$1 in method eqThing is never used
Eq[I]
, but you don't use that knowledge - you delegate to a method that constructs an Eq instance without any knowledge of the underlying type: https://github.com/typelevel/cats/blob/main/kernel/src/main/scala/cats/kernel/Eq.scala#L106
Eq.instance
and in it you can use the Eq[I]
instance
I: Eq
syntax)
in this case you just want to delegate - what does it mean for two Thing[I]
to be equal? for their thing.a
to be equal.
And you have the Eq[I]
instance to compare just the a
s
implicit def eqThing[I: Eq]: Eq[Thing[I]]
This says "If I know how to check equality of things of type I
, I can also check equality of things of type Thing[I]
"
You just need to use Eq.instance
to wire things together
Eq.by
which is even simpler
implicit def eqThing[I: Eq]: Eq[Thing[I]] = Eq.by(_.a)
something like this
IO
is more modern than Haskell's