I have what I believe to be a fairly simple tail-recursive function. However, @tailrec
tells me otherwise.
@tailrec
def _next(continue : String, current : List[Long], first : Boolean ) : Stream[Long] = {
current match {
case head :: tail => head #:: _next(continue, tail, false) //this line breaks tailrec
case Nil if first => empty
case _ => {
val (nc, nl) = getIds(continue)
_next(nc, nl, true)
}
}
}
which presents me with
[error] could not optimize @tailrec annotated method _next: it contains a recursive call not in tail position
[error] case head :: tail => head #:: _next(continue, tail, false)
[error] ^
it probably has to do with the implicit notification I receive from eclipse: - Implicit conversions found: _next(continue, tail, false) => consWrapper(_next(continue, tail, false))
, but unfortunately, that isn't helping me resolve the issue.
How can I fix this, and, for brownie points, where did I go wrong thinking this would tail-recurse?