Tin

Examples · 19 of 339

19-equality

== compares values, not identities: two arrays, structs or enums are equal when their parts are.

examples/19-equality.tintin run examples/19-equality.tin
// == compares values, not identities: two arrays, structs or enums are equal
// when their parts are. Anything holding a function has no ==.

type Crew = | Wheels | Hands | Eyes

type Step = { crew: Crew, task: string }

fn main() {
  let plan = [
    Step { crew: Wheels, task: "fetch filament" },
    Step { crew: Hands, task: "load the spool" },
    Step { crew: Wheels, task: "return to dock" },
  ]
  let forWheels = plan.filter(s => s.crew == Wheels)
  print("{forWheels.len} steps for the rover")

  let again = [Step { crew: Wheels, task: "fetch filament" }]
  print(forWheels[0] == again[0])
  print(plan.contains(Step { crew: Eyes, task: "inspect" }))
  print(Some([1, 2]) == Some([1, 2]))
}
2 steps for the rover
true
false
true