Add `Comparable#uniq`; CRuby2.4

parent 4e365156
......@@ -708,4 +708,20 @@ module Enumerable
def nil.to_h
{}
end
def uniq(&block)
hash = {}
if block
self.each do|*v|
v = v.__svalue
hash[block.call(v)] ||= v
end
else
self.each do|*v|
v = v.__svalue
hash[v] ||= v
end
end
hash.values
end
end
......@@ -158,6 +158,21 @@ class Enumerator
}
end
def uniq(&block)
hash = {}
Lazy.new(self){|yielder, val|
if block
v = block.call(val)
else
v = val
end
unless hash.include?(v)
yielder << val
hash[v] = val
end
}
end
alias force to_a
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment