The (...)(People)
syntax is designed for when you've built up a list of arguments (well, technically it's a Builder
, not a list) with and
and want to lift the People
constructor into the applicative functor for Reads
so that you can apply it to those arguments.
For example, if your People
type looked like this:
case class People(names: Set[Id], home: String)
You could write:
implicit val PeopleReads: Reads[People] = (
(__ "names").read[Set[Id]] and
(__ "home").read[String]
)(People)
In your case, though, the constructor for People
has a single argument, and you haven't used and
, so you don't have a Builder[Reads[Set[Id] ~ String]
, you've just got a plain old Reads[Set[Id]]
.
This is nice, because it means you don't need the weird applicative functor syntax—all you need is map
:
implicit val PeopleReads = (__ "names").read[Set[Id]].map(People)
And you're done.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…