I have two functions that are working as expected
def getSomething: Promise[JsValue]def getSomethingElse: Promise[JsValue]
Now I want to define a third function (def getAll: Promise[JsValue]) that calls getSomething and then based on the response either return the response or getSomethingElse and append its response to the original.
I currently have getAll defined as follows:
def getAll: Promise[JsValue] = {
getSomething flatMap { response:JsValue =>
(response \ "someAttribute").asOpt[String] match {
case None =>
val resultPromise = Promise[JsValue]
resultPromise.redeem(response)
resultPromise
case Some(someAttribute) => getSomethingElse map { moreResponse:JsValue =>
response ++ moreResponse
}
}
}
}
This works but was wondering if there was a shorter way to accomplish the same thing that was more canonical scala?
Got a response from Derek Williams on the cross post on Play Frameworks Google Group.