Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[writing-async-app-in-scala-part-3] smartMap extension
def smartMap[U](f: T => U)(implicit ec: ExecutionContext): Future[U] =
if (future.isCompleted) {
if (future.value.get.isSuccess)
wrap(f(future.value.get.get))
else
future.asInstanceOf[Future[U]]
} else {
future.map(f)(ec)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment