Beispiel #1
0
def test_max_by():
    def square(n):
        return n * n

    assert_equal(min_by(square, -3, 2), 2)
    assert_equal(reduce(min_by(square), 0, [3, -5, 4, 1, -2]), 0)
    assert_equal(reduce(min_by(square), 0, []), 0)
Beispiel #2
0
def max_by_test():
    def square(n):
        return n * n

    assert_equal(max_by(square, -3, 2), -3)
    assert_equal(reduce(max_by(square), 0, [3, -5, 4, 1, -2]), -5)
    assert_equal(reduce(max_by(square), 0, []), 0)
Beispiel #3
0
def any_pass(ps, v):
    """Takes a list of predicates and returns a predicate that returns true for a
    given list of arguments if at least one of the provided predicates is
    satisfied by those arguments.
    The function returned is a curried function whose arity matches that of the
    highest-arity predicate"""
    return reduce(either, always(False), ps)(v)
Beispiel #4
0
def any_pass(ps, v):
    return reduce(either, always(False), ps)(v)
Beispiel #5
0
def all_pass(ps, v):
    return reduce(both, always(True), ps)(v)
Beispiel #6
0
from ramda.curry import curry
from ramda.reduce import reduce
from .multiply import multiply

product = reduce(multiply, 1)