from typing import Callable
import ast


def eval_lambda(val: str) -> Callable:
    """Parse a lambda from a string safely.

    Args:
        val: string representing a lambda.

    Returns:
        a callable.

    Raises:
        ValueError: in case the lambda can not be parsed.
    """
    parsed_lamba = ast.parse(val).body[0].value  # type:ignore
    if isinstance(parsed_lamba, ast.Lambda) and "eval" not in val:
        return eval(val)
    else:
        raise ValueError(f"'{val}' can not be safely parsed as a lambda function")