Cleaning up file resources in a DRY manner
I think this can be written more cleanly with flatMap


  flatMap[U](f: (T) ⇒ Try[U]): Try[U]
  
  Returns the given function applied to the value from this Success or returns this if this is a Failure.


val isReportSent = Try {
 ...
}.flatMap(_ =&gt; Try { sendReport(...) })

cleanUp(output, file)

isReportSent.get