Effect type nested inside itself, such as Future of Future
ID |
scala.correctness.nested_stateful_monads |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
medium |
Remediation Effort |
medium |
Resource |
Api Misuse |
Language |
Scala |
Description
This declares an effect wrapped in another of the same kind. It is almost always a map that should have been a flatMap - the inner effect is never run or awaited, so failures and results inside it are silently lost. Use flatMap to compose the two steps, or flatten the declared type.
Rationale
This declares an effect wrapped in another of the same kind. It is almost always a map that should have been a flatMap - the inner effect is never run or awaited, so failures and results inside it are silently lost. Use flatMap to compose the two steps, or flatten the declared type.
The following code illustrates the pattern detected by this rule:
class NestedStatefulMonads {
// FLAGGED: Effect type nested inside itself, such as Future of Future
def fetch(id: String): Future[Future[String]] = Future.successful(Future.successful(id))
}