Skip to content
instance method

Set#divide

() { (A, A) -> ::Hash::_Key } -> ::Set[self]
() { (A) -> ::Hash::_Key } -> ::Set[self]
divide { |o1, o2| ... } → set
divide { |o| ... } → set
divide → enumerator

Divides the set into a set of subsets according to the commonality defined by the given block.

If the arity of the block is 2, elements o1 and o2 are in common if both block.call(o1, o2) and block.call(o2, o1) are true. Otherwise, elements o1 and o2 are in common if block.call(o1) == block.call(o2).

Example
numbers = Set[1, 3, 4, 6, 9, 10, 11]
set = numbers.divide { |i,j| (i - j).abs == 1 }
set        #=> Set[Set[1],
           #       Set[3, 4],
           #       Set[6],
           #       Set[9, 10, 11]]

Returns an enumerator if no block is given.

See also #disjoint? #each #difference #empty? also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0