Why is this not tail recursive?

62 views
Skip to first unread message

Peter Wolf

unread,
Jan 5, 2017, 4:51:33 PM1/5/17
to scala-user
Hi, why does @tailrec complain here?  It says getFoo(page+1) is not in tail recursive position. 

class Foo
def getFoo(page: Int, pageSize: Int): Seq[Foo] = ???

@tailrec
def getFoo(page: Int): Seq[Foo] = {
val foos = getFoo(page,pageSize)
if(foos.size >= pageSize) foos else foos ++ getFoo(page+1)
}

Dennis Haupt

unread,
Jan 5, 2017, 4:53:52 PM1/5/17
to Peter Wolf, scala-user
in "foos ++ getFoo(page+1)"
the last function to be called is "++", not "getFoo"
 
 
 
Gesendet: Donnerstag, 05. Januar 2017 um 22:51 Uhr
Von: "Peter Wolf" <opu...@gmail.com>
An: scala-user <scala...@googlegroups.com>
Betreff: [scala-user] Why is this not tail recursive?
--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Peter Wolf

unread,
Jan 5, 2017, 4:56:38 PM1/5/17
to Dennis Haupt, scala-user
Right!  Duh!  

Thanks
P

To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages