Skip to content

Instantly share code, notes, and snippets.

@fthomas
Last active December 13, 2015 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fthomas/4979797 to your computer and use it in GitHub Desktop.
Save fthomas/4979797 to your computer and use it in GitHub Desktop.
// see http://stackoverflow.com/questions/14924707/how-to-write-a-scalaz-isempty-parameter-for-generic-types
import scalaz._
import Scalaz._
object Test {
def asOption[C](c: C)(implicit ev: IsEmpty[({type F[_] = C})#F]): Option[C] =
if (ev.isEmpty(c)) None else Some(c)
implicit def detailedIsEmpty[A, C[_]](implicit ev: IsEmpty[C]) =
ev.asInstanceOf[IsEmpty[({type F[_] = C[A]})#F]]
implicit def detailedIsEmptyMap[K, V](implicit ev: IsEmpty[({type F[V] = Map[K, V]})#F]) =
ev.asInstanceOf[IsEmpty[({type F[_] = Map[K, V]})#F]]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment