from typing import OrderedDict


def unique_by(l, fn):
    """Return a filtered list such that a given function is unique
    for each element of the list.

    Parameters
    ----------
    l : list
        A list of arbitrary objects.
    fn : function
        Must return a hashable object.

    Returns
    -------
    list
        A list of unique elements according to `fn`.
    """
    by_key = OrderedDict(zip([fn(_) for _ in l], l))
    return list(by_key.values())