pyfun-zeromode 1.1.0__tar.gz → 1.2.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyfun-zeromode
3
- Version: 1.1.0
3
+ Version: 1.2.0
4
4
  Summary: Functional programming constructs (Maybe, Pipe) for Python
5
5
  Author: Avilay Parekh
6
6
  Author-email: Avilay Parekh <avilay@gmail.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pyfun-zeromode"
3
- version = "1.1.0"
3
+ version = "1.2.0"
4
4
  description = "Functional programming constructs (Maybe, Pipe) for Python"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -20,3 +20,9 @@ build-backend = "uv_build"
20
20
 
21
21
  [tool.uv.build-backend]
22
22
  module-name = "pyfun"
23
+
24
+ [dependency-groups]
25
+ dev = [
26
+ "ipykernel>=7.4.0",
27
+ "pytest>=9.2.0",
28
+ ]
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pyfun-zeromode"
3
- version = "1.1.0"
3
+ version = "1.2.0"
4
4
  description = "Functional programming constructs (Maybe, Pipe) for Python"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -21,3 +21,9 @@ build-backend = "uv_build"
21
21
 
22
22
  [tool.uv.build-backend]
23
23
  module-name = "pyfun"
24
+
25
+ [dependency-groups]
26
+ dev = [
27
+ "ipykernel>=7.4.0",
28
+ "pytest>=9.2.0",
29
+ ]
@@ -1,8 +1,9 @@
1
1
  from dataclasses import dataclass
2
2
  from functools import wraps
3
- from typing import Callable
3
+ from typing import Callable, final
4
4
 
5
5
 
6
+ @final
6
7
  @dataclass(frozen=True, slots=True)
7
8
  class Some[T]:
8
9
  value: T
@@ -16,6 +17,10 @@ class Some[T]:
16
17
  def then[U](self, func: Callable[[], Maybe[U]]) -> Maybe[U]:
17
18
  return func()
18
19
 
20
+ def filter(self, pred: Callable[[T], bool]) -> Maybe[T]:
21
+ """Keeps this value if pred returns True for it, otherwise gives Nothing()."""
22
+ return self if pred(self.value) else Nothing[T]()
23
+
19
24
  def value_or(self, default: T) -> T:
20
25
  return self.value
21
26
 
@@ -23,6 +28,7 @@ class Some[T]:
23
28
  return self.value
24
29
 
25
30
 
31
+ @final
26
32
  @dataclass(frozen=True, slots=True)
27
33
  class Nothing[T]:
28
34
  def map[U](self, func: Callable[[T], U]) -> Nothing[U]:
@@ -34,6 +40,10 @@ class Nothing[T]:
34
40
  def then[U](self, func: Callable[[], Maybe[U]]) -> Nothing[U]:
35
41
  return Nothing()
36
42
 
43
+ def filter(self, pred: Callable[[T], bool]) -> Nothing[T]:
44
+ """Returns Nothing() without calling pred."""
45
+ return self
46
+
37
47
  def value_or(self, default: T) -> T:
38
48
  return default
39
49
 
File without changes