We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 80a2d81 commit 82480c8Copy full SHA for 82480c8
core/src/main/scala/com/avsystem/commons/SharedExtensions.scala
@@ -461,6 +461,19 @@ object SharedExtensionsUtils extends SharedExtensions {
461
*/
462
def toOptArg: OptArg[A] =
463
if (tr.isFailure) OptArg.Empty else OptArg(tr.get)
464
+
465
+ /**
466
+ * Apply side-effect only if Try is a failure.
467
+ *
468
+ * Don't use .failed projection here, because it unnecessarily creates Exception in case of Success,
469
+ * which is an expensive operation.
470
+ */
471
+ def tapFailure(action: Throwable => Unit): Try[A] = tr match {
472
+ case Success(_) => tr
473
+ case Failure(throwable) =>
474
+ action(throwable)
475
+ tr
476
+ }
477
}
478
479
class LazyTryOps[A](private val tr: () => Try[A]) extends AnyVal {
0 commit comments