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

Constructor Details

#initialize(inner) ⇒ void

Parameters:



117
118
119
# File 'lib/mangrove/result.rb', line 117

def initialize(inner)
  @inner = inner
end

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

  • other (BasicObject)

Returns:

  • (Boolean)


122
123
124
125
126
127
128
129
130
131
# File 'lib/mangrove/result.rb', line 122

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

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

Parameters:

Returns:



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

def and(other)
  other
end

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

Parameters:

Returns:



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

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:



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

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

#err?Boolean

Returns:

  • (Boolean)


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

def err? = false

#expect!(_message) ⇒ OkType

Parameters:

  • _message (String)

Returns:



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

def expect!(_message)
  @inner
end

#expect_with!(&_block) ⇒ OkType

Parameters:

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

Returns:



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

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)])


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

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:



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

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:



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

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:



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

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:



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

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)])


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

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

#ok?Boolean

Returns:

  • (Boolean)


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

def ok? = true

#ok_innerOkType

Returns:



134
135
136
# File 'lib/mangrove/result.rb', line 134

def ok_inner
  @inner
end

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

Parameters:

Returns:



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

def or(_other)
  self
end

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

Parameters:

Returns:



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

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:



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

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

#to_sString

Returns:

  • (String)


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

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

#unwrap!OkType

Returns:



139
140
141
# File 'lib/mangrove/result.rb', line 139

def unwrap!
  @inner
end