from itertools import groupby
from operator import itemgetter
from typing import Iterable
from typing import Optional
from typing import Callable
from typing import Iterator


def unique_justseen(it: Iterable, key: Optional[Callable] = None) -> Iterator:
    """
    List unique elements, preserving order. Remember only the element just seen.

    >>> ''.join(unique_justseen('AAAABBBCCDAABBB'))
    'ABCDAB'
    >>> ''.join(unique_justseen('ABBCcAD', str.lower))
    'ABCAD'
    """
    return map(next, map(itemgetter(1), groupby(it, key)))