I have a problem: I have a list in scala like this (List(“Entry1”, “Entry2”, “Entry3”))
and I want to print this list functional. So I don’t want to use any kind of loops.
I know it is possible using some kind of this code:
def test(input:List[_])
input match
{
case //and what now?
case _ => //recursion I guess?
}
I want to print this list using this method, every element on a new line.
Could someone help me please?
Thanks!
The standard way would be:
Or, if you want the index with it:
But I take it from your question that this is an exercise in writing a recursive function, so knowing the built-in way doesn’t really help you.
So, if you want to do it yourself, recursively, without the built-in
foreachmethod, try this:UPDATE: Regarding your comment about having the list index, try this: