Class: Nothing

Inherits:
Object
  • 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

.instanceObject

[View source]

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

def self.instance
  @instance ||= new
end

Instance Method Details

#==(m) ⇒ Object

[View source]

302
303
304
# File 'lib/maybe.rb', line 302

def ==(m)
  m.is_a?(Nothing)
end

#ap(m) ⇒ Object Also known as: apply

[View source]

288
289
290
# File 'lib/maybe.rb', line 288

def ap(m)
  self
end

#flat_map(&f) ⇒ Object

[View source]

275
276
277
# File 'lib/maybe.rb', line 275

def flat_map(&f)
  self
end

#getObject

Raises:

[View source]

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

[View source]

222
223
224
# File 'lib/maybe.rb', line 222

def get_or_else(&f)
  f.call
end

#inspectObject

[View source]

314
315
316
# File 'lib/maybe.rb', line 314

def inspect
  "Nothing"
end

#just?Boolean

Returns:

  • (Boolean)
[View source]

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

def just?
  false
end

#map(&f) ⇒ Object

[View source]

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

def map(&f)
  self
end

#nothing?Boolean

Returns:

  • (Boolean)
[View source]

238
239
240
# File 'lib/maybe.rb', line 238

def nothing?
  true
end