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)
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)
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)
def any_pass(ps, v): return reduce(either, always(False), ps)(v)
def all_pass(ps, v): return reduce(both, always(True), ps)(v)
from ramda.curry import curry from ramda.reduce import reduce from .multiply import multiply product = reduce(multiply, 1)