I have the following function in scala:
def is_in[T](e: T, as: List[T]) : Boolean = as match
{
case Nil => false;
case x::xs => e == x || is_in(e, xs);
}
Run Code Online (Sandbox Code Playgroud)
Now I want to make this function tail recursive. My idea is the following:
// tail recursive:
def is_in[T](e: T, as:List[T]) : Boolean =
{
@tailrec
def is_in_tailrec[T](e: T, as:List[T], acc: Boolean) : Boolean =
{
as match
{
case Nil => acc;
case x::xs => is_in_tailrec(... here …Run Code Online (Sandbox Code Playgroud)