Class: Fear::Some

Inherits:
Object
  • Object
show all
Includes:
Option
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 Option

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

Constructor Details

#initialize(value) ⇒ Some

Returns a new instance of Some.



18
19
20
# File 'lib/fear/some.rb', line 18

def initialize(value)
  @value = value
end

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

  • other (Any)

Returns:

  • (Boolean)


57
58
59
# File 'lib/fear/some.rb', line 57

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

#empty?false

Returns:

  • (false)


33
34
35
# File 'lib/fear/some.rb', line 33

def empty?
  false
end

#getany

Returns:

  • (any)


23
24
25
# File 'lib/fear/some.rb', line 23

def get
  @value
end

#inspectString Also known as: to_s

Returns:

  • (String)


62
63
64
# File 'lib/fear/some.rb', line 62

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

#or_nilany

Returns:

  • (any)


28
29
30
# File 'lib/fear/some.rb', line 28

def or_nil
  @value
end

#rejectOption

Returns:



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

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

#selectOption

Returns:



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

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