Skip to content

Commit 7486ce7

Browse files
committed
Fixes doc statement on half open ranges.
1 parent 59bd2b8 commit 7486ce7

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,19 @@ with switch(value) as s:
5858
value = 4 # matches first case
5959

6060
with switch(value) as s:
61-
s.case(range(1, 5), lambda: ...)
61+
s.case(range(1, 6), lambda: ...)
6262
s.case(range(6, 7), lambda: ...)
6363
s.default(lambda: ...)
6464
```
6565

66-
**Warning / open for debate**:
66+
**Closed vs. Open ranges**
6767

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.
68+
Looking at the above code it's a bit weird that 6 appears
69+
at the end of one case, beginning of the next. But `range()` is
70+
half open/closed.
7271

73-
Thoughts? I'm going with `1,2,3,4,5` for `range(1,5)` for now.
72+
To handle the inclusive case, I've added closed_range(start, stop).
73+
For example, closed_range(1,5) -> [1,2,3,4,5]
7474

7575
## Why not just raw `dict`?
7676

0 commit comments

Comments
 (0)