I’m trying to build an interactive console program. Is this the normal way of implementing a command processor in scala?
abstract class Command extends (() => Unit)
class Greet(val greeting: String) extends Command {
def apply = println(greeting)
}
object Exit extends Command {
def apply = System.exit(0)
}
If you have a method running on an infinite loop, would it take a cmd: Command and you would call cmd.apply() or cmd()? This seems to do the trick but there may be a better way.
Also when you do :t myCommand in the REPL you get .e.g :t Exit = Exit.type. Is there a way of getting (() => Unit)?
And would your list of available commands go into an Enumeration type, say Commands?