Class: Stupidedi::Either::Failure

Inherits:
Stupidedi::Either show all
Defined in:
lib/stupidedi/either.rb

Direct Known Subclasses

Reader::Failure

Instance Attribute Summary collapse

Filtering the Value collapse

Transforming the Value collapse

Instance Method Summary collapse

Methods inherited from Stupidedi::Either

failure, success

Constructor Details

#initialize(reason) ⇒ Failure

Returns a new instance of Failure.



164
165
166
# File 'lib/stupidedi/either.rb', line 164

def initialize(reason)
  @reason = reason
end

Instance Attribute Details

#reasonObject (readonly)

Returns the value of attribute reason.



162
163
164
# File 'lib/stupidedi/either.rb', line 162

def reason
  @reason
end

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


240
241
242
# File 'lib/stupidedi/either.rb', line 240

def ==(other)
  other.is_a?(self.class) and other.reason == @reason
end

#copy(changes = {}) ⇒ Failure

Returns:



169
170
171
172
# File 'lib/stupidedi/either.rb', line 169

def copy(changes = {})
  Failure.new \
    changes.fetch(:reason, @reason)
end

#defined?Boolean

Returns false.

Returns:

  • (Boolean)

    false



175
176
177
# File 'lib/stupidedi/either.rb', line 175

def defined?
  false
end

#explain {|reason| ... } ⇒ Failure

Yield Parameters:

  • reason

Yield Returns:

  • reason

Returns:



228
229
230
# File 'lib/stupidedi/either.rb', line 228

def explain(&block)
  copy(:reason => deconstruct(block))
end

#fetch(default = nil) ⇒ Object



179
180
181
# File 'lib/stupidedi/either.rb', line 179

def fetch(default = nil)
  default
end

#flatmapFailure

Returns:



208
209
210
# File 'lib/stupidedi/either.rb', line 208

def flatmap
  self
end

#inspectString

Returns:

  • (String)


254
255
256
# File 'lib/stupidedi/either.rb', line 254

def inspect
  "Either.failure(#{@reason.inspect})"
end

#mapFailure

Returns:



203
204
205
# File 'lib/stupidedi/either.rb', line 203

def map
  self
end

#or {|reason| ... } ⇒ Either

Yield Parameters:

  • reason

Yield Returns:

Returns:



215
216
217
218
219
220
221
222
223
# File 'lib/stupidedi/either.rb', line 215

def or(&block)
  result = deconstruct(block)

  if result.is_a?(Either)
    result
  else
    raise TypeError, "block did not return an instance of Either"
  end
end

#pretty_print(q) ⇒ void

This method returns an undefined value.



245
246
247
248
249
250
251
# File 'lib/stupidedi/either.rb', line 245

def pretty_print(q)
  q.text("Either.failure")
  q.group(2, "(", ")") do
    q.breakable ""
    q.pp @reason
  end
end

#reject(reason = nil) ⇒ Failure

Returns:



192
193
194
# File 'lib/stupidedi/either.rb', line 192

def reject(reason = nil)
  self
end

#select(reason = nil) ⇒ Failure

Returns:



187
188
189
# File 'lib/stupidedi/either.rb', line 187

def select(reason = nil)
  self
end

#tapObject



235
236
237
# File 'lib/stupidedi/either.rb', line 235

def tap
  self
end