Last active
August 29, 2015 14:25
-
-
Save taisukeoe/3e36a3c6a3bc45be0c01 to your computer and use it in GitHub Desktop.
Break down Callback which has two ore more functions into the same number of PartialFunction
This file contains 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
trait Callback{ | |
def onSet(s:Set[String]):Unit | |
def onList(l:List[String]):Unit | |
} | |
def funcWithCallback(s:String,callback:Callback):Unit = ??? | |
def funcAsFuture(s:String):Future[Traversable[String]] = { | |
val p = Promise[Traversable[String]]() | |
val f = p.future | |
funcWithCallback(s,new Callback{ | |
def onSet(s:Set[String]):Unit = p.success(s) | |
def onList(l:List[String]):Unit = p.success(l) | |
}) | |
} | |
val pf1:PartialFunction[Set[String],Result] = ... | |
val pf2:PartialFunction[List[String],Result] = ... | |
//If PartialFucntion is Monoid, might it be appendable as follows? | |
val pf:PartialFunction[Traversable[String],Result] = pf1 append pf2 | |
//Break down Callback into two ore more PartialFunction implementations | |
val f:Future[Result] = for{ | |
trav <- funcAsFuture.map(s) | |
} pf(trav) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment