Track

Values, Types & Pure Functions

Go Syntax & The Type System

WebContainer
0 XP
0d streak
Concept
Core Principles
Code Example
4Knowledge Check
5Hands-On Drill
60%
Lesson 1 · 6 min

Values, Types & Pure Functions

Every API, calculation, and concurrent worker starts with values flowing through functions. Clear types make those flows predictable before a bug reaches production.

In this lesson

STEP 1

A function is a named recipe: it receives input, does one focused job, and returns an output.

STEP 2

An accumulator starts with the identity value for an operation. For addition, that value is 0, so an empty list naturally returns 0.

STEP 3

A pure function does not change its input or depend on hidden state. That makes it easier to test, reuse, and parallelise later in Go.

Interactive Example

A safe sum has an honest starting value

Interactive Editor
typescript
Loading...
Output Console
Modify code and click "Run Code" (or ⌘+Enter) to evaluate output in real time.
What happens here?
  1. Start at 0 because adding 0 changes nothing.
  2. Visit each number exactly once.
  3. Return the accumulated value; do not mutate the input list.

Quick check

What should a sum function return for an empty list?

Next: Phase 2 Hands-On Drill

Ready to write code?

Solve the coding challenge in the in-browser IDE with live visible and hidden specification tests.