0

Say I have this:

val index? = 
   label<Int|False> return:
     for (this in tuple, i in 0 to false) do:
       if this == that:
         return(i)
match(index?:Int):
  println("index was %_" % [index])
else: 
  println("not found")

Is there a cleaner or more idiomatic form to search a tuple and return the index of the item if it exists?

1 Answers1

0

Yup! Just use this function:

val index = index-of(tuple, that)

It does exactly that. There's also an index-when function where you can plugin any predicate you want.

Patrick

Patrick Li
  • 672
  • 4
  • 11