lib/rumonade/either.rb in rumonade-0.2.1 vs lib/rumonade/either.rb in rumonade-0.2.2

- old
+ new

@@ -41,9 +41,19 @@ # @return [RightProjection] Projects this Either as a Right. def right RightProjection.new(self) end + + # @param [Either] other the either to combine with + # @return [Either] Returns a +Left+ with all Left values (if any), otherwise a +Right+ with all Right values + def +(other) + if [self, other].any?(&:left?) + Left([self, other].map { |either| either.left.to_opt }.flatten) + else + Right([self, other].map { |either| either.right.to_opt }.flatten) + end + end end # The left side of the disjoint union, as opposed to the Right side. class Left < Either # @param left_value the value to store in a +Left+, usually representing a failure result \ No newline at end of file