Combining Futures And Options in Scala

implicit class FutureOption[T](val m: Future[Option[T]]) {
}
def fmap[U](tf: T => U)(
implicit executionContext: ExecutionContext): Future[Option[U]] = m.map(_.map(tf(_)))
def fflatMap[U](tf: T => Future[Option[U]])(
implicit executionContext: ExecutionContext): Future[Option[U]]= this.m
.flatMap(_.map(tf(_)).getOrElse(Future { None }))

--

--

Programmer, Thinker, Entrepreneur, “Intuitioner”

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store