pyfun-zeromode 0.1.0__tar.gz
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.
- pyfun_zeromode-0.1.0/PKG-INFO +9 -0
- pyfun_zeromode-0.1.0/README.md +0 -0
- pyfun_zeromode-0.1.0/pyproject.toml +17 -0
- pyfun_zeromode-0.1.0/src/pyfun/__init__.py +4 -0
- pyfun_zeromode-0.1.0/src/pyfun/maybe.py +47 -0
- pyfun_zeromode-0.1.0/src/pyfun/pipe.py +13 -0
- pyfun_zeromode-0.1.0/src/pyfun/py.typed +0 -0
|
File without changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "pyfun-zeromode"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Add your description here"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Avilay Parekh", email = "avilay@gmail.com" }
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.14"
|
|
10
|
+
dependencies = []
|
|
11
|
+
|
|
12
|
+
[build-system]
|
|
13
|
+
requires = ["uv_build>=0.9.26,<0.10.0"]
|
|
14
|
+
build-backend = "uv_build"
|
|
15
|
+
|
|
16
|
+
[tool.uv.build-backend]
|
|
17
|
+
module-name = "pyfun"
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Callable, assert_never
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass(frozen=True, slots=True)
|
|
8
|
+
class Some[T]:
|
|
9
|
+
value: T
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(frozen=True, slots=True)
|
|
13
|
+
class Nothing:
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
type Maybe[T] = Some[T] | Nothing
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def fmap[T, U](container: Maybe[T], func: Callable[[T], U]) -> Maybe[U]:
|
|
21
|
+
match container:
|
|
22
|
+
case Some(v):
|
|
23
|
+
return Some(func(v))
|
|
24
|
+
case Nothing():
|
|
25
|
+
return Nothing()
|
|
26
|
+
case _ as unreachable:
|
|
27
|
+
assert_never(unreachable)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def unwrap[T](container: Maybe[T]) -> T:
|
|
31
|
+
match container:
|
|
32
|
+
case Some(v):
|
|
33
|
+
return v
|
|
34
|
+
case Nothing():
|
|
35
|
+
raise RuntimeError("nothing to unwrap")
|
|
36
|
+
case _ as never:
|
|
37
|
+
assert_never(never)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def bind[T, U](container: Maybe[T], func: Callable[[T], Maybe[U]]) -> Maybe[U]:
|
|
41
|
+
match container:
|
|
42
|
+
case Some(v):
|
|
43
|
+
return func(v)
|
|
44
|
+
case Nothing():
|
|
45
|
+
return Nothing()
|
|
46
|
+
case _ as unreachable:
|
|
47
|
+
assert_never(unreachable)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Callable
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Pipe[T]:
|
|
7
|
+
__slots__ = ("value",)
|
|
8
|
+
|
|
9
|
+
def __init__(self, value: T) -> None:
|
|
10
|
+
self.value = value
|
|
11
|
+
|
|
12
|
+
def __or__[U](self, func: Callable[[T], U]) -> Pipe[U]:
|
|
13
|
+
return Pipe(func(self.value))
|
|
File without changes
|