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

from_results

Constructor Details

#initialize(inner) ⇒ void

Parameters:



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

def initialize(inner)
  @inner = inner
end

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

  • other (BasicObject)

Returns:

  • (Boolean)


151
152
153
154
155
156
157
158
159
160
# File 'lib/mangrove/result.rb', line 151

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

#err?Boolean

Returns:

  • (Boolean)


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

def err? = true

#err_innerErrType

Returns:



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

def err_inner
  @inner
end

#expect!(message) ⇒ OkType

Parameters:

  • message (String)

Returns:

Raises:



173
174
175
# File 'lib/mangrove/result.rb', line 173

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

#expect_with!(&block) ⇒ OkType

Parameters:

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

Returns:

Raises:



178
179
180
# File 'lib/mangrove/result.rb', line 178

def expect_with!(&block)
  raise Result::ControlSignal, block.call
end

#map_err(&block) ⇒ Result[OkType, ErrType]

Parameters:

Returns:



194
195
196
# File 'lib/mangrove/result.rb', line 194

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

#map_ok(&_block) ⇒ Result[OkType, ErrType]

Parameters:

Returns:



189
190
191
# File 'lib/mangrove/result.rb', line 189

def map_ok(&_block)
  self
end

#ok?Boolean

Returns:

  • (Boolean)


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

def ok? = false

#to_sString

Returns:

  • (String)


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

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

#unwrap!OkType

Returns:

Raises:



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

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