diff --git a/pampy/pampy.py b/pampy/pampy.py index 1cb7746..54c5a13 100644 --- a/pampy/pampy.py +++ b/pampy/pampy.py @@ -142,7 +142,7 @@ def match_iterable(patterns, values) -> Tuple[bool, List]: -def match(var, *args, default=NoDefault, strict=True): +def match(var, *args, default=NoDefault, strict=True, run_callable=True): """ Match `var` against a number of potential patterns. @@ -181,7 +181,7 @@ def match(var, *args, default=NoDefault, strict=True): if matched_as_value: lambda_args = args if len(args) > 0 else BoxedArgs(var) - return run(action, lambda_args) + return run(action, lambda_args) if run_callable else action if default is NoDefault: if _ not in patterns: diff --git a/tests/test_basic.py b/tests/test_basic.py index c7114f0..2cd61a3 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -152,4 +152,9 @@ class Color(Enum): self.assertEqual(match(Color.RED, Color.BLUE, "blue", Color.RED, "red", _, "else"), "red") self.assertEqual(match(Color.RED, Color.BLUE, "blue", Color.GREEN, "green", _, "else"), "else") self.assertEqual(match(1, Color.BLUE, "blue", Color.GREEN, "green", _, "else"), "else") - \ No newline at end of file + + def test_match_no_run(self): + self.assertEqual(match(2, 2, lambda: 0, run_callable=False)(), 0) + def fn(): + return "xyz" + self.assertEqual(match(2, 2, fn, run_callable=False), fn)