-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from tsingbx/main
Add help doc for multiple return values
- Loading branch information
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Go+ has built-in support for _multiple return values_. | ||
// This feature is used often in idiomatic Go+, for example | ||
// to return both result and error values from a function. | ||
|
||
import "fmt" | ||
|
||
// The `(int, int)` in this function signature shows that | ||
// the function returns 2 `int`s. | ||
func vals() (int, int) { | ||
return 3, 7 | ||
} | ||
|
||
// Here we use the 2 different return values from the | ||
// call with _multiple assignment_. | ||
a, b := vals() | ||
println a | ||
println b | ||
|
||
// If you only want a subset of the returned values, | ||
// use the blank identifier `_`. | ||
_, c := vals() | ||
println c |