Sha256: 0697a2c3c7ed6609ad929c5abc8c68d4d5896246dfd17aada5dc16d13550b279
Contents?: true
Size: 769 Bytes
Versions: 1
Compression:
Stored size: 769 Bytes
Contents
class Some include Option attr_reader :value def initialize(value) @value = value end def each &block block.call(value) end def none?(&block) block.nil? ? false : super end def value_or(default=nil) value end def some?(type=value.class) value.class == type end def & other other.and_option(self) end def == other other.is_a?(Some) && value == other.value end def | other self end def merge(other, &block) other.match do |m| m.some { |v| block.nil? ? Some[([value] + [v]).flatten] : Some[block.call(value, v)] } m.none { self } end end def to_s "Some[#{value.inspect}]" end def self.[](*values) new(values.size == 1 ? values.first : values) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
optional-0.0.7 | lib/optional/some.rb |