Skip to content

Instantly share code, notes, and snippets.

@Centaur
Created May 20, 2014 12:54
Show Gist options
  • Save Centaur/8858ed707608a56be39f to your computer and use it in GitHub Desktop.
Save Centaur/8858ed707608a56be39f to your computer and use it in GitHub Desktop.
higherKinds
import scala.language.higherKinds
trait MaybeEmpty[T[_]] {
def isEmpty(thing: T[_]): Boolean
}
implicit def optionMaybeEmpty[O[_] <: Option[_]] = new MaybeEmpty[O] {
def isEmpty(thing: O[_]) = thing.isEmpty
}
def doNotEmpty[T[_]](thing: T[_])(implicit m: MaybeEmpty[T]) = {
val emptyStr = if(m.isEmpty(thing)) "empty" else "not empty"
println(s"$thing is $emptyStr")
}
doNotEmpty(None)
doNotEmpty(Some(1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment