from typing import OrderedDict


def groupby_name(bindings, tier=0):
    """
    Groups bindings by the name fragment specified by tier. Input bindings
    can be not sorted. The order of the bindings remains initial in scope of
    its group.

    Yields:
        (name, [binding(s)...]) tuples.
    """
    res = OrderedDict()
    for binding in bindings:
        name_at_tier = binding.qualname[tier]
        if name_at_tier in res:
            res[name_at_tier].append(binding)
        else:
            res[name_at_tier] = [binding]
    return res