1  package frost.core
 2  
 3  ====================================================================================================
 4  Holds either a value or an `Error`. `Maybe` is intended for use as a return type for a method which
 5  returns a value, but is not always guaranteed to succeed.
 6  ====================================================================================================
 7  choice Maybe<T> {
 8      ================================================================================================
 9      A successful call with return value.
10      ================================================================================================
11      SUCCESS(T)
12  
13      ================================================================================================
14      An error occurred.
15      ================================================================================================
16      ERROR(Error)
17  
18      ================================================================================================
19      Returns the result of a successful call.
20      ================================================================================================
21      @pre(succeeded())
22      function get():T {
23          match self {
24              when SUCCESS(value) {
25                  return value
26              }
27          }
28          unreachable
29      }
30  
31      ================================================================================================
32      Returns the error message of a failed call.
33      ================================================================================================
34      @pre(!succeeded())
35      function error():Error {
36          match self {
37              when ERROR(error) {
38                  return error
39              }
40          }
41          unreachable
42      }
43  
44      ================================================================================================
45      Returns `true` if the call succeeded.
46      ================================================================================================
47      function succeeded():Bit {
48          match self {
49              when SUCCESS {
50                  return true
51              }
52              when ERROR {
53                  return false
54              }
55          }
56          unreachable
57      }
58  }