Unit in scala - Not able to understand

scala

Solution

Unit in scala is identical to void in Java, moreover, Java sees Scala's Unit as void, and vise versa. So in java it could be written like:

void foreach(MethodThatReturnsVoid f) {
    f.apply(elem)
    left.foreach(f)
    right.foreach(f)
}

It is a little bit pseudocode (since java doesn't support first class functions yet) but I hope you've got the idea.

Problem

Am bogged down by this syntax: ``` def foreach(f: Tweet => Unit): Unit = { f(elem) left.foreach(f) right.foreach(f) } ``` where `Tweet` is a class with three variables. What does it mean for a function to return `Unit`? I tried different things but am not able to call the function itself in this case. Please help. Thanks

Original source