Beispiel #1
0
def round_(x, precision=0):
    """Round number to precision.

    Args:
        x (number): Number to round.
        precision (int, optional): Rounding precision. Defaults to ``0``.

    Returns:
        int: Rounded number.

    Example:

        >>> round_(3.275) == 3.0
        True
        >>> round_(3.275, 1) == 3.3
        True

    See Also:
        - :func:`round_` (main definition)
        - :func:`curve` (alias)

    .. versionadded:: 2.1.0
    """
    rounder = pyd.partial_right(round, precision)

    if pyd.is_number(x):
        result = rounder(x)
    elif pyd.is_list(x):
        # pylint: disable=unnecessary-lambda
        result = pyd.map_(x, lambda item: rounder(item))
    else:
        result = None

    return result
Beispiel #2
0
def test_partial_right(case, case_args, case_kargs, args, expected):
    assert _.partial_right(case, *case_args, **case_kargs)(*args) == expected