Custom Types

Array Types

You can use arrays as types.

let Person = [name: String, age: UInt]
let grow = (person: Person) -> person.age++

let lu = new Person("Lu", 28)
lu:grow()

Function Types

You can use functions as types.

let Even = [n] => n % 2 == 0
let half = [n: Even] => n / 2

half(4) //2
half(3) //Type Error

Checking

You can check a value's type with the is or type function.

Last updated

Was this helpful?