wird 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wird/__init__.py +7 -0
- wird/_future.py +110 -0
- wird/_value.py +65 -0
- wird/py.typed +0 -0
- wird-1.0.0.dist-info/METADATA +12 -0
- wird-1.0.0.dist-info/RECORD +7 -0
- wird-1.0.0.dist-info/WHEEL +4 -0
wird/__init__.py
ADDED
wird/_future.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import (
|
|
5
|
+
Any,
|
|
6
|
+
Awaitable,
|
|
7
|
+
Callable,
|
|
8
|
+
Concatenate,
|
|
9
|
+
Generator,
|
|
10
|
+
Type,
|
|
11
|
+
overload,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
__all__ = ("Future",)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass(slots=True, frozen=True)
|
|
18
|
+
class Future[T]:
|
|
19
|
+
internal: Awaitable[T]
|
|
20
|
+
|
|
21
|
+
@staticmethod
|
|
22
|
+
def from_[V](value: V) -> Future[V]:
|
|
23
|
+
async def _identity() -> V:
|
|
24
|
+
return value
|
|
25
|
+
|
|
26
|
+
return Future(_identity())
|
|
27
|
+
|
|
28
|
+
@overload
|
|
29
|
+
def unwrap(self) -> Awaitable[T]: ...
|
|
30
|
+
|
|
31
|
+
@overload
|
|
32
|
+
def unwrap[R](self, *, as_type: Type[R]) -> Awaitable[R]: ...
|
|
33
|
+
|
|
34
|
+
def unwrap(self, **_) -> Awaitable[Any]:
|
|
35
|
+
return self.internal
|
|
36
|
+
|
|
37
|
+
def map[**P, R](
|
|
38
|
+
self,
|
|
39
|
+
fn: Callable[Concatenate[T, P], R],
|
|
40
|
+
*args: P.args,
|
|
41
|
+
**kwargs: P.kwargs,
|
|
42
|
+
) -> Future[R]:
|
|
43
|
+
return Future(_map(self.internal, fn, *args, **kwargs))
|
|
44
|
+
|
|
45
|
+
def inspect[**P](
|
|
46
|
+
self,
|
|
47
|
+
fn: Callable[Concatenate[T, P], Any],
|
|
48
|
+
*args: P.args,
|
|
49
|
+
**kwargs: P.kwargs,
|
|
50
|
+
) -> Future[T]:
|
|
51
|
+
return Future(_inspect(self.internal, fn, *args, **kwargs))
|
|
52
|
+
|
|
53
|
+
def map_async[**P, R](
|
|
54
|
+
self,
|
|
55
|
+
fn: Callable[Concatenate[T, P], Awaitable[R]],
|
|
56
|
+
*args: P.args,
|
|
57
|
+
**kwargs: P.kwargs,
|
|
58
|
+
) -> Future[R]:
|
|
59
|
+
return Future(_map_async(self.internal, fn, *args, **kwargs))
|
|
60
|
+
|
|
61
|
+
def inspect_async[**P](
|
|
62
|
+
self,
|
|
63
|
+
fn: Callable[Concatenate[T, P], Awaitable[Any]],
|
|
64
|
+
*args: P.args,
|
|
65
|
+
**kwargs: P.kwargs,
|
|
66
|
+
) -> Future[T]:
|
|
67
|
+
return Future(_inspect_async(self.internal, fn, *args, **kwargs))
|
|
68
|
+
|
|
69
|
+
def __await__(self) -> Generator[Any, Any, T]:
|
|
70
|
+
return self.internal.__await__()
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
async def _map[T, **P, R](
|
|
74
|
+
value: Awaitable[T],
|
|
75
|
+
fn: Callable[Concatenate[T, P], R],
|
|
76
|
+
*args: P.args,
|
|
77
|
+
**kwargs: P.kwargs,
|
|
78
|
+
) -> R:
|
|
79
|
+
return fn(await value, *args, **kwargs)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
async def _inspect[T, **P](
|
|
83
|
+
value: Awaitable[T],
|
|
84
|
+
fn: Callable[Concatenate[T, P], Any],
|
|
85
|
+
*args: P.args,
|
|
86
|
+
**kwargs: P.kwargs,
|
|
87
|
+
) -> T:
|
|
88
|
+
_value = await value
|
|
89
|
+
fn(_value, *args, **kwargs)
|
|
90
|
+
return _value
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
async def _map_async[T, **P, R](
|
|
94
|
+
value: Awaitable[T],
|
|
95
|
+
fn: Callable[Concatenate[T, P], Awaitable[R]],
|
|
96
|
+
*args: P.args,
|
|
97
|
+
**kwargs: P.kwargs,
|
|
98
|
+
) -> R:
|
|
99
|
+
return await fn(await value, *args, **kwargs)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
async def _inspect_async[T, **P](
|
|
103
|
+
value: Awaitable[T],
|
|
104
|
+
fn: Callable[Concatenate[T, P], Awaitable[Any]],
|
|
105
|
+
*args: P.args,
|
|
106
|
+
**kwargs: P.kwargs,
|
|
107
|
+
) -> T:
|
|
108
|
+
_value = await value
|
|
109
|
+
await fn(_value, *args, **kwargs)
|
|
110
|
+
return _value
|
wird/_value.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Any, Awaitable, Callable, Concatenate, Type, overload
|
|
5
|
+
|
|
6
|
+
from . import _future as f
|
|
7
|
+
|
|
8
|
+
__all__ = ("Value",)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(slots=True, frozen=True)
|
|
12
|
+
class Value[T]:
|
|
13
|
+
internal: T
|
|
14
|
+
|
|
15
|
+
@overload
|
|
16
|
+
def unwrap(self) -> T: ...
|
|
17
|
+
|
|
18
|
+
@overload
|
|
19
|
+
def unwrap[R](self, *, as_type: Type[R]) -> R: ...
|
|
20
|
+
|
|
21
|
+
def unwrap(self, **_) -> Any:
|
|
22
|
+
return self.internal
|
|
23
|
+
|
|
24
|
+
def map[**P, R](
|
|
25
|
+
self,
|
|
26
|
+
fn: Callable[Concatenate[T, P], R],
|
|
27
|
+
*args: P.args,
|
|
28
|
+
**kwargs: P.kwargs,
|
|
29
|
+
) -> Value[R]:
|
|
30
|
+
return Value(fn(self.internal, *args, **kwargs))
|
|
31
|
+
|
|
32
|
+
def inspect[**P](
|
|
33
|
+
self,
|
|
34
|
+
fn: Callable[Concatenate[T, P], Any],
|
|
35
|
+
*args: P.args,
|
|
36
|
+
**kwargs: P.kwargs,
|
|
37
|
+
) -> Value[T]:
|
|
38
|
+
fn(self.internal, *args, **kwargs)
|
|
39
|
+
return self
|
|
40
|
+
|
|
41
|
+
def map_async[**P, R](
|
|
42
|
+
self,
|
|
43
|
+
fn: Callable[Concatenate[T, P], Awaitable[R]],
|
|
44
|
+
*args: P.args,
|
|
45
|
+
**kwargs: P.kwargs,
|
|
46
|
+
) -> f.Future[R]:
|
|
47
|
+
return f.Future(fn(self.internal, *args, **kwargs))
|
|
48
|
+
|
|
49
|
+
def inspect_async[**P](
|
|
50
|
+
self,
|
|
51
|
+
fn: Callable[Concatenate[T, P], Awaitable[Any]],
|
|
52
|
+
*args: P.args,
|
|
53
|
+
**kwargs: P.kwargs,
|
|
54
|
+
) -> f.Future[T]:
|
|
55
|
+
return f.Future(_inspect_async(self.internal, fn, *args, **kwargs))
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
async def _inspect_async[T, **P](
|
|
59
|
+
value: T,
|
|
60
|
+
fn: Callable[Concatenate[T, P], Awaitable[Any]],
|
|
61
|
+
*args: P.args,
|
|
62
|
+
**kwargs: P.kwargs,
|
|
63
|
+
) -> T:
|
|
64
|
+
await fn(value, *args, **kwargs)
|
|
65
|
+
return value
|
wird/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wird
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Basic monads for implementing pipe-styled processing
|
|
5
|
+
Project-URL: Repository, https://github.com/katunilya/wird
|
|
6
|
+
Project-URL: Issues, https://github.com/katunilya/wird/issues
|
|
7
|
+
Author-email: Ilya Katun <katun.ilya@gmail.com>
|
|
8
|
+
Maintainer-email: Ilya Katun <katun.ilya@gmail.com>
|
|
9
|
+
Requires-Python: >=3.13
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# wird
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
wird/__init__.py,sha256=GtVwwTM9vUGrkdBJzxWnA0WmJHiPpP-JvRshMXWIWyo,96
|
|
2
|
+
wird/_future.py,sha256=IH8_2kXlZBamfHDrI1Xid7FrUMRb6fvSzVPd94RfD-8,2545
|
|
3
|
+
wird/_value.py,sha256=XfNWZrEolvGmASnmroxXtyAud-7fJLAdKjRa9t9aCRE,1553
|
|
4
|
+
wird/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
wird-1.0.0.dist-info/METADATA,sha256=SOV9O1pgoIn4dn24duv2xuLLOhI7GFV2lvTv23NblDA,403
|
|
6
|
+
wird-1.0.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
7
|
+
wird-1.0.0.dist-info/RECORD,,
|