import typing


def __read_commands(stream: typing.TextIO, n: int, func: typing.Callable[[str], str]) -> list[str]:
    """Read the last N commands from the stream excluding the current process' command.

    :param stream: the TextIO object to read.
    :param n: the amount off lines to read.
    :param func: a function to apply to each of the returned lines to extract a command, the string passed to func
        will have any trailing whitespace stripped.
    :return: the unprocessed last n lines from the file.
    """
    return list(map(lambda cmd: func(cmd.rstrip()),
                    stream.readlines()[-(n + 1):-1]))