dafny-lang / libraries

Libraries useful for Dafny programs
Other
43 stars 25 forks source link

feat: Add `MapFailure` to `Result` #31

Closed seebees closed 2 years ago

seebees commented 2 years ago

For :- to work nicely the Failure side of the Result needs to line up with the return value. While this can be simplified by always using the same type, this is an unresonalb requirement.

This lets custsomers align the Failure side of return value. AlignFailure may also be a good name.

Example

  function Foo(): Result<string, int>

  function Bar(): Result<string, string> {
    var fooString :- Foo().MapFailure(_ => "Foo failed.");
    // work
    Success(fooString)
  }

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.