'Set a collection value from an iterable of state-bearers.
``adapter`` is an optional callable invoked with a CollectionAdapter
and the iterable.  Should return an iterable of state-bearing
instances suitable for appending via a CollectionAdapter.  Can be used
for, e.g., adapting an incoming dictionary into an iterator of values
rather than keys.'

def _set_iterable(self, state, dict_, iterable, adapter=None):

    (new_collection, user_data) = self._initialize_collection(state)
    if adapter:
        new_values = list(adapter(new_collection, iterable))
    else:
        new_values = list(iterable)
    old = self.get(state, dict_, passive=PASSIVE_ONLY_PERSISTENT)
    if (old is PASSIVE_NO_RESULT):
        old = self.initialize(state, dict_)
    elif (old is iterable):
        return
    state._modified_event(dict_, self, old, True)
    old_collection = getattr(old, '_sa_adapter')
    dict_[self.key] = user_data
    collections.bulk_replace(new_values, old_collection, new_collection)
    old_collection.unlink(old)
