Class: ReSorcery::Result::Err

Inherits:
Object
  • Object
show all
Defined in:
lib/re_sorcery/result/err.rb

Instance Method Summary collapse

Constructor Details

#initialize(err) ⇒ Err

Returns a new instance of Err.



6
7
8
# File 'lib/re_sorcery/result/err.rb', line 6

def initialize(err)
  @err = err
end

Instance Method Details

#==(other) ⇒ Object



34
35
36
# File 'lib/re_sorcery/result/err.rb', line 34

def ==(other)
  other.class == Err && other.instance_eval { @err } == @err
end

#and_thenObject



10
11
12
# File 'lib/re_sorcery/result/err.rb', line 10

def and_then
  self
end

#as_jsonObject



38
39
40
41
42
43
# File 'lib/re_sorcery/result/err.rb', line 38

def as_json(*)
  {
    kind: :err,
    value: @err,
  }
end

#assign(_name) ⇒ Object



26
27
28
# File 'lib/re_sorcery/result/err.rb', line 26

def assign(_name)
  self
end

#cata(ok:, err:) ⇒ Object



30
31
32
# File 'lib/re_sorcery/result/err.rb', line 30

def cata(ok:, err:)
  err.call(@err)
end

#mapObject



14
15
16
# File 'lib/re_sorcery/result/err.rb', line 14

def map
  self
end

#map_error(&block) ⇒ Object



18
19
20
# File 'lib/re_sorcery/result/err.rb', line 18

def map_error(&block)
  Err.new(block.call(@err))
end

#or_else(&block) ⇒ Object



22
23
24
# File 'lib/re_sorcery/result/err.rb', line 22

def or_else(&block)
  ArgCheck['block', block.call(@err), Ok, Err]
end