Class: Fear::Some

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

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.



12
13
14
# File 'lib/fear/some.rb', line 12

def initialize(value)
  @value = value
end

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

  • other (Any)

Returns:

  • (Boolean)


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

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

#deconstructArray<any>

Returns:

  • (Array<any>)


92
93
94
# File 'lib/fear/some.rb', line 92

def deconstruct
  [get]
end

#empty?false Also known as: blank?

Returns:

  • (false)


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

def empty?
  false
end

#filter_map(&filter) ⇒ RightBiased::Left, RightBiased::Right

Returns:

  • (RightBiased::Left, RightBiased::Right)


87
88
89
# File 'lib/fear/some.rb', line 87

def filter_map(&filter)
  map(&filter).select(&:itself)
end

#getany

Returns:

  • (any)


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

def get
  @value
end

#inspectString Also known as: to_s

Returns:

  • (String)


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

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

#or_nilany

Returns:

  • (any)


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

def or_nil
  @value
end

#present?true

Returns:

  • (true)


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

def present?
  true
end

#rejectOption

Returns:



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

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

#selectOption

Returns:



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

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

#zip(other) ⇒ Fear::Option

Parameters:

Returns:



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/fear/some.rb', line 72

def zip(other)
  if other.is_a?(Option)
    other.map do |x|
      if block_given?
        yield(value, x)
      else
        [value, x]
      end
    end
  else
    raise TypeError, "can't zip with #{other.class}"
  end
end