Class: Maybe::Some

Inherits:
Maybe
  • Object
show all
Defined in:
lib/maybe.rb

Constant Summary

Constants inherited from Maybe

IsBlank

Instance Attribute Summary

Attributes inherited from Maybe

#value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Maybe

#>>, #apply!, #dig, #dig!, #map, #map!, #match, #none?, #of, of, #on, #on_failure, #on_success, #or, #some?, #type, #unwrap

Constructor Details

#initialize(value = nil) ⇒ Some



123
124
125
# File 'lib/maybe.rb', line 123

def initialize(value = nil)
  @value = value
end

Class Method Details

.[]Object



119
120
121
# File 'lib/maybe.rb', line 119

def self.[](...)
  new(...)
end

Instance Method Details

#>(other) ⇒ Object



139
140
141
# File 'lib/maybe.rb', line 139

def >(other)
  other.respond_to?(:call) ? other.call(@value) : other
end

#deconstructObject



127
128
129
# File 'lib/maybe.rb', line 127

def deconstruct
  [@value]
end

#fmap(&block) ⇒ Object



143
144
145
# File 'lib/maybe.rb', line 143

def fmap(&block)
  Maybe[block.call(@value)]
end

#inspectObject



131
132
133
# File 'lib/maybe.rb', line 131

def inspect
  format("#<Zx::Maybe::#{self}:0x%x value=%s>", object_id, @value.inspect)
end

#to_sObject



135
136
137
# File 'lib/maybe.rb', line 135

def to_s
  'Some'
end