Skip to content

Commit

Permalink
Update pipeline example and test to include currying
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinitto committed Feb 9, 2023
1 parent 6fc14a7 commit 66ff540
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions funml/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ def execute(*args: Any, **kwargs: Any) -> ExecutionExpression:
```python
import funml as ml
output = ml.val(90) >> (lambda x: x**2) >> (lambda v: v/90) >> ml.execute()
# prints 90
to_power_of = ml.val(lambda power, v: v**power)
divided_by = ml.val(lambda divisor, v: v / divisor)
output = ml.val(90) >> to_power_of(3) >> divided_by(90) >> divided_by(3) >> ml.execute()
# prints 2700
```
"""
return ExecutionExpression(*args, **kwargs)
8 changes: 6 additions & 2 deletions tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@

def test_execute():
"""execute terminates pipeline"""
to_power_of = val(lambda power, v: v**power)
divided_by = val(lambda divisor, v: v / divisor)
with_suffix = val(lambda suffix, v: f"{v}{suffix}")

test_data = [
(val(90) >> (lambda x: x**2) >> (lambda v: v / 90), 90),
(val(90) >> to_power_of(3) >> divided_by(90) >> divided_by(3), 2700),
(
val("hey") >> (lambda x: f"{x} you") >> (lambda g: f"{g}, John"),
val("hey") >> with_suffix(" you") >> with_suffix(f", John"),
"hey you, John",
),
]
Expand Down

0 comments on commit 66ff540

Please sign in to comment.