Class: Mayak::Monads::Try::Success

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

Constant Summary collapse

Value =
type_member

Instance Method Summary collapse

Methods included from Mayak::Monads::Try

#==, #as, check, #failure_as, guard, #recover_with_try, sequence

Constructor Details

#initialize(value) ⇒ Success

Returns a new instance of Success.



232
233
234
# File 'lib/mayak/monads/try.rb', line 232

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

Instance Method Details

#either(failure_branch, success_branch) ⇒ Object



309
310
311
# File 'lib/mayak/monads/try.rb', line 309

def either(failure_branch, success_branch)
  success_branch.call(@value)
end

#failure?Boolean

Returns:

  • (Boolean)


280
281
282
# File 'lib/mayak/monads/try.rb', line 280

def failure?
  false
end

#failure_or(value) ⇒ Object



295
296
297
# File 'lib/mayak/monads/try.rb', line 295

def failure_or(value)
  value
end

#filter_or(error, &blk) ⇒ Object



261
262
263
264
265
266
267
# File 'lib/mayak/monads/try.rb', line 261

def filter_or(error, &blk)
  if blk.call(@value)
    self
  else
    Mayak::Monads::Try::Failure[Value].new(error)
  end
end

#flat_map(&blk) ⇒ Object



252
253
254
# File 'lib/mayak/monads/try.rb', line 252

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

#flat_map_failure(&blk) ⇒ Object



338
339
340
# File 'lib/mayak/monads/try.rb', line 338

def flat_map_failure(&blk)
  self
end

#map(&blk) ⇒ Object



242
243
244
# File 'lib/mayak/monads/try.rb', line 242

def map(&blk)
  Mayak::Monads::Try::Success.new(blk.call(@value))
end

#map_failure(&blk) ⇒ Object



328
329
330
# File 'lib/mayak/monads/try.rb', line 328

def map_failure(&blk)
  self
end

#recover(value) ⇒ Object



376
377
378
# File 'lib/mayak/monads/try.rb', line 376

def recover(value)
  self
end

#recover_on(error_type, &blk) ⇒ Object



366
367
368
# File 'lib/mayak/monads/try.rb', line 366

def recover_on(error_type, &blk)
  self
end

#recover_with(&blk) ⇒ Object



386
387
388
# File 'lib/mayak/monads/try.rb', line 386

def recover_with(&blk)
  self
end

#successObject



270
271
272
# File 'lib/mayak/monads/try.rb', line 270

def success
  @value
end

#success?Boolean

Returns:

  • (Boolean)


275
276
277
# File 'lib/mayak/monads/try.rb', line 275

def success?
  true
end

#success_or(value) ⇒ Object



290
291
292
# File 'lib/mayak/monads/try.rb', line 290

def success_or(value)
  @value
end

#tee(&blk) ⇒ Object



318
319
320
321
# File 'lib/mayak/monads/try.rb', line 318

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

#to_maybeObject



353
354
355
# File 'lib/mayak/monads/try.rb', line 353

def to_maybe
  Mayak::Monads::Maybe::Some.new(@value)
end

#to_result(&blk) ⇒ Object



348
349
350
# File 'lib/mayak/monads/try.rb', line 348

def to_result(&blk)
  Mayak::Monads::Result::Success.new(@value)
end