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
permalink
.instance ⇒ Object
[View source]
192
193
194
|
# File 'lib/maybe.rb', line 192
def self.instance
@instance ||= new
end
|
Instance Method Details
permalink
#ap(m) ⇒ Object
Also known as:
apply
[View source]
288
289
290
|
# File 'lib/maybe.rb', line 288
def ap(m)
self
end
|
permalink
#flat_map(&f) ⇒ Object
[View source]
275
276
277
|
# File 'lib/maybe.rb', line 275
def flat_map(&f)
self
end
|
[View source]
207
208
209
|
# File 'lib/maybe.rb', line 207
def get
raise NothingError, "cannot get the value of Nothing."
end
|
permalink
#get_or_else(&f) ⇒ Object
[View source]
222
223
224
|
# File 'lib/maybe.rb', line 222
def get_or_else(&f)
f.call
end
|
[View source]
314
315
316
|
# File 'lib/maybe.rb', line 314
def inspect
"Nothing"
end
|
[View source]
230
231
232
|
# File 'lib/maybe.rb', line 230
def just?
false
end
|
[View source]
256
257
258
|
# File 'lib/maybe.rb', line 256
def map(&f)
self
end
|
permalink
#nothing? ⇒ Boolean
[View source]
238
239
240
|
# File 'lib/maybe.rb', line 238
def nothing?
true
end
|