Class: Mangrove::Result::Ok

Inherits:
Object
  • Object
show all
Extended by:
T::Generic, T::Helpers, T::Sig
Includes:
Mangrove::Result
Defined in:
lib/mangrove/result.rb

Constant Summary collapse

OkType =
type_member
ErrType =
type_member

Instance Method Summary collapse

Methods included from Mangrove::Result

err, err_wt, from_results, ok, ok_wt

Constructor Details

#initialize(inner) ⇒ void

Parameters:



127
128
129
# File 'lib/mangrove/result.rb', line 127

def initialize(inner)
  @inner = inner
end

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

  • other (BasicObject)

Returns:

  • (Boolean)


132
133
134
135
136
137
138
139
140
141
142
# File 'lib/mangrove/result.rb', line 132

def ==(other)
  case other
  when Result::Ok
    other.instance_variable_get(:@inner) == @inner
  when Result::Err
    false
  else # rubocop:disable Lint/DuplicateBranch
    # Because == is defined on BasicObject, we can't be sure that `other` is an Option
    false
  end
end

#and(other) ⇒ Result[T.type_parameter(:NewOkType), ErrType]

Parameters:

Returns:



203
204
205
# File 'lib/mangrove/result.rb', line 203

def and(other)
  other
end

#and_then(&block) ⇒ Result[T.type_parameter(:NewOkType), ErrType]

Parameters:

Returns:



208
209
210
# File 'lib/mangrove/result.rb', line 208

def and_then(&block)
  block.call(@inner)
end

#and_then_wt(_t_new_ok, &block) ⇒ Result[T.type_parameter(:NewOkType), ErrType]

Parameters:

  • _t_new_ok (T::Class[T.type_parameter(:NewOkType)])
  • block (T.proc.params(this: OkType).returns(Result[T.type_parameter(:NewOkType), ErrType]))

Returns:



213
214
215
# File 'lib/mangrove/result.rb', line 213

def and_then_wt(_t_new_ok, &block)
  block.call(@inner)
end

#err?Boolean

Returns:

  • (Boolean)


168
# File 'lib/mangrove/result.rb', line 168

def err? = false

#expect!(_message) ⇒ OkType

Parameters:

  • _message (String)

Returns:



155
156
157
# File 'lib/mangrove/result.rb', line 155

def expect!(_message)
  @inner
end

#expect_with!(&_block) ⇒ OkType

Parameters:

  • _block (T.proc.returns(T.type_parameter(:E)))

Returns:



160
161
162
# File 'lib/mangrove/result.rb', line 160

def expect_with!(&_block)
  @inner
end

#map(&block) ⇒ Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]

Parameters:

  • block (T.proc.params(this: Result[OkType, ErrType]).returns(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]))

Returns:

  • (Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)])


171
172
173
# File 'lib/mangrove/result.rb', line 171

def map(&block)
  block.call(self)
end

#map_err(&_block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]

Parameters:

  • _block (T.proc.params(this: ErrType).returns(T.type_parameter(:NewErrType)))

Returns:



192
193
194
# File 'lib/mangrove/result.rb', line 192

def map_err(&_block)
  T.cast(self, Result::Ok[OkType, T.type_parameter(:NewErrType)])
end

#map_err_wt(_t_new_err, &_block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]

Because sorbet deduct types from return values well. This method takes a type of new inner values.

Parameters:

  • _t_new_err (T::Class[T.type_parameter(:NewErrType)])
  • _block (T.proc.params(this: ErrType).returns(T.type_parameter(:NewErrType)))

Returns:



198
199
200
# File 'lib/mangrove/result.rb', line 198

def map_err_wt(_t_new_err, &_block)
  T.cast(self, Result::Ok[OkType, T.type_parameter(:NewErrType)])
end

#map_ok(&block) ⇒ Result[T.type_parameter(:NewOkType), ErrType]

Parameters:

  • block (T.proc.params(this: OkType).returns(T.type_parameter(:NewOkType)))

Returns:



181
182
183
# File 'lib/mangrove/result.rb', line 181

def map_ok(&block)
  Result::Ok[T.type_parameter(:NewOkType), ErrType].new(block.call(@inner))
end

#map_ok_wt(_t_new_ok, &block) ⇒ Result[T.type_parameter(:NewOkType), ErrType]

Because sorbet deduct types from return values well. This method takes a type of new inner values.

Parameters:

  • _t_new_ok (T::Class[T.type_parameter(:NewOkType)])
  • block (T.proc.params(this: OkType).returns(T.type_parameter(:NewOkType)))

Returns:



187
188
189
# File 'lib/mangrove/result.rb', line 187

def map_ok_wt(_t_new_ok, &block)
  Result::Ok[T.type_parameter(:NewOkType), ErrType].new(block.call(@inner))
end

#map_wt(_t_new_ok, _t_new_err, &block) ⇒ Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]

Parameters:

  • _t_new_ok (T.type_parameter(:NewOkType))
  • _t_new_err (T.type_parameter(:NewErrType))
  • block (T.proc.params(this: Result[OkType, ErrType]).returns(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]))

Returns:

  • (Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)])


176
177
178
# File 'lib/mangrove/result.rb', line 176

def map_wt(_t_new_ok, _t_new_err, &block)
  block.call(self)
end

#ok?Boolean

Returns:

  • (Boolean)


165
# File 'lib/mangrove/result.rb', line 165

def ok? = true

#ok_innerOkType

Returns:



145
146
147
# File 'lib/mangrove/result.rb', line 145

def ok_inner
  @inner
end

#or(_other) ⇒ Result[OkType, ErrType]

Parameters:

Returns:



218
219
220
# File 'lib/mangrove/result.rb', line 218

def or(_other)
  self
end

#or_else(&_block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]

Parameters:

Returns:



223
224
225
# File 'lib/mangrove/result.rb', line 223

def or_else(&_block)
  T.cast(self, Result::Ok[OkType, T.type_parameter(:NewErrType)])
end

#or_else_wt(_t_new_err, &_block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]

Parameters:

  • _t_new_err (T::Class[T.type_parameter(:NewErrType)])
  • _block (T.proc.params(this: ErrType).returns(Result[OkType, T.type_parameter(:NewErrType)]))

Returns:



228
229
230
# File 'lib/mangrove/result.rb', line 228

def or_else_wt(_t_new_err, &_block)
  T.cast(self, Result::Ok[OkType, T.type_parameter(:NewErrType)])
end

#to_sString

Returns:

  • (String)


233
234
235
# File 'lib/mangrove/result.rb', line 233

def to_s
  "#{super}: inner=`#{@inner}`"
end

#unwrap!OkType

Returns:



150
151
152
# File 'lib/mangrove/result.rb', line 150

def unwrap!
  @inner
end