-
Notifications
You must be signed in to change notification settings - Fork 0
/
usage.py
49 lines (32 loc) · 955 Bytes
/
usage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from functools import partial
from typing import Union, List
from pypelines import pypeline
def add_two(x: int) -> int:
return x + 2
def make_double(x: int) -> int:
return x * 2
@pypeline()
def magic_computations(x: int) -> int:
return x | add_two | make_double
@pypeline()
def even_more_magic_comps(x: int) -> int:
return x | range | sum | (lambda x: x * 2)
@pypeline()
def magic_equation(x: int) -> bool:
return x | range | sum | make_double == 90
@pypeline()
def even_more_interesting_computations(x: int) -> List[int]:
return x | range | partial(map, lambda x: x * x) | list
def fizz_detector(x: int) -> Union[str, int]:
return (
"FizzBuzz"
if x % 15 == 0
else "Buzz"
if x % 5 == 0
else "Fizz"
if x % 3 == 0
else x
)
@pypeline()
def fizzbuzz(x: int) -> List[Union[str, int]]:
return x | partial(range, 1) | partial(map, fizz_detector) | list