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.
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.3
2
+ Name: pyfun-zeromode
3
+ Version: 0.1.0
4
+ Summary: Add your description here
5
+ Author: Avilay Parekh
6
+ Author-email: Avilay Parekh <avilay@gmail.com>
7
+ Requires-Python: >=3.14
8
+ Description-Content-Type: text/markdown
9
+
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,4 @@
1
+ from pyfun.maybe import Maybe, Nothing, Some, bind, fmap, unwrap
2
+ from pyfun.pipe import Pipe
3
+
4
+ __all__ = ["Maybe", "Nothing", "Some", "fmap", "bind", "Pipe", "unwrap"]
@@ -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