pythonic-fp-fptools 6.0.0__tar.gz → 6.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pythonic-fp-fptools
3
- Version: 6.0.0
3
+ Version: 6.1.0
4
4
  Summary: Functional programming tools for Python.
5
5
  Keywords: either,fp,functional,functional programming,lazy,maybe,monad,non-strict
6
6
  Author-email: "Geoffrey R. Scheller" <geoffrey@scheller.com>
@@ -15,9 +15,9 @@ Classifier: Programming Language :: Python :: 3.14
15
15
  Classifier: Programming Language :: Python :: 3.15
16
16
  Classifier: Typing :: Typed
17
17
  License-File: LICENSE
18
- Requires-Dist: pythonic-fp-booleans>=3.0.2
19
- Requires-Dist: pythonic-fp-circulararray>=6.0.4
20
- Requires-Dist: pythonic-fp-gadgets>=4.0.2
18
+ Requires-Dist: pythonic-fp-booleans>=5,<6
19
+ Requires-Dist: pythonic-fp-circulararray>=6.2.2,<6.4
20
+ Requires-Dist: pythonic-fp-gadgets>=4.5.0,<6
21
21
  Project-URL: Changelog, https://github.com/grscheller/pythonic-fp-fptools/blob/main/CHANGELOG.md
22
22
  Project-URL: Documentation, https://grscheller.github.io/pythonic-fp-fptools/release/html/
23
23
  Project-URL: Homepage, https://grscheller.github.io/pythonic-fp/
@@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"
4
4
 
5
5
  [project]
6
6
  name = "pythonic-fp-fptools"
7
- version = "6.0.0"
7
+ version = "6.1.0"
8
8
  description = "Functional programming tools for Python."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.14" # floor: PEP 649/749 deferred annotations — class-level self-reference NameErrors on <3.14
@@ -32,9 +32,9 @@ classifiers = [
32
32
  "Typing :: Typed",
33
33
  ]
34
34
  dependencies = [
35
- "pythonic-fp-booleans>=3.0.2",
36
- "pythonic-fp-circulararray>=6.0.4",
37
- "pythonic-fp-gadgets>=4.0.2",
35
+ "pythonic-fp-booleans>=5,<6",
36
+ "pythonic-fp-circulararray>=6.2.2,<6.4",
37
+ "pythonic-fp-gadgets>=4.5.0,<6",
38
38
  ]
39
39
 
40
40
  [project.urls]
@@ -50,9 +50,6 @@ docs = [
50
50
  ]
51
51
  test = [
52
52
  "pytest>=8.4.1",
53
- "pythonic-fp-containers>=4.0.1",
54
- "pythonic-fp-iterables>=5.1.3",
55
- "pythonic-fp-queues>=5.1.1",
56
53
  ]
57
54
 
58
55
  [tool.flit.module]
@@ -41,8 +41,9 @@ class State[S, A]:
41
41
  Instance members:
42
42
 
43
43
  - Property *run* is the **state action**
44
- - Method *bind* performs state action composition
45
- - Method *eval* performs the **run action**
44
+ - Method ``bind`` performs state action composition
45
+ - Method ``then`` performs
46
+ - Method ``eval`` performs the **run action**
46
47
 
47
48
  - the **run action** evaluates the **state action** by
48
49
 
@@ -78,16 +79,37 @@ class State[S, A]:
78
79
  """
79
80
  self.run = run
80
81
 
82
+ def eval(self, init: S) -> A:
83
+ """
84
+ .. admonition:: run action
85
+
86
+ Evaluate the state action by passing in an initial state
87
+ and returning the produced value.
88
+
89
+ :param init: An initial state to pass into the state action.
90
+ :returns: The value produced by the run action.
91
+
92
+ """
93
+ a, _ = self.run(init)
94
+ return a
95
+
81
96
  def bind[B](self, g: Callable[[A], State[S, B]]) -> State[S, B]:
82
97
  """
83
98
  .. admonition:: state action composition
84
99
 
100
+ Run the first action, use its result to compose
101
+ a new state action.
102
+
85
103
  :param g: A function that produces a State[S, B]
86
104
  from an A.
87
105
  :returns: A State[S, B] whose state action is the
88
106
  composition of the state actions from self
89
107
  followed by the one produced by g.
90
108
 
109
+ .. note::
110
+
111
+ Same as the Haskell ``>>=`` operator.
112
+
91
113
  """
92
114
 
93
115
  def compose(s: S) -> tuple[B, S]:
@@ -96,19 +118,19 @@ class State[S, A]:
96
118
 
97
119
  return State(compose)
98
120
 
99
- def eval(self, init: S) -> A:
121
+ def then[B](self, sb: State[S, B]) -> State[S, B]:
100
122
  """
101
- .. admonition:: run action
123
+ .. admonition:: sequence two state actions
102
124
 
103
- Evaluate the state action by passing in an initial state
104
- and returning the produced value.
125
+ Run the first action, discard its result,
126
+ then run the second action.
105
127
 
106
- :param init: An initial state to pass into the state action.
107
- :returns: The value produced by the run action.
128
+ .. note::
129
+
130
+ Same as the Haskell ``>>`` operator.
108
131
 
109
132
  """
110
- a, _ = self.run(init)
111
- return a
133
+ return self.bind(lambda _: sb)
112
134
 
113
135
  def map[B](self, f: Callable[[A], B]) -> State[S, B]:
114
136
  """
@@ -230,7 +252,7 @@ class State[S, A]:
230
252
  return State.get().bind(lambda a: State.put(f(a)))
231
253
 
232
254
  @staticmethod
233
- def sequence[ST, AA](sas: list[State[ST, AA]]) -> State[ST, list[AA]]:
255
+ def sequence[ST, AA](sa_list: list[State[ST, AA]]) -> State[ST, list[AA]]:
234
256
  """
235
257
  .. admonition:: sequence a list
236
258
 
@@ -253,9 +275,10 @@ class State[S, A]:
253
275
  """
254
276
 
255
277
  def append_ret(ls: list[AA], a: AA) -> list[AA]:
256
- ls.append(a)
257
- return ls
278
+ copy = ls.copy()
279
+ copy.append(a)
280
+ return copy
258
281
 
259
- return CA(sas).foldl(
282
+ return CA(sa_list).foldl(
260
283
  lambda s1, sa: s1.map2(sa, append_ret), State.unit(list[AA]([]))
261
284
  )