Skip to content

Instantly share code, notes, and snippets.

@maowug
Last active October 4, 2015 10:29
Show Gist options
  • Save maowug/e15a6b0a2a7ef31d00b7 to your computer and use it in GitHub Desktop.
Save maowug/e15a6b0a2a7ef31d00b7 to your computer and use it in GitHub Desktop.
/**
* queryStringをFakeRequestに入れるユーティリティ
* FakeRequest().copy(queryString = qs)にすると、戻り値が
* Iteratee[Array[Byte], Result] となるため、これを Future[B] へ fold します
*
* //usage:
* // val actual = controller.purchase()(FakeRequest().copy(
* // queryString = validBuyingRequestParams)) fold toFuture
*/
def toFuture[B](step: Step[Array[Byte], B]): Future[B] = step match {
case Step.Done(a0, e) => Future(a0)
case Step.Cont(k) => k(Input.EOF) fold {
case Step.Done(a1, _) => Future.successful(a1)
case _ => throw new Exception("error or diverging iteratee")
}
case Step.Error(msg, e) => throw new Exception("error iteratee")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment