Hi Nolan,
Well, this is more OO-calisthenics that anything to do with Salat.
Normally this could be done with an apply on the companion object, but
both the input and the output are typed to String, you would get an
error about defining "apply" twice. So try a factory method of some
type for creating the object:
scala> :paste
// Entering paste mode (ctrl-D to finish)
sealed trait Token {
def credentials: String
}
object PasswordToken {
def hash(s: String) = s.reverse
def create(password: String): PasswordToken =
PasswordToken(credentials = hash(password))
}
case class PasswordToken(credentials: String) extends Token
// Exiting paste mode, now interpreting.
defined trait Token
defined module PasswordToken
defined class PasswordToken
scala> PasswordToken("secure") // doesn't hash password
res0: PasswordToken = PasswordToken(secure)
scala> PasswordToken.create("secure") // does hash password
res1: PasswordToken = PasswordToken(eruces)
Best,
Rose