Created
May 20, 2014 12:54
-
-
Save Centaur/8858ed707608a56be39f to your computer and use it in GitHub Desktop.
higherKinds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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