Has anyone successfully written a failable function in Verse?

  1. You can’t return explicitly from a failable context. So that stops you from using return Y
  2. false? always fails, without returning any value. However, right now the compiler still wants to see the function return a value of its return type (int) since it can’t infer that anything after false? won’t execute.

You could wrap this in an option:

Find(X:[]int, F(:int)<transacts><decides>:void)<transacts><decides>:int =
    var RetInt:?int = false 
    for (Y:X, F[Y], not RetInt?):
        set RetInt = option{Y}
    RetInt?
4 Likes