Class: Kleisli::Validation::Failure

Inherits:
Kleisli::Validation show all
Defined in:
lib/kleisli/validation.rb

Constant Summary

Constants inherited from Kleisli::Validation

VERSION

Instance Method Summary collapse

Constructor Details

#initialize(left) ⇒ Failure

Returns a new instance of Failure.



70
71
72
# File 'lib/kleisli/validation.rb', line 70

def initialize(left)
  @left = left
end

Instance Method Details

#*(other) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/kleisli/validation.rb', line 57

def *(other)
  if other.class == Failure
    unless self.left.class == other.left.class &&
            self.left.respond_to?(:sappend)
      raise ArgumentError,
              "Failures must contain members of a common Semigroup"
    end
    Failure(self.left.sappend(other.left))
  else
    self
  end
end

#>(f) ⇒ Object



74
75
76
# File 'lib/kleisli/validation.rb', line 74

def >(f)
  self
end

#fmap(&f) ⇒ Object



78
79
80
# File 'lib/kleisli/validation.rb', line 78

def fmap(&f)
  self
end

#or(other = self, &other_blk) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/kleisli/validation.rb', line 86

def or(other=self, &other_blk)
  if other_blk
    other_blk.call(@left)
  else
    other
  end
end

#to_maybeObject



82
83
84
# File 'lib/kleisli/validation.rb', line 82

def to_maybe
  Maybe::None.new
end

#to_sObject Also known as: inspect



94
95
96
# File 'lib/kleisli/validation.rb', line 94

def to_s
  "Failure(#{@left.inspect})"
end