Class: Zx::Maybe::Some

Inherits:
Zx::Maybe show all
Defined in:
lib/zx/maybe.rb

Constant Summary

Constants inherited from Zx::Maybe

IsBlank

Instance Attribute Summary

Attributes inherited from Zx::Maybe

#value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Zx::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

Returns a new instance of Some.



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

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

Class Method Details

.[]Object



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

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

Instance Method Details

#>(other) ⇒ Object



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

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

#deconstructObject



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

def deconstruct
  [@value]
end

#fmap(&block) ⇒ Object



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

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

#inspectObject



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

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

#to_sObject



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

def to_s
  'Some'
end