from typing import Callable
import functools


def compose(*function: Callable) -> Callable:
    """Compose functions.
    I.e::

        ``lambda x: f(g(x))``
        can be written:
        ``compose(f, g)``

    Args:
        *function (Callable):
            Any number of functions to compose together.
            Output type of function N must be the input type of function N+1.

    Returns:
        Callable:
            A composed function with input type same as the firs function, and output
            type same as the last function.
    """
    return functools.reduce(lambda f, g: lambda x: f(g(x)), function, lambda x: x)