Parameterized Functions
Specialize a function with [bracket] parameters.
Functions With a Parameter
A parameterized function takes a compile-time value in square brackets, letting one definition adapt itself before the program runs. ⚙️
fn repeat[count: Int](msg: String):
for i in range(count):
print(msg)The Bracket List
Place your parameters in brackets right after the function name, then your normal arguments in parentheses just after that.
fn scale[factor: Int](x: Int) -> Int:
return x * factorAll lessons in this course
- Parameters vs Arguments
- Parameterized Functions
- Parameterized Structs
- Why Compile-Time Wins Speed