from typing import Any
from typing import Callable


def ask_for_input(
    question: str, default: Any = None, callback: Callable[[Any], Any] = str
) -> Any:
    """
    Ask for input from the user at the command line.

    Parameters
    ----------
    question
        A string to display as a prompt for the user.
    default
        The default answer to the question.
    callback
        The return value of this callback is what is returned from this
        function. Useful for simple conversions, like receiving an integer
        instead of a raw string.

    Returns
    -------
    answer
        The input, passed through ``callback``.
    """
    while True:
        input_str = input(question + " [Default: {}] > ".format(default))

        trimmed = input_str.replace(" ", "")
        if trimmed == "":
            return default

        try:
            return callback(trimmed)
        except Exception as e:
            print(e)