Examples:
// Input you a code using a loop
def
[
,
]
(
:
,
): =
{
var
:
=
while(){
val new{{to_first_upper(local_var.name)}} =
{{local_var.name}} = new{{to_first_upper(local_var.name)}}
}
}
// Output - Auto-generated tailrec
// Scala(tailrec)
def {{func_name}}
[
{{type_param.name}}
,
]
(
{{param.name}}: {{param.type}}
,
): {{ret_type}}
= {
import scala.annotation.tailrec
@tailrec
def _{{func_name}}(
{{local_var.name}}: {{local_var.type}}
,
):
{{ret_type}}
=
{
if({{while_cond}}) {
val new{{to_first_upper(local_var.name)}} = {{local_var.update_value}}
_{{func_name}}(
new{{to_first_upper(local_var.name)}}
,
)
}
else {{ret_val}}
}
_{{func_name}}(
{{local_var.init_value}}
,
)
}
// Input confirmation
def {{func_name}}
[
{{type_param.name}}
,
]
(
{{param.name}}: {{param.type}}
,
): {{ret_type}}
=
{
var {{local_var.name}}: {{local_var.type}} = {{local_var.init_value}}
while({{while_cond}}){
val new{{to_first_upper(local_var.name)}} = {{local_var.update_value}}
{{local_var.name}} = new{{to_first_upper(local_var.name)}}
}
{{ret_val}}
}