def crash_on(condition, function=default_crash_messages, *args): def print_and_crash(): messages = function(*args) print('\n'.join(messages)) sys.exit(1) util.crossroad(lambda: condition, print_and_crash, util.noop)
def result_get_goal_points(result, goal_id): def is_correct_goal(goal): return goal.id == goal_id goal = util.find(is_correct_goal, result.goals) on_fail = lambda: 0 on_success = lambda: goal.points return util.crossroad(lambda: goal, on_success, on_fail)
def result_get_or_add_goal(result, rule): def on_fail(): goal = make_goal_from_rule(rule) result_add_goal(result, goal) return goal def is_correct_goal(goal): return rule.towards == goal.id def get_goal(): goal = util.find(is_correct_goal, result_get_goals(result)) return goal return util.crossroad(get_goal, get_goal, on_fail)
def get_problem_points(problem): return util.crossroad(lambda: isinstance(problem, str), lambda: 1, lambda: problem['points'])
def get_problem_id(problem): return util.crossroad(lambda: isinstance(problem, str), lambda: problem, lambda: problem['id'])
def process_rule(rule): needs = context.bool_expression(rule.needs) success = lambda: on_rule_success(rule) fail = lambda: on_rule_fail(rule) util.crossroad(lambda: needs, success, fail)