Scala 如何将方法的返回值作为输入传递给其他方法

Scala 如何将方法的返回值作为输入传递给其他方法,scala,Scala,我想在methodB中使用返回值c,这是您问题的技术术语 给定 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 ? } 以下所有函数组合的计算结果相同 def methodA(s: Stri

我想在
methodB
中使用返回值
c
,这是您问题的技术术语

给定

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 ?
}
以下所有函数组合的计算结果相同

def methodA(s: String): String = {
  s + ", hello "
}

def methodB(s: String): String = {
  s + " world!"
}

val a = methodA("Shyam")
methodB(a)

methodB(methodA("Shyam"))

(methodA _ andThen methodB)("Shyam")

(methodB _ compose methodA)("Shyam")
是你问题的专业术语

给定

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 ?
}
以下所有函数组合的计算结果相同

def methodA(s: String): String = {
  s + ", hello "
}

def methodB(s: String): String = {
  s + " world!"
}

val a = methodA("Shyam")
methodB(a)

methodB(methodA("Shyam"))

(methodA _ andThen methodB)("Shyam")

(methodB _ compose methodA)("Shyam")

要获取由
methodA()
返回的值,您需要调用
methodA()
并保存它返回的值。您可以执行类似
methodB(methodA(myValue))
的操作来获取由
methodA()
返回的值,您需要调用
methodA()
并保存它返回的值。您可以执行类似
methodB的操作(方法A(myValue))