Automatic type class derivation for cats | Currently 1.1.1 | Code of conduct http://typelevel.org/conduct.html
Eq
instance that takes care of all but one field? In my specific use-case, it's a very large case class with about 25 fields, and I'd like to avoid the error-prone boilerplate... I need to compare all but the database ID :D
HList
of values of some typeclass that forms a Monad
, so it has some means of combining or sequencing. In my concrete case, it's Atto Parser
s.
Parser
s can be sequenced with ~
, for example, to yield a Parser
that yields a pair of the types of the combined Parser
s.
HList
of Parser[T]
to get a single Parser
with (an unfortunately horribly nested) Tuple
?
cats.sequence
package
Parser[HList]
test("sequencing Either")(check {
forAll { (x: Either[String, Int], y: Either[String, String], z: Either[String, Float]) =>
val expected = (x, y, z) mapN (_ :: _ :: _ :: HNil)
(x :: y :: z :: HNil).sequence == expected
}
})
Parser[A] ~ Parser[B] => Parser[(A, B)]
.
hlistOfParsers.sequence.map(_.tupled)
Applicative[Parser]
implicit class Command[P <: HList : IsHCons : *->*[Parser]#λ](parsers: P) {
def command[InF, InL <: HList, R, O <: Product, OL <: HList](f: InF)
(implicit
fntop: FnToProduct.Aux[InF, InL => R],
pgood: Comapped.Aux[P, Parser, InL]
): String => Either[Throwable, R] = { s =>
val tough = parsers.sequence
val parser = tough.map(flatten).map(_.productElements)
val args = parser.parseOnly(s).either.leftMap(s => new RuntimeException(s))
args.map(a => fntop(f)(a))
}
}
Sequencer
.
Sequencer.Aux[P, Parser, InL]
Hi!
In the following code:
import cats.Show
import cats.derived
import com.comcast.ip4s.{Cidr, IpAddress}
case class Route[+IP <: IpAddress](destination: Cidr[IP], nexthop: IP)
object Route {
implicit def show[IP <: IpAddress]: Show[Route[IP]] = {
implicit val ipShow: Show[IP] = IpAddress.show
implicit val cidrShow: Show[Cidr[IP]] = Cidr.show
derived.semiauto.show
}
}
I'm getting the following error:
[error] /home/simon/DSI/openstack/scala-neutron-client/src/main/scala/pt/tecnico/dsi/openstack/neutron/models/Route.scala:30:22: Could not derive an instance of Show[A] where A = pt.tecnico.dsi.openstack.neutron.models.Route[IP].
[error] Make sure that A has a Typeable instance and satisfies one of the following conditions:
[error] * it is a case class where all fields have a Show instance
[error] * it is a sealed trait where all subclasses have a Show instance
[error] derived.semiauto.show
[error] ^
Which makes no sense, is this a bug, or am I missing something?
Typeable[Cidr[IP]]
, I'm trying to implement one