import functools


def define_if(condition, errmsg="requested function not available"):
    """Decorator for conditional definition of a function.

    Parameters
    ----------
    condition : bool
        If True the function is called normally.  If False, a
        ``NotImplementedError`` is raised when the function is called.
    errmsg: str, optional
        The error message to print when ``condition`` is False.

    Returns
    -------
    func : function wrapper
    """

    def decorator(func):
        @functools.wraps(func)
        def func_wrapper(*args, **kwargs):
            if condition:
                return func(*args, **kwargs)
            else:
                raise NotImplementedError(errmsg)

        return func_wrapper

    return decorator