What is a nice approach for collecting and using useful Scala utility functions across projects. The focus here on really simple, standalone functions like:
def toBinary(i: Int, digits: Int = 8) =
String.format("%" + digits + "s", i.toBinaryString).replace(' ', '0')
def concat(ss: String*) = ss filter (_.nonEmpty) mkString ", "
concat: (ss: String*)String
This question is basic, I know 😉 but, I’ve learned that there is always an optimum way to do something. For example, reusing code from within the Scala interactive shell, Idea, Eclipse, with or without SBT, having the library hosed on GitHub, ect, could quickly introduce optimal, and non-optimal approaches to such a simple problem.
You might want to put such methods in a package object.
You could also put them in a normal
objectand import everything in the object when you need those methods.