Scala: how to understand the flatMap method of Try?

后端 未结 6 2386
情深已故
情深已故 2021-02-20 05:29

The flatMap method of the Success is implemented like this:

  def flatMap[U](f: T => Try[U]): Try[U] =
    try f(value)
    catch {
      case NonFatal(e) =&g         


        
6条回答
  •  闹比i
    闹比i (楼主)
    2021-02-20 06:12

    I found Dan Spiewak's "Monads Are Not Metaphors" very helpful in getting my head around monads. For folks starting from Scala (like me) it's far easier to grasp than anything else I've found - including Odersky's writings. In reading it, note that 'bind'=='flatMap'.

提交回复
热议问题