Reputation: 51
def methodA(testvalue1 : String) : String={
c=a+b
return c
}
def methodB(testvalue2:String ) :String={
//here I want to use value returned by methodA, how could I do that ?
}
I want to use return value c
in methodB
.
Upvotes: 0
Views: 46
Reputation: 48420
Function composition is the technical term for your question.
Given
def methodA(s: String): String = {
s + ", hello "
}
def methodB(s: String): String = {
s + " world!"
}
all the following function compositions evaluate to the same value
val a = methodA("Shyam")
methodB(a)
methodB(methodA("Shyam"))
(methodA _ andThen methodB)("Shyam")
(methodB _ compose methodA)("Shyam")
namely
Shyam, hello world!
Upvotes: 2