I have a class with an unknown number of functions:
class processors {
def p1(s: String): String = {
//code
}
def p2(s: String): String = {
//code
}
def p3(s: String): String = {
//code
}
...
}
I want to be able to run all the function one by one in the order they are written (p1 -> p2 -> p3 -> ...). Also, I would like to pass the initial string to p1
, which will pass the result as the argument for p2
and do on. Is there a simple way to do that?
EDIT:
What I have so far:
At the moment I have a hard-coded sequence:
val processors = Seq(p1 _, p2 _, p3 _).reduce(_ andThen _)
processors(some_string)
I'd like to avoid the hard-coding, basically..