Module: TypedCache::Either

Includes:
Kernel
Defined in:
lib/typed_cache/either.rb

Overview

@rbs! type either[out E, out R] = (Left | Right) & _Either[E, R]

Class Method Summary collapse

Class Method Details

.left(error) ⇒ Object

: [E] (E) -> either[E, bot]



11
12
# File 'lib/typed_cache/either.rb', line 11

def left(error) = Left.new(error)
#: [R] (R) -> either[bot, R]

.right(value) ⇒ Object

: [R] ® -> either[bot, R]



13
# File 'lib/typed_cache/either.rb', line 13

def right(value) = Right.new(value)

.wrap(value, error_class = StandardError) ⇒ Object

: [E, R] (E | R) -> either[E, R]



16
17
18
19
20
21
22
23
# File 'lib/typed_cache/either.rb', line 16

def wrap(value, error_class = StandardError)
  case value
  when Left, Right then value
  when error_class then Left.new(value)
  else
    Right.new(value)
  end
end