Class: Mayak::Monads::Maybe::Some

Inherits:
Object
  • Object
show all
Extended by:
T::Generic, T::Helpers, T::Sig
Includes:
Mayak::Monads::Maybe
Defined in:
lib/mayak/monads/maybe.rb

Constant Summary collapse

Value =
type_member

Instance Method Summary collapse

Methods included from Mayak::Monads::Maybe

#==, #as, check, guard, sequence

Constructor Details

#initialize(value) ⇒ Some

Returns a new instance of Some.



182
183
184
# File 'lib/mayak/monads/maybe.rb', line 182

def initialize(value)
  @value = T.let(value, Value)
end

Instance Method Details

#either(none_branch, some_branch) ⇒ Object



262
263
264
# File 'lib/mayak/monads/maybe.rb', line 262

def either(none_branch, some_branch)
  some_branch.call(@value)
end

#filter(&blk) ⇒ Object



211
212
213
214
215
216
217
# File 'lib/mayak/monads/maybe.rb', line 211

def filter(&blk)
  if blk.call(@value)
    self
  else
    Mayak::Monads::Maybe::None[Value].new
  end
end

#flat_map(&blk) ⇒ Object



202
203
204
# File 'lib/mayak/monads/maybe.rb', line 202

def flat_map(&blk)
  blk.call(@value)
end

#map(&blk) ⇒ Object



192
193
194
# File 'lib/mayak/monads/maybe.rb', line 192

def map(&blk)
  Mayak::Monads::Maybe::Some.new(blk.call(@value))
end

#none?Boolean

Returns:

  • (Boolean)


230
231
232
# File 'lib/mayak/monads/maybe.rb', line 230

def none?
  false
end

#recover(value) ⇒ Object



287
288
289
# File 'lib/mayak/monads/maybe.rb', line 287

def recover(value)
  self
end

#recover_with_maybe(maybe) ⇒ Object



297
298
299
# File 'lib/mayak/monads/maybe.rb', line 297

def recover_with_maybe(maybe)
  self
end

#some?Boolean

Returns:

  • (Boolean)


225
226
227
# File 'lib/mayak/monads/maybe.rb', line 225

def some?
  true
end

#tee(&blk) ⇒ Object



249
250
251
252
# File 'lib/mayak/monads/maybe.rb', line 249

def tee(&blk)
  blk.call(@value)
  self
end

#to_result(failure) ⇒ Object



272
273
274
# File 'lib/mayak/monads/maybe.rb', line 272

def to_result(failure)
  Mayak::Monads::Result::Success[T.type_parameter(:Failure), Value].new(@value)
end

#to_try(error) ⇒ Object



277
278
279
# File 'lib/mayak/monads/maybe.rb', line 277

def to_try(error)
  Mayak::Monads::Try::Success.new(@value)
end

#valueObject



220
221
222
# File 'lib/mayak/monads/maybe.rb', line 220

def value
  @value
end

#value_or(value) ⇒ Object



240
241
242
# File 'lib/mayak/monads/maybe.rb', line 240

def value_or(value)
  @value
end