Futures - map vs flatmap

前端 未结 4 1644
长发绾君心
长发绾君心 2020-12-23 09:59

I\'ve read the docs about map and flatMap and I understand that flatMap is used for an operation that accepts a Future pa

4条回答
  •  情歌与酒
    2020-12-23 10:38

    def flatMap[B](f: A => Option[B]): Option[B] = 
      this match {
        case None => None
        case Some(a) => f(a)
      }
    

    This is a simple example where how the flatMap works for Option, this can help to understand better, It is actually composing it is not adding a wrapper again.That's what we need.

提交回复
热议问题