We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 59bd2b8 commit 7486ce7Copy full SHA for 7486ce7
README.md
@@ -58,19 +58,19 @@ with switch(value) as s:
58
value = 4 # matches first case
59
60
with switch(value) as s:
61
- s.case(range(1, 5), lambda: ...)
+ s.case(range(1, 6), lambda: ...)
62
s.case(range(6, 7), lambda: ...)
63
s.default(lambda: ...)
64
```
65
66
-**Warning / open for debate**:
+**Closed vs. Open ranges**
67
68
-I'm a little unsure what is the right way to handle this.
69
-On one hand, reading `case(range(1,5))` seems like it should
70
-include `1, 2, 3, 4, 5`. But `list(range(1,5))` is `[1,2,3,4]`.
71
-So that would be inconsistent.
+Looking at the above code it's a bit weird that 6 appears
+at the end of one case, beginning of the next. But `range()` is
+half open/closed.
72
73
-Thoughts? I'm going with `1,2,3,4,5` for `range(1,5)` for now.
+To handle the inclusive case, I've added closed_range(start, stop).
+For example, closed_range(1,5) -> [1,2,3,4,5]
74
75
## Why not just raw `dict`?
76
0 commit comments