Typed Parameters
Last updated
// Function with a number parameter
def double(number val) (
return val * 2
)
// Function with a string parameter
def greet(string name) (
// Using ++ to concatenate without spaces
return "Hello, " ++ name ++ "!"
)
// Function with multiple typed parameters
def createPerson(string name, number age) (
return {
name: name,
age: age
}
)def double(number val) (
return val * 2
)
log double(10) // Works correctly, outputs: 20
log double("10") // Error: Expected number but got string// Function that takes a callback function
def processData(array data, processor) (
result = []
for i data.len (
result = result.append(processor(data[i]))
)
return result
)
// Using the function
numbers = [1, 2, 3, 4, 5]
log processData(numbers, double) // Outputs: [2, 4, 6, 8, 10]