|
1 | 1 | module Rs |
| 2 | + class Result |
| 3 | + class TypeError < StandardError |
| 4 | + def initialize: (untyped value_type, untyped error_type) -> void |
| 5 | + end |
| 6 | + |
| 7 | + class TypeNilClass < StandardError; end |
| 8 | + class TypeMismatch < StandardError; end |
| 9 | + class WrapNil < StandardError; end |
| 10 | + class UnwrapOnErr < StandardError; end |
| 11 | + class UnwrapErrOnOk < StandardError; end |
| 12 | + |
| 13 | + def is_ok: () -> bool |
| 14 | + def is_ok_and: () { (T) -> bool } -> bool |
| 15 | + def is_err: () -> bool |
| 16 | + def is_err_and: () { (E) -> bool } -> bool |
| 17 | + def ok: () -> Option[T] |
| 18 | + def err: () -> Option[E] |
| 19 | + def expect: (String) -> T |
| 20 | + def unwrap: () -> T |
| 21 | + def unwrap_or: (T) -> T |
| 22 | + def unwrap_or_else: () { (E) -> T } -> T |
| 23 | + def expect_err: (String) -> E |
| 24 | + def unwrap_err: () -> E |
| 25 | + def map: (Class value_type) { (T) -> U } -> Result[U, E] |
| 26 | + def map_or: (U) { (T) -> U } -> U |
| 27 | + def map_or_else: (Proc) { (T) -> U } -> U |
| 28 | + def map_err: (Class error_type) { (E) -> F } -> Result[T, F] |
| 29 | + def tap: () { (T) -> void } -> Result[T, E] |
| 30 | + def inspect_err: () { (E) -> void } -> Result[T, E] |
| 31 | + def and: (Result[U, E]) -> Result[U, E] |
| 32 | + def and_then: (Class value_type) { (T) -> Result[U, E] } -> Result[U, E] |
| 33 | + def or: (Result[T, F]) -> Result[T, F] |
| 34 | + def or_else: (Class error_type) { (E) -> Result[T, F] } -> Result[T, F] |
| 35 | + def self.from_or: (Class value_type, E error) { () -> T } -> Result[T, E] |
| 36 | + def self.from_or?: (Class value_type, E error) { () -> T | nil } -> Result[T, E] |
| 37 | + def self.from_or!: (Class value_type, E error) { () -> T } -> Result[T, E] |
| 38 | + end |
| 39 | + |
| 40 | + class Ok < Result |
| 41 | + attr_reader value: T |
| 42 | + attr_reader value_type: Class |
| 43 | + attr_accessor error_type: Class |
| 44 | + |
| 45 | + def self.[]: (Class value_type, Class error_type) { () -> T } -> Ok[T, E] |
| 46 | + def initialize: (T value) -> void |
| 47 | + def inspect: () -> String |
| 48 | + def ==: (untyped) -> bool |
| 49 | + end |
| 50 | + |
| 51 | + class Err < Result |
| 52 | + attr_reader error: E |
| 53 | + attr_reader error_type: Class |
| 54 | + attr_accessor value_type: Class |
| 55 | + |
| 56 | + def self.[]: (Class value_type, Class error_type) { () -> E } -> Err[T, E] |
| 57 | + def initialize: (E error) -> void |
| 58 | + def inspect: () -> String |
| 59 | + def ==: (untyped) -> bool |
| 60 | + end |
| 61 | + |
2 | 62 | module Result |
3 | 63 | VERSION: String |
4 | | - # See the writing guide of rbs: https://github.com/ruby/rbs#guides |
5 | 64 | end |
6 | 65 | end |
0 commit comments