为什么我需要在第一行添加类型注释?
c.get[List[String]]("primary-group")
是Decoder.Result[List[String]]
在flatMap
它应该保持顶级类型之后,Decoder.Result[String]
但它会更改为 Either[DecodingFailure, String]。为什么?是它的问题dependent type
吗?
case class JWTPayload(primaryGroup: Group, groupMember: List[Group], name: String, pid: String)
implicit val jwtPayloadDecoder: Decoder[JWTPayload] = Decoder.instance(c =>
(
c.get[List[String]]("primary-group").flatMap(l => if(l.size == 1) l.head.asRight else DecodingFailure("", c.history).asLeft) : Decoder.Result[String],
c.get[List[String]]("group-member"),
c.get[String]("name"),
c.get[String]("pid")
).map4(
JWTPayload
)
)
没有: Decoder.Result[String
我得到
Error:(43, 7) value map4 is not a member of (scala.util.Either[io.circe.DecodingFailure,String], io.circe.Decoder.Result[List[String]], io.circe.Decoder.Result[String], io.circe.Decoder.Result[String])
possible cause: maybe a semicolon is missing before `value map4'?
).map4(
谢谢