John Doe John Doe - 2 months ago 19
Scala Question

Adapting argument list in Scala

I want to implement the

unapply
method but, I get the following strange error:

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] ^


Here's my code:

def unapply(genre: Genre): Option[(Option[BSONObjectID], String,
Option[DateTime], Option[DateTime])] =
Some(genre._id, genre.name, genre.created, genre.updated)


I am doing this as part of the JSON conversion:

implicit val genreWrites: OWrites[Genre] = (
(__ \ "_id").writeNullable[BSONObjectID] and
(__ \ "name").write[String] and
(__ \ "created").writeNullable[DateTime] and
(__ \ "updated").writeNullable[DateTime]
) (unlift(Genre.unapply))


Any idea why this happens?

Answer

You need additional parenthesis to declare the tuple:

Some((genre._id, genre.name, genre.created, genre.updated))

What the compiler is telling you is that you're passing multiple parameters to the constructor of the Some[A].apply method which expects a single argument of type A.

Comments