Class: Mangrove::Result::Err

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, from_results, ok

Constructor Details

#initialize(inner) ⇒ void

Parameters:



238
239
240
# File 'lib/mangrove/result.rb', line 238

def initialize(inner)
  @inner = inner
end

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

  • other (BasicObject)

Returns:

  • (Boolean)


243
244
245
246
247
248
249
250
251
252
# File 'lib/mangrove/result.rb', line 243

def ==(other)
  case other
  when Result::Ok
    false
  when Result::Err
    other.instance_variable_get(:@inner) == @inner
  else
    false
  end
end

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

Parameters:

Returns:



312
313
314
# File 'lib/mangrove/result.rb', line 312

def and(_other)
  T.cast(self, Result::Err[T.type_parameter(:NewOkType), ErrType])
end

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

Parameters:

Returns:



317
318
319
# File 'lib/mangrove/result.rb', line 317

def and_then(&_block)
  T.cast(self, Result::Err[T.type_parameter(:NewOkType), ErrType])
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:



322
323
324
# File 'lib/mangrove/result.rb', line 322

def and_then_wt(_t_new_ok, &_block)
  T.cast(self, Result::Err[T.type_parameter(:NewOkType), ErrType])
end

#err?Boolean

Returns:

  • (Boolean)


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

def err? = true

#err_innerErrType

Returns:



255
256
257
# File 'lib/mangrove/result.rb', line 255

def err_inner
  @inner
end

#expect!(message) ⇒ OkType

Parameters:

  • message (String)

Returns:

Raises:



265
266
267
# File 'lib/mangrove/result.rb', line 265

def expect!(message)
  raise Result::ControlSignal, message
end

#expect_with!(&block) ⇒ OkType

Parameters:

  • block (T.proc.returns(T.untyped))

Returns:

Raises:



270
271
272
# File 'lib/mangrove/result.rb', line 270

def expect_with!(&block)
  raise Result::ControlSignal, block.call
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)])


281
282
283
# File 'lib/mangrove/result.rb', line 281

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:



302
303
304
# File 'lib/mangrove/result.rb', line 302

def map_err(&block)
  Result::Err[OkType, T.type_parameter(:NewErrType)].new(block.call(@inner))
end

#map_err_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(T.type_parameter(:NewErrType)))

Returns:



307
308
309
# File 'lib/mangrove/result.rb', line 307

def map_err_wt(_t_new_err, &block)
  Result::Err[OkType, T.type_parameter(:NewErrType)].new(block.call(@inner))
end

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

Parameters:

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

Returns:



291
292
293
# File 'lib/mangrove/result.rb', line 291

def map_ok(&_block)
  T.cast(self, Result::Err[T.type_parameter(:NewOkType), ErrType])
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:



297
298
299
# File 'lib/mangrove/result.rb', line 297

def map_ok_wt(_t_new_ok, &_block)
  T.cast(self, Result::Err[T.type_parameter(:NewOkType), ErrType])
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)])


286
287
288
# File 'lib/mangrove/result.rb', line 286

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

#ok?Boolean

Returns:

  • (Boolean)


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

def ok? = false

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

Parameters:

Returns:



327
328
329
# File 'lib/mangrove/result.rb', line 327

def or(other)
  other
end

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

Parameters:

Returns:



332
333
334
# File 'lib/mangrove/result.rb', line 332

def or_else(&block)
  block.call(@inner)
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:



337
338
339
# File 'lib/mangrove/result.rb', line 337

def or_else_wt(_t_new_err, &block)
  block.call(@inner)
end

#to_sString

Returns:

  • (String)


342
343
344
# File 'lib/mangrove/result.rb', line 342

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

#unwrap!OkType

Returns:

Raises:



260
261
262
# File 'lib/mangrove/result.rb', line 260

def unwrap!
  raise Result::ControlSignal, @inner
end