codex-storage / questionable

Elegant optional types for Nim
Other
116 stars 5 forks source link

`without` with error variable works for any Result type #59

Closed markspanbroek closed 3 months ago

markspanbroek commented 5 months ago

These type of statements used to only work for ?!T types:

without x =? y, error:
  # do something with error

Now they also work for any Result[T, E] types, with the caveat that the error is converted to a ref CatchableError. Conversion is necessary, because we need a type for the error variable that works for any type of result, in case that we have multiple =? bindings in the without expression, e.g.:

var a: ?!int
var b: Result[int, string]

without x =? a and y =? b, error:
  # without conversion error types would clash