Class: Mona::Result::OK

Inherits:
Object
  • Object
show all
Defined in:
lib/mona/result/ok.rb

Overview

A Successful (OK) result

Since:

  • 0.1.0

Direct Known Subclasses

Dict::OK

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ OK

Returns a new instance of OK.

Since:

  • 0.1.0



7
8
9
# File 'lib/mona/result/ok.rb', line 7

def initialize(value)
  @value = value.freeze
end

Instance Attribute Details

#valueObject (readonly)

Since:

  • 0.1.0



11
12
13
# File 'lib/mona/result/ok.rb', line 11

def value
  @value
end

Instance Method Details

#and_tapObject

Since:

  • 0.1.0



27
# File 'lib/mona/result/ok.rb', line 27

def and_tap(&) = tap { yield @value }

#and_thenObject

Since:

  • 0.1.0



25
# File 'lib/mona/result/ok.rb', line 25

def and_then(&) = Result[yield @value]

#deconstructObject

Since:

  • 0.1.0



31
# File 'lib/mona/result/ok.rb', line 31

def deconstruct = [:ok, @value]

#deconstruct_keys(_keys = nil) ⇒ Object

Since:

  • 0.1.0



33
# File 'lib/mona/result/ok.rb', line 33

def deconstruct_keys(_keys = nil) = { ok: @value }

#either(ok, _err) ⇒ Object

Since:

  • 0.1.0



23
# File 'lib/mona/result/ok.rb', line 23

def either(ok, _err) = ok.call(@value)

#errObject

Since:

  • 0.1.0



21
# File 'lib/mona/result/ok.rb', line 21

def err(&) = nil

#err?Boolean

Returns:

  • (Boolean)

Since:

  • 0.1.0



17
# File 'lib/mona/result/ok.rb', line 17

def err? = false

#ok {|@value| ... } ⇒ Object

Yields:

Since:

  • 0.1.0



19
# File 'lib/mona/result/ok.rb', line 19

def ok(&) = yield @value

#ok?Boolean

Returns:

  • (Boolean)

Since:

  • 0.1.0



15
# File 'lib/mona/result/ok.rb', line 15

def ok? = true

#or_elseObject

Since:

  • 0.1.0



29
# File 'lib/mona/result/ok.rb', line 29

def or_else(&) = self

#to_resultObject

Since:

  • 0.1.0



35
# File 'lib/mona/result/ok.rb', line 35

def to_result = self

#to_sObject Also known as: inspect

Since:

  • 0.1.0



37
# File 'lib/mona/result/ok.rb', line 37

def to_s = "#<OK #{@value.inspect}>"

#value_orObject

Since:

  • 0.1.0



13
# File 'lib/mona/result/ok.rb', line 13

def value_or(&) = @value