我想实现unapply
方法但是,我得到以下奇怪的错误:
Adapting argument list by creating a 4-tuple: this may not be what you want.
[error] signature: Some.apply[A](x: A): Some[A]
[error] given arguments: genre._id, genre.name, genre.created, genre.updated
[error] after adaptation: Some((genre._id, genre.name, genre.created, genre.updated): (Option[reactivemongo.bson.BSONObjectID], String, Option[org.joda.time.DateTime], Option[org.joda.time.DateTime]))
[error] Some(genre._id, genre.name, genre.created, genre.updated)
[error] ^
这是我的代码:
def unapply(genre: Genre): Option[(Option[BSONObjectID], String,
Option[DateTime], Option[DateTime])] =
Some(genre._id, genre.name, genre.created, genre.updated)
我这样做是JSON转换的一部分:
implicit val genreWrites: OWrites[Genre] = (
(__ \ "_id").writeNullable[BSONObjectID] and
(__ \ "name").write[String] and
(__ \ "created").writeNullable[DateTime] and
(__ \ "updated").writeNullable[DateTime]
) (unlift(Genre.unapply))
知道为什么会这样吗?
答案 0 :(得分:3)
您需要额外的括号来声明元组:
Some((genre._id, genre.name, genre.created, genre.updated))
编译器告诉您的是,您要将多个参数传递给Some[A].apply
,这需要一个A
类型的参数。