Class: Fear::Some

Inherits:
Object
  • Object
show all
Includes:
Option, RightBiased::Right
Defined in:
lib/fear/some.rb

Constant Summary collapse

EXTRACTOR =
proc do |option|
  if Fear::Some === option
    Fear.some([option.get])
  else
    Fear.none
  end
end

Instance Method Summary collapse

Methods included from RightBiased::Right

#===, #any?, #each, #flat_map, #get_or_else, #include?, included, #map, #or_else, #to_option

Methods included from Option

#any?, #each, #flat_map, #get_or_else, #include?, #left_class, #map, #match, match, matcher, #or_else, #right_class

Constructor Details

#initialize(value) ⇒ Some

Returns a new instance of Some.


20
21
22
# File 'lib/fear/some.rb', line 20

def initialize(value)
  @value = value
end

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

  • other (Any)

Returns:

  • (Boolean)

59
60
61
# File 'lib/fear/some.rb', line 59

def ==(other)
  other.is_a?(Some) && get == other.get
end

#empty?false

Returns:

  • (false)

35
36
37
# File 'lib/fear/some.rb', line 35

def empty?
  false
end

#getany

Returns:

  • (any)

25
26
27
# File 'lib/fear/some.rb', line 25

def get
  @value
end

#inspectString Also known as: to_s

Returns:

  • (String)

64
65
66
# File 'lib/fear/some.rb', line 64

def inspect
  "#<Fear::Some get=#{value.inspect}>"
end

#or_nilany

Returns:

  • (any)

30
31
32
# File 'lib/fear/some.rb', line 30

def or_nil
  @value
end

#rejectOption

Returns:


49
50
51
52
53
54
55
# File 'lib/fear/some.rb', line 49

def reject
  if yield(value)
    None
  else
    self
  end
end

#selectOption

Returns:


40
41
42
43
44
45
46
# File 'lib/fear/some.rb', line 40

def select
  if yield(value)
    self
  else
    None
  end
end