Curriculum Foundations Functions & multi-return
Functions & multi-return
Functions look familiar — func name(args) returnType { ... } — with one big new idea: multiple return values. Go functions can return a tuple, and the convention for "this might fail" is to return (result, error). We'll meet error properly in a later module, but the *shape* arrives here.
Exercises
10 ready
01
pick one
TypeScript and Go both have first-class functions, but the syntax
02
pick one
TypeScript returns multiple values by packing them into an
03
pick one
TypeScript expresses "this can fail" by returning a union with
04
pick one
Exercise 3 covered the (T, error) return-tuple signature. To put a
05
fill blanks
Exercise 1 covered the function-signature shape by recognition. Now
06
fill blanks
Exercise 3 covered the (T, error) return-tuple convention by
07
type one line
Type the Go line that, on empty input, returns the zero value of
08
type one line
Type the Go line that performs the if err != nil error check
09
write a program
Write a Go function divmod(a, b int) (int, int) that returns the
10
write a program
Preview the (result, error) shape that becomes the canonical Go