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.



166
167
168
# File 'lib/stupidedi/either.rb', line 166

def initialize(reason)
  @reason = reason
end

Instance Attribute Details

#reasonObject (readonly)

Returns the value of attribute reason.



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

def reason
  @reason
end

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


242
243
244
# File 'lib/stupidedi/either.rb', line 242

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

#copy(changes = {}) ⇒ Failure

Returns:



171
172
173
174
# File 'lib/stupidedi/either.rb', line 171

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

#defined?Boolean

Returns false.

Returns:

  • (Boolean)

    false



177
178
179
# File 'lib/stupidedi/either.rb', line 177

def defined?
  false
end

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

Yield Parameters:

  • reason

Yield Returns:

  • reason

Returns:



230
231
232
# File 'lib/stupidedi/either.rb', line 230

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

#fetch(default = nil) ⇒ Object



181
182
183
# File 'lib/stupidedi/either.rb', line 181

def fetch(default = nil)
  default
end

#flatmapFailure

Returns:



210
211
212
# File 'lib/stupidedi/either.rb', line 210

def flatmap
  self
end

#inspectString

Returns:

  • (String)


256
257
258
# File 'lib/stupidedi/either.rb', line 256

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

#mapFailure

Returns:



205
206
207
# File 'lib/stupidedi/either.rb', line 205

def map
  self
end

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

Yield Parameters:

  • reason

Yield Returns:

Returns:



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

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.



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

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

#reject(reason = nil) ⇒ Failure

Returns:



194
195
196
# File 'lib/stupidedi/either.rb', line 194

def reject(reason = nil)
  self
end

#select(reason = nil) ⇒ Failure

Returns:



189
190
191
# File 'lib/stupidedi/either.rb', line 189

def select(reason = nil)
  self
end

#tapObject



237
238
239
# File 'lib/stupidedi/either.rb', line 237

def tap
  self
end