<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_compartments(self, stream, compartments, adjacencies, properties=None):
 """Write iterable of compartments as YAML object to stream. Args: stream: File-like object. compartments: Iterable of compartment entries. adjacencies: Dictionary mapping IDs to adjacent compartment IDs. properties: Set of compartment properties to output (or None to output all). """

        def convert(entry):
            return self.convert_compartment_entry(
                entry, adjacencies.get(entry.id))

        self._write_entries(stream, compartments, convert, properties)