I have the following python function to recursively find all partitions of a set:
def partitions(set_):
if not set_:
yield []
return
You'll have to think of Ruby's yield like a call to a user-defined operation.
def twice
yield
yield
end
twice { puts "Hello" }
So whenever your code yields a value, a processing function for this element will be called.
partitions([1, 2, 3, 4].to_set) { |result|
# process result
}
This code doesn't generate a list at all.