-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(task): add
sghi.task.Task
composition support (#36)
Add support for `sghi.task.Task` instances composition. `Task` instances can be composed using the `<<` and `>>` operators. See the example below: ```python import operator from functools import partial from sghi.task import Task, task add_100: Task[int, int] = task(partial(operator.add, 100)) int_from_str: Task[str, int] = task(int) int_to_str: Task[int, str] = task(str) mul_by_10: Task[int, int] = task(partial(operator.mul, 10)) chained: Task[int, str] = add_100 >> mul_by_10 >> int_to_str composed: Task[str, int] = add_100 << mul_by_10 << int_from_str assert isinstance(chained, Task) assert isinstance(composed, Task) assert chained(50) == "1500" assert composed("50") == 600 ```
- Loading branch information
1 parent
0ff6c46
commit 53ca0fb
Showing
3 changed files
with
380 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.