From 985bf9fed202b2088a318373ff81e146166568c4 Mon Sep 17 00:00:00 2001 From: Julian Fleischer Date: Sun, 2 Jan 2022 13:58:33 +0100 Subject: [PATCH] Fix #11 --- README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a1fde93..0d7abcb 100644 --- a/README.md +++ b/README.md @@ -660,6 +660,23 @@ Takes the optional values `exactly`, `at_least`, and `at_most` which makes `Some either `exactly` _n_ items, `at_least` _n_, or `at_most` _n_ items (`at_least` and `at_most` can be given at the same time, but not together with `exactly`). +Note the difference between `Some(1, 2)` and `Some([1, 2])`. The first version matches subsequences, the second +version matches items which are themselves lists: + +```python +match([0, 1, 2 , 1, 2 , 3], [0, Some( 1, 2 ), 3]) # matches the subsequence 1, 2 twice +match([0, [1, 2], [1, 2], 3], [0, Some([1, 2]), 3]) # matches the item [1, 2] twice, which happen to be lists +``` + +`Some` also goes by the names of `Many` and `Remaining`, which is sometimes nice to convey meaning: + +```python +match(range(1, 10), [1, 2, 'remaining' @ Remaining()]) +match([0, 1, 1, 1, 2, 1], [0, Many(1), Remaining(InstanceOf(int))]) +``` + +When used with no arguments, `Some()` is the same as `Some(...)`. + ### `Between(lower, upper)` @@ -800,7 +817,7 @@ if result := match("2020-08-27", Transformed(date.fromisoformat, 'date' @ _): ### `At(path, pattern)` -Checks whether the nested object to be matched satisfied pattern at the given path. The match fails if the given path +Checks whether the nested object to be matched satisfies pattern at the given path. The match fails if the given path can not be resolved. ```python