require 'facets/core/enumerable/commonality'

module Enumerable

  # Like commonality but returns an array if no block is given.
  #
  def find_collisions( &blk ) #:yield:
    if block_given?
      commonality( &blk )
    else
      commonality.values.flatten.uniq
    end
  end

end



#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCEnumerable < Test::Unit::TestCase

    def test_find_collisions
      a = [1,2,2,3,3,3]
      assert_equal( [2,3], a.find_collisions )
      a = [1,2,2,3,3,3]
      r = {false=>[1, 2, 2], true=>[3, 3, 3]}
      assert_equal( r, a.find_collisions { |x| x > 2 } )
    end

  end

=end
