<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def get_stim(self, type_, return_all=False):
        ''' Returns component elements of the specified type.

        Args:
            type_ (str or Stim class): the desired Stim subclass to return.
            return_all (bool): when True, returns all elements that matched the
                specified type as a list. When False (default), returns only
                the first matching Stim.

        Returns:
            If return_all is True, a list of matching elements (or an empty
            list if no elements match). If return_all is False, returns the
            first matching Stim, or None if no elements match.
        '''
        if isinstance(type_, string_types):
            type_ = _get_stim_class(type_)
        matches = []
        for s in self.elements:
            if isinstance(s, type_):
                if not return_all:
                    return s
                matches.append(s)
        if not matches:
            return [] if return_all else None
        return matches