Class: Nothing
- Inherits:
-
Object
show all
- Includes:
- Contracts::Core, Maybe
- Defined in:
- lib/maybe.rb
Overview
Nothing is a member of the Maybe union type that represents a null value. It’s used in conjunction with the Just type to allow one to gracefully handle null values without having to create a large amount of conditional logic.
Constant Summary
collapse
- NothingError =
Class.new(RuntimeError)
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Maybe
Just, Nothing, #Proc, from_nullable, lift, of, zip
Class Method Details
.instance ⇒ Object
192
193
194
|
# File 'lib/maybe.rb', line 192
def self.instance
@instance ||= new
end
|
Instance Method Details
#==(m) ⇒ Object
302
303
304
|
# File 'lib/maybe.rb', line 302
def ==(m)
m.is_a?(Nothing)
end
|
#ap(m) ⇒ Object
Also known as:
apply
288
289
290
|
# File 'lib/maybe.rb', line 288
def ap(m)
self
end
|
#flat_map(&f) ⇒ Object
275
276
277
|
# File 'lib/maybe.rb', line 275
def flat_map(&f)
self
end
|
#get ⇒ Object
207
208
209
|
# File 'lib/maybe.rb', line 207
def get
raise NothingError, "cannot get the value of Nothing."
end
|
#get_or_else(&f) ⇒ Object
222
223
224
|
# File 'lib/maybe.rb', line 222
def get_or_else(&f)
f.call
end
|
#inspect ⇒ Object
314
315
316
|
# File 'lib/maybe.rb', line 314
def inspect
"Nothing"
end
|
#just? ⇒ Boolean
230
231
232
|
# File 'lib/maybe.rb', line 230
def just?
false
end
|
#map(&f) ⇒ Object
256
257
258
|
# File 'lib/maybe.rb', line 256
def map(&f)
self
end
|
#nothing? ⇒ Boolean
238
239
240
|
# File 'lib/maybe.rb', line 238
def nothing?
true
end
|