Class: Jade::Ok

Inherits:
Data
  • Object
show all
Defined in:
lib/jade/result.rb

Instance Method Summary collapse

Constructor Details

#initialize(ok: nil) ⇒ Ok

Returns a new instance of Ok.



5
6
7
# File 'lib/jade/result.rb', line 5

def initialize(ok: nil)
  super
end

Instance Method Details

#and_tapObject



18
19
20
21
22
23
24
# File 'lib/jade/result.rb', line 18

def and_tap
  result = yield(ok)
  case result
  in Ok then self
  in Err then result
  end
end

#and_then {|ok| ... } ⇒ Object

Yields:

  • (ok)


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

def and_then
  yield(ok)
end

#and_then_combineObject



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

def and_then_combine
  result = yield(ok)
  case result
  in Ok(ok2) then Ok.new([*ok, ok2])
  in Err(_) then result
  end
end

#error?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/jade/result.rb', line 57

def error?
  false
end

#mapObject Also known as: map_both



9
10
11
# File 'lib/jade/result.rb', line 9

def map
  Ok.new(yield(ok))
end

#map2(result) ⇒ Object



30
31
32
33
34
35
# File 'lib/jade/result.rb', line 30

def map2(result)
  case result
  in Ok(ok2) then Ok.new(yield(ok, ok2))
  in Err(_) then result
  end
end

#map_errorObject



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

def map_error
  self
end

#ok?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/jade/result.rb', line 53

def ok?
  true
end

#on_err(_error_type = nil) ⇒ Object



45
46
47
# File 'lib/jade/result.rb', line 45

def on_err(_error_type = nil)
  self
end

#with_default(_default) ⇒ Object



49
50
51
# File 'lib/jade/result.rb', line 49

def with_default(_default)
  ok
end