Skip to content

Instantly share code, notes, and snippets.

@robertberry-zz
Created March 7, 2014 12:04
Show Gist options
  • Save robertberry-zz/9410272 to your computer and use it in GitHub Desktop.
Save robertberry-zz/9410272 to your computer and use it in GitHub Desktop.
[info] Compiling 9 Scala sources to /home/robert/Git/mobile-apps-api/common/target/scala-2.10/classes...
[error] /home/robert/Git/mobile-apps-api/common/app/lib/PlayJson.scala:17: type mismatch;
[error] found : (play.api.libs.json.Reads[Nothing], play.api.libs.json.Reads[Nothing]) => play.api.libs.json.Reads[Nothing]
[error] required: (play.api.libs.json.Reads[_ <: A], play.api.libs.json.Reads[_ <: A]) => play.api.libs.json.Reads[_ <: A]
[error] def oneOf[A](reads: Seq[Reads[_ <: A]]): Reads[A] = reads.reduce(either)
[error] ^
[error] /home/robert/Git/mobile-apps-api/common/app/lib/PlayJson.scala:17: type mismatch;
[error] found : play.api.libs.json.Reads[_$1] where type _$1 <: A
[error] required: play.api.libs.json.Reads[A]
[error] Note: _$1 <: A, but trait Reads is invariant in type A.
[error] You may wish to define A as +A instead. (SLS 4.5)
[error] def oneOf[A](reads: Seq[Reads[_ <: A]]): Reads[A] = reads.reduce(either)
@robertberry-zz
Copy link
Author

PLAY SUCKS DAMMIT

@phadej
Copy link

phadej commented Aug 29, 2014

  // Reads is covariant, dunno why it isn't.
  def readsUpCast[A](r: Reads[_ <: A]): Reads[A] = r.map(x => x)

  def mapx[A](reads: Seq[Reads[_ <: A]]): Seq[Reads[A]] = reads.map(readsUpCast[A] _)

  def oneOf[A](reads: Seq[Reads[_ <: A]]): Reads[A] = mapx[A](reads).reduce(_ orElse _)

@phadej
Copy link

phadej commented Aug 29, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment