from typing import Callable


def mask(lis: list, key: Callable, keep_last=None) -> list:
    """
    Create a mask on `lis` using the `key` function.
    `key` will be evaluated on pairs of items in `lis`.
    Returned list will only include items where `key` evaluates to True.
    Arguments:
        keep_last (boolean): In a sequence of items where key() is False,
                             keep the last one.
    """
    result = [lis[0]]
    for item in lis[1:]:
        if key(item, result[-1]):
            result.append(item)
        elif keep_last is True:
            result[-1] = item
    return result