go - Golang return values of function as input arguments to another -


if have

func returnintandstring() (i int, s string) {...} 

and have:

func dosomething(i int, s string) {...} 

then can following successfully:

dosomething(returnintandstring()) 

however, let's want add argument dosomething like:

func dosomething(msg string, int, s string) {...} 

go complains when compiling if call like:

dosomething("message", returnintandstring()) 

with:

main.go:45: multiple-value returnintandstring() in single-value context main.go:45: not enough arguments in call dosomething() 

is there way or should give , assign return values returnintandstring references , pass msg , these values dosomething(msg, code, str) ?

it's described here in spec. requires inner function return correct types arguments. there no allowance parameters along function returns multiple values.

as special case, if return values of function or method g equal in number , individually assignable parameters of function or method f, call f(g(parameters_of_g)) invoke f after binding return values of g parameters of f in order. call of f must contain no parameters other call of g, , g must have @ least 1 return value. if f has final ... parameter, assigned return values of g remain after assignment of regular parameters.

func split(s string, pos int) (string, string) {   return s[0:pos], s[pos:] }  func join(s, t string) string {   return s + t }  if join(split(value, len(value)/2)) != value {   log.panic("test fails") } 

if specific conditions not met, need assign return values , call function separately.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -