Download pool/shard008/Python/0071463_tree.py from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 660 Bytes
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard008/Python/0071463_tree.py
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/pool/shard008/Python/0071463_tree.py
-
curl -L -o 0071463_tree.py https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard008/Python/0071463_tree.py
660 Bytes
| from typing import NamedTuple, TypeVar, Callable | |
| A = TypeVar("A") | |
| R = TypeVar("R") | |
| Branch = Callable[[R, R], R] | |
| class BinaryTree(NamedTuple): | |
| constructor: Callable[[R, Branch[R]], R] | |
| def __call__(self, leaf: R, branch: Branch[R]): | |
| return self.constructor(leaf, branch) | |
| def leaf(cls): | |
| def leafer(leaf: R, branch: Branch[R]) -> R: | |
| return leaf | |
| return cls(leafer) | |
| def branch(cls, left, right): | |
| def brancher(leaf: R, branch: Branch[R]) -> R: | |
| return branch(left, right) | |
| return cls(brancher) | |
| class BT(NamedTuple): | |
| left: "BT" | |
| right: "BT" |