-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutilities.py
More file actions
51 lines (28 loc) · 982 Bytes
/
Copy pathutilities.py
File metadata and controls
51 lines (28 loc) · 982 Bytes
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
50
51
from typing import Any, Callable, Iterable, Optional, TypeVar
A = TypeVar('A')
B = TypeVar('B')
C = TypeVar('C')
def idem(x: A) -> A:
return x
def equals(x: A) -> Callable[[A], bool]:
return lambda y: x == y
def first(tuple: tuple[A, B]) -> A:
(a, b) = tuple
return a
def second(tuple: tuple[A, B]) -> B:
(a, b) = tuple
return b
def strs(xs: Any) -> list[str]:
return list(map(str, xs))
def compose2(f: Callable[[B], C], g: Callable[[A], B]) -> Callable[[A], C]:
return lambda x: f(g(x))
def fromOptional(value: Optional[A], fallback: A) -> A:
return value if value is not None else fallback
def itemList(prefix: str, strs: Iterable[str]) -> str:
return "\n".join(map(lambda s: prefix + s, strs))
def stripIndentation(string: str) -> str:
return "\n".join(map(lambda line: line.lstrip(), string.split("\n")))
def flag(name: str) -> str:
return "--" + name
def shortFlag(name: str) -> str:
return "-" + name