class Just

Just is a member of the Maybe union type that represents a non-null value. It's used in conjunction with the Nothing type to allow one to gracefully handle null values without having to create a large amount of conditional logic.

Constants

C

Public Class Methods

new(value) click to toggle source
# File lib/maybe.rb, line 329
def initialize(value)
  @value = value
end

Public Instance Methods

==(m) click to toggle source
# File lib/maybe.rb, line 444
def ==(m)
  m.is_a?(Just) && m.get == get
end
ap(m) click to toggle source
# File lib/maybe.rb, line 427
def ap(m)
  m.flat_map {|f| map(&f) }
end
Also aliased as: apply
apply(m)
Alias for: ap
flat_map(&f) click to toggle source
# File lib/maybe.rb, line 414
def flat_map(&f)
  f.call(@value)
end
get() click to toggle source
# File lib/maybe.rb, line 343
def get
  @value
end
get_or_else(&f) click to toggle source
# File lib/maybe.rb, line 357
def get_or_else(&f)
  @value
end
inspect() click to toggle source
# File lib/maybe.rb, line 456
def inspect
  "Just(#{@value.inspect})"
end
just?() click to toggle source
# File lib/maybe.rb, line 365
def just?
  true
end
map(&f) click to toggle source
# File lib/maybe.rb, line 391
def map(&f)
  flat_map {|value| Maybe.of(f.call(value)) }
end
nothing?() click to toggle source
# File lib/maybe.rb, line 373
def nothing?
  false
end