PinkBubbleGoApe
PinkBubbleGoApe

Reputation: 21

Running Scala function from command line

I'm working on an exercise. I need to create a java project that can be run from the scala command line. The final output should be this:

scala> int2str(6)
res0: String = six

scala> int2str(65)
res0: String = sixty-five

How do I create a function that can be accessed by scala like that? I can create a Scala project in IntelliJ, but I don't know how to export that function to be used like that.

Any help is appreciated.

Thanks

Upvotes: 0

Views: 481

Answers (1)

Bondarenko
Bondarenko

Reputation: 293

Assuming you have the following scala code:

object A {
 def int2str(i: Int): String = ""
}

You can just make a jar file from your scala project with a command sbt package for instance, then run scala -cp <your jar>. In the scala console just import your function:

import A.int2str

Upvotes: 1

Related Questions