Skip to content

Commit a651786

Browse files
authored
Fixes effects example (#97)
* Fixes effects example * Fix type of effect * Update docs. Remove lagacy matching * Update pyright
1 parent cc16dca commit a651786

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ repos:
2828
language: node
2929
pass_filenames: false
3030
types: [python]
31-
additional_dependencies: ["[email protected].266"]
31+
additional_dependencies: ["[email protected].275"]
3232
repo: local
3333
- hooks:
3434
- id: jb-to-sphinx

README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ def keep_positive(a: int) -> Option[int]:
258258
```python
259259
from expression import Option, Ok
260260
def exists(x : Option[int]) -> bool:
261-
for value in x.match(Ok):
262-
return True
263-
261+
match x:
262+
case Some(_):
263+
return True
264264
return False
265265
```
266266

@@ -408,14 +408,10 @@ Now you may pattern match the shape to get back the actual value:
408408

409409
shape = Shape.Rectangle(2.3, 3.3)
410410

411-
with match(shape) as case:
412-
if case(Circle):
413-
assert False
414-
415-
for rect in case(Shape.RECTANGLE(width=2.3)):
416-
assert rect.length == 3.3
417-
418-
if case.default():
411+
match shape:
412+
case Shape(value=Rectangle(width=2.3)):
413+
assert shape.value.width == 2.3
414+
case _:
419415
assert False
420416
```
421417

docs/tutorial/effects.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,23 +150,24 @@ Effects are not the same as side-effects. Effects are just values with a context
150150
Expression have a nice way of dealing with effects and lets you safely work with wrapped values wihout having to error check:
151151

152152
```python
153-
from expression import effect
154-
from expression.core import option, Option, Some, Nothing
153+
from expression import effect, Option, Some, Nothing
155154

156-
def divide(a: float, divisor: float) -> Option[int]:
155+
156+
def divide(a: float, divisor: float) -> Option[float]:
157157
try:
158-
return Some(a/divisor)
158+
return Some(a / divisor)
159159
except ZeroDivisionError:
160160
return Nothing
161161

162162

163-
@effect.option
164-
def comp(x):
165-
result = yield from divide(42, x)
163+
@effect.option[float]()
164+
def comp(x: float):
165+
result: float = yield from divide(42, x)
166166
result += 32
167167
print(f"The result is {result}")
168168
return result
169169

170+
170171
comp(42)
171172
```
172173

0 commit comments

Comments
 (0)