@@ -7,72 +7,71 @@ import scala.util.Try
77import scala .util .control .NonFatal
88
99/**
10- * The `Retry` type represents a computation that is retrying itself in case of an exception. It uses a `RetryStrategy`
11- * as a policy for the retry operation.
12- *
13- * The result may be successful consisting of the computation result value or a failure that
14- * is wrapping the underlying exception. The type is similar to the scala [[scala.util.Try ]] type.
15- *
16- * Example:
17- * {{{
18- * import scala.concurrent.duration._
19- * import util.retry.blocking.{RetryStrategy, Failure, Retry, Success}
20- *
21- * implicit val retryStrategy =
22- * RetryStrategy.fixedBackOff(retryDuration = 1.seconds, maxAttempts = 2)
23- *
24- * val r = Retry(1 / 1) match {
25- * case Success(x) => x
26- * case Failure(t) => log("Exception occurred", t)
27- * }
28- * }}}
29- */
10+ * The `Retry` type represents a computation that is retrying itself in case of an exception. It uses a `RetryStrategy`
11+ * as a policy for the retry operation.
12+ *
13+ * The result may be successful consisting of the computation result value or a failure that
14+ * is wrapping the underlying exception. The type is similar to the scala [[scala.util.Try ]] type.
15+ *
16+ * Example:
17+ * {{{
18+ * import scala.concurrent.duration._
19+ * import util.retry.blocking.{RetryStrategy, Failure, Retry, Success}
20+ *
21+ * implicit val retryStrategy =
22+ * RetryStrategy.fixedBackOff(retryDuration = 1.seconds, maxAttempts = 2)
23+ *
24+ * val r = Retry(1 / 1) match {
25+ * case Success(x) => x
26+ * case Failure(t) => log("Exception occurred", t)
27+ * }
28+ * }}}
29+ */
3030sealed trait Retry [+ T ] {
31-
3231 /**
33- * Returns `true` if the `Retry` is a `Failure` otherwise it returns `false`.
34- */
32+ * Returns `true` if the `Retry` is a `Failure` otherwise it returns `false`.
33+ */
3534 def flatMap [S ](f : T => Retry [S ]): Retry [S ]
3635
3736 /**
38- * Maps the given function to the value from this `Success` or returns this if this is a `Failure`.
39- */
37+ * Maps the given function to the value from this `Success` or returns this if this is a `Failure`.
38+ */
4039 def map [S ](f : T => S )(implicit strategy : RetryStrategyProducer ): Retry [S ]
4140
4241 /**
43- * Returns `true` if the `Retry` is a `Failure` otherwise it returns `false`.
44- */
42+ * Returns `true` if the `Retry` is a `Failure` otherwise it returns `false`.
43+ */
4544 def isFailure : Boolean
4645
4746 /**
48- * Returns `true` if the `Retry` is a `Success` otherwise it returns `false` otherwise.
49- */
47+ * Returns `true` if the `Retry` is a `Success` otherwise it returns `false` otherwise.
48+ */
5049 def isSuccess : Boolean
5150
5251 /**
53- * Returns the computation value in case of a `Success`.
54- * In case of a `Failure` it throws the underlying exception.
55- */
52+ * Returns the computation value in case of a `Success`.
53+ * In case of a `Failure` it throws the underlying exception.
54+ */
5655 def get : T
5756
5857 /**
59- * Returns the computation value in case of a `Success`. Otherwise it is returning the provided default.
60- */
58+ * Returns the computation value in case of a `Success`. Otherwise it is returning the provided default.
59+ */
6160 def getOrElse [U >: T ](default : => U ): U = if (isSuccess) get else default
6261
6362 /**
64- * Applies the given function `f` if this is a `Success`, otherwise returns `Unit` if this is a `Failure`.
65- */
63+ * Applies the given function `f` if this is a `Success`, otherwise returns `Unit` if this is a `Failure`.
64+ */
6665 def foreach [X ](f : T => X )
6766
6867 /**
69- * Applies the given function `f` if this is a `Failure`, otherwise returns this if this is a `Success`.
70- */
68+ * Applies the given function `f` if this is a `Failure`, otherwise returns this if this is a `Success`.
69+ */
7170 def recover [X >: T ](f : PartialFunction [Throwable , X ]): Retry [X ]
7271
7372 /**
74- * Transforms the `Retry` value by applying a transformation function to its underlying value
75- */
73+ * Transforms the `Retry` value by applying a transformation function to its underlying value
74+ */
7675 def transform [X ](f : T => X ): X
7776}
7877
@@ -85,8 +84,7 @@ final case class Success[+T](value: T) extends Retry[T] {
8584 override def foreach [X ](f : T => X ): Unit = f(value)
8685 override def transform [X ](f : T => X ): X = f(value)
8786 override def flatMap [S ](f : T => Retry [S ]): Retry [S ] = f(value)
88- override def map [S ](f : T => S )(
89- implicit strategy : RetryStrategyProducer ): Retry [S ] = Retry (f(value))
87+ override def map [S ](f : T => S )(implicit strategy : RetryStrategyProducer ): Retry [S ] = Retry (f(value))
9088}
9189
9290final case class Failure [+ T ](exception : Throwable ) extends Retry [T ] {
@@ -106,8 +104,7 @@ final case class Failure[+T](exception: Throwable) extends Retry[T] {
106104 override def foreach [X ](f : T => X ): Unit = ()
107105 override def transform [X ](f : T => X ): X = throw exception
108106 override def flatMap [S ](f : T => Retry [S ]): Retry [S ] = Failure (exception)
109- override def map [S ](f : T => S )(
110- implicit strategy : () => RetryStrategy ): Retry [S ] = Failure (exception)
107+ override def map [S ](f : T => S )(implicit strategy : () => RetryStrategy ): Retry [S ] = Failure (exception)
111108}
112109
113110object Retry {
0 commit comments