dtools.fp 1.3.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.
- dtools/fp/__init__.py +34 -0
- dtools/fp/err_handling.py +436 -0
- dtools/fp/function.py +71 -0
- dtools/fp/iterables.py +413 -0
- dtools/fp/lazy.py +126 -0
- dtools/fp/py.typed +0 -0
- dtools/fp/singletons.py +238 -0
- dtools/fp/state.py +107 -0
- dtools_fp-1.3.0.dist-info/LICENSE +176 -0
- dtools_fp-1.3.0.dist-info/METADATA +58 -0
- dtools_fp-1.3.0.dist-info/RECORD +12 -0
- dtools_fp-1.3.0.dist-info/WHEEL +4 -0
dtools/fp/singletons.py
ADDED
@@ -0,0 +1,238 @@
|
|
1
|
+
# Copyright 2023-2025 Geoffrey R. Scheller
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
"""### Module fp.singletons - collection of singleton classes
|
16
|
+
|
17
|
+
Classes permitting at most only one instantiation. Safer, but not as performant,
|
18
|
+
than a non-exported module level global. Difficult, but not impossible, for
|
19
|
+
a typical end-user to exploit. Different versions tailored for different use
|
20
|
+
cases.
|
21
|
+
|
22
|
+
#### Singleton types:
|
23
|
+
|
24
|
+
* **class NoValue:** singleton instance representing the absence of a value
|
25
|
+
* **Class Sentinel:** singleton instances used as a "hidden" sentinel value
|
26
|
+
* **class Nada:** singleton instance representing & propagating failure
|
27
|
+
|
28
|
+
##### `NoValue` was designed as a None replacement
|
29
|
+
|
30
|
+
While `None` represents "returned no values," `NoValue()` represents the absence
|
31
|
+
of a value. Non-existing values should not be comparable to anything, even
|
32
|
+
themselves. End-users may use both `None` and `()` as sentinel values which
|
33
|
+
colliding with using either to represent "nothingness."
|
34
|
+
|
35
|
+
---
|
36
|
+
|
37
|
+
##### `Sentinel` values used as hidden implementation details
|
38
|
+
|
39
|
+
* Here is another implementation for Sentinel:``
|
40
|
+
* on GitHub: [taleinat/python-stdlib-sentinels](https://github.com/taleinat/python-stdlib-sentinels)
|
41
|
+
* on PyPI: [Project: Sentinels](https://pypi.org/project/sentinels/)
|
42
|
+
* see: [PEP 661](https://peps.python.org/pep-0661/)
|
43
|
+
|
44
|
+
Initially this one was somewhat close to mine and also enabled pickling.
|
45
|
+
Subsequently it was "enhanced" to allow sentinel values to be subclassed. My
|
46
|
+
implementation is substantially more simple, python implementation independent,
|
47
|
+
less Gang-of-Four OOP, and more Pythonic.
|
48
|
+
|
49
|
+
---
|
50
|
+
|
51
|
+
##### `Nada` propagates failure
|
52
|
+
|
53
|
+
Nada is a singleton representing & propagating failure. Failure just blissfully
|
54
|
+
propagates down "the happy path." For almost everything you do with it, it just
|
55
|
+
returns itself. The maintainer has not used this construct enough yet to
|
56
|
+
determine if it is a brilliant idea or a horrible blunder.
|
57
|
+
"""
|
58
|
+
from __future__ import annotations
|
59
|
+
|
60
|
+
__all__ = [ 'NoValue', 'Sentinel', 'Nada' ]
|
61
|
+
|
62
|
+
from collections.abc import Callable, Iterator
|
63
|
+
from typing import Any, Final, final
|
64
|
+
|
65
|
+
class NoValue():
|
66
|
+
"""Singleton class representing a missing value.
|
67
|
+
|
68
|
+
* similar to `None` but
|
69
|
+
* while `None` represents "returned no values"
|
70
|
+
* `NoValue()` represents the absence of a value
|
71
|
+
* usage
|
72
|
+
* `import NoValue from dtools.fp.err_handling` and then
|
73
|
+
* either use `NoValue()` directly
|
74
|
+
* or define `_noValue: Final[NoValue] = NoValue()` don't export it
|
75
|
+
* compare using `is` and `is not`
|
76
|
+
* not `==` or `!=`
|
77
|
+
* `None` means returned no values, so `None == None` makes sense
|
78
|
+
* if one or both values are missing, then what is there to compare?
|
79
|
+
|
80
|
+
"""
|
81
|
+
__slots__ = ()
|
82
|
+
_instance: NoValue|None = None
|
83
|
+
|
84
|
+
def __new__(cls) -> NoValue:
|
85
|
+
if cls._instance is None:
|
86
|
+
cls._instance = super(NoValue, cls).__new__(cls)
|
87
|
+
return cls._instance
|
88
|
+
|
89
|
+
def __init__(self) -> None:
|
90
|
+
return
|
91
|
+
|
92
|
+
def __repr__(self) -> str:
|
93
|
+
return 'NoValue()'
|
94
|
+
|
95
|
+
def __eq__(self, other: object) -> bool:
|
96
|
+
return False
|
97
|
+
|
98
|
+
@final
|
99
|
+
class Sentinel():
|
100
|
+
"""Singleton classes representing a sentinel values.
|
101
|
+
|
102
|
+
* intended for library code, not to be exported/shared between modules
|
103
|
+
* otherwise some of its intended typing guarantees may be lost
|
104
|
+
* useful substitute for `None` as a hidden sentinel value
|
105
|
+
* allows `None` to be stored in data structures
|
106
|
+
* allows end users to choose to use `None` or `()` as sentinel values
|
107
|
+
* always equals itself (unlike `noValue`)
|
108
|
+
* usage
|
109
|
+
* import Sentinel and then either
|
110
|
+
* define `_my_sentinel: Final[Sentinel] = Sentinel('my_sentinel')`
|
111
|
+
* or use `Sentinel('my_sentinel')` directly
|
112
|
+
* compare using either
|
113
|
+
* `is` and `is not` or `==` and `!=`
|
114
|
+
* the `Sentinel()` value always equals itself
|
115
|
+
* and never equals anything else, especially other sentinel values
|
116
|
+
|
117
|
+
"""
|
118
|
+
__slots__ = '_sentinel_name',
|
119
|
+
_instances: dict[str, Sentinel] = {}
|
120
|
+
|
121
|
+
def __new__(cls, sentinel_name: str) -> Sentinel:
|
122
|
+
if sentinel_name not in cls._instances:
|
123
|
+
cls._instances[sentinel_name] = super(Sentinel, cls).__new__(cls)
|
124
|
+
return cls._instances[sentinel_name]
|
125
|
+
|
126
|
+
def __init__(self, sentinel_name: str) -> None:
|
127
|
+
self._sentinel_name = sentinel_name
|
128
|
+
return
|
129
|
+
|
130
|
+
def __repr__(self) -> str:
|
131
|
+
return "Sentinel('" + self._sentinel_name + "')"
|
132
|
+
|
133
|
+
@final
|
134
|
+
class Nada():
|
135
|
+
"""Singleton class representing & propagating failure.
|
136
|
+
|
137
|
+
* singleton `_nada: nada = Nada()` represents a non-existent value
|
138
|
+
* returns itself for arbitrary method calls
|
139
|
+
* returns itself if called as a Callable with arbitrary arguments
|
140
|
+
* interpreted as an empty container by standard Python functions
|
141
|
+
* warning: non-standard equality semantics
|
142
|
+
* comparison compares true only when 2 non-missing values compare true
|
143
|
+
* thus `a == b` means two non-missing values compare as equal
|
144
|
+
* usage
|
145
|
+
* import `Nada` and then
|
146
|
+
* either use `Nada()` directly
|
147
|
+
* or define `_nada: Final[Nada] = Nada()` don't export it
|
148
|
+
* start propagating failure by setting a propagating value to Nada()
|
149
|
+
* works best when working with expression
|
150
|
+
* failure may fail to propagate
|
151
|
+
* for a function/method with just side effects
|
152
|
+
* engineer Nada() to fail to trigger side effects
|
153
|
+
* test for failure by comparing a result to `Nada()` itself using
|
154
|
+
* `is` and `is not`
|
155
|
+
* propagate failure through a calculation using
|
156
|
+
* `==` and `!=`
|
157
|
+
* the `Nada()` value never equals itself
|
158
|
+
* and never equals anything else
|
159
|
+
|
160
|
+
"""
|
161
|
+
__slots__ = ()
|
162
|
+
_instance: Nada|None = None
|
163
|
+
_hash: int = 0
|
164
|
+
|
165
|
+
sentinel: Final[Sentinel] = Sentinel('Nada')
|
166
|
+
|
167
|
+
def __new__(cls) -> Nada:
|
168
|
+
if cls._instance is None:
|
169
|
+
cls._instance = super(Nada, cls).__new__(cls)
|
170
|
+
cls._hash = hash((cls._instance, (cls._instance,)))
|
171
|
+
return cls._instance
|
172
|
+
|
173
|
+
def __iter__(self) -> Iterator[Any]:
|
174
|
+
return iter(())
|
175
|
+
|
176
|
+
def __hash__(self) -> int:
|
177
|
+
return self._hash
|
178
|
+
|
179
|
+
def __repr__(self) -> str:
|
180
|
+
return 'Nada()'
|
181
|
+
|
182
|
+
def __bool__(self) -> bool:
|
183
|
+
return False
|
184
|
+
|
185
|
+
def __len__(self) -> int:
|
186
|
+
return 0
|
187
|
+
|
188
|
+
def __add__(self, right: Any) -> Nada:
|
189
|
+
return Nada()
|
190
|
+
|
191
|
+
def __radd__(self, left: Any) -> Nada:
|
192
|
+
return Nada()
|
193
|
+
|
194
|
+
def __mul__(self, right: Any) -> Nada:
|
195
|
+
return Nada()
|
196
|
+
|
197
|
+
def __rmul__(self, left: Any) -> Nada:
|
198
|
+
return Nada()
|
199
|
+
|
200
|
+
def __eq__(self, right: Any) -> bool:
|
201
|
+
return False
|
202
|
+
|
203
|
+
def __ne__(self, right: Any) -> bool:
|
204
|
+
return True
|
205
|
+
|
206
|
+
def __ge__(self, right: Any) -> bool:
|
207
|
+
return False
|
208
|
+
|
209
|
+
def __gt__(self, right: Any) -> bool:
|
210
|
+
return False
|
211
|
+
|
212
|
+
def __le__(self, right: Any) -> bool:
|
213
|
+
return False
|
214
|
+
|
215
|
+
def __lt__(self, right: Any) -> bool:
|
216
|
+
return False
|
217
|
+
|
218
|
+
def __getitem__(self, index: int|slice) -> Any:
|
219
|
+
return Nada()
|
220
|
+
|
221
|
+
def __setitem__(self, index: int|slice, item: Any) -> None:
|
222
|
+
return
|
223
|
+
|
224
|
+
def __call__(self, *args: Any, **kwargs: Any) -> Any:
|
225
|
+
return Nada()
|
226
|
+
|
227
|
+
def __getattr__(self, name: str) -> Callable[..., Any]:
|
228
|
+
def method(*args: tuple[Any], **kwargs: dict[str, Any]) -> Any:
|
229
|
+
return Nada()
|
230
|
+
return method
|
231
|
+
|
232
|
+
def nada_get(self, alt: Any=sentinel) -> Any:
|
233
|
+
"""Get an alternate value, defaults to `Nada()`."""
|
234
|
+
if alt == Sentinel('Nada'):
|
235
|
+
return Nada()
|
236
|
+
else:
|
237
|
+
return alt
|
238
|
+
|
dtools/fp/state.py
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
# Copyright 2024-2025 Geoffrey R. Scheller
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
"""### Module fp.state - state monad
|
16
|
+
|
17
|
+
Handling state functionally.
|
18
|
+
|
19
|
+
#### Pure FP State handling type:
|
20
|
+
|
21
|
+
* class **State**: A pure FP immutable implementation for the State Monad
|
22
|
+
* translated to Python from the book "Functional Programming in Scala"
|
23
|
+
* authors Chiusana & Bjarnason
|
24
|
+
* using `bind` instead of `flatmap`
|
25
|
+
* I feel `flatmap` is misleading for non-container-like monads
|
26
|
+
* flatmap name too long
|
27
|
+
* without do-notation code tends to march to the right
|
28
|
+
* `bind` for state monad is part of the user API
|
29
|
+
* shorter to type
|
30
|
+
* less of just an implementation detail
|
31
|
+
|
32
|
+
"""
|
33
|
+
from __future__ import annotations
|
34
|
+
|
35
|
+
__all__ = [ 'State' ]
|
36
|
+
|
37
|
+
from collections.abc import Callable
|
38
|
+
from typing import Any, Never
|
39
|
+
|
40
|
+
class State[S, A]():
|
41
|
+
"""Data structure generating values while propagating changes of state.
|
42
|
+
|
43
|
+
* class `State` represents neither a state nor (value, state) pair
|
44
|
+
* it wraps a transformation old_state -> (value, new_state)
|
45
|
+
* the `run` method is this wrapped transformation
|
46
|
+
* `bind` is just state propagating function composition
|
47
|
+
* `bind` is sometimes called "flatmap"
|
48
|
+
|
49
|
+
"""
|
50
|
+
__slots__ = 'run'
|
51
|
+
|
52
|
+
def __init__(self, run: Callable[[S], tuple[A, S]]) -> None:
|
53
|
+
self.run = run
|
54
|
+
|
55
|
+
def bind[B](self, g: Callable[[A], State[S, B]]) -> State[S, B]:
|
56
|
+
def compose(s: S) -> tuple[B, S]:
|
57
|
+
a, s1 = self.run(s)
|
58
|
+
return g(a).run(s1)
|
59
|
+
return State(lambda s: compose(s))
|
60
|
+
|
61
|
+
def map[B](self, f: Callable[[A], B]) -> State[S, B]:
|
62
|
+
return self.bind(lambda a: State.unit(f(a)))
|
63
|
+
|
64
|
+
def map2[B, C](self, sb: State[S, B], f: Callable[[A, B], C]) -> State[S, C]:
|
65
|
+
return self.bind(lambda a: sb.map(lambda b: f(a, b)))
|
66
|
+
|
67
|
+
def both[B](self, rb: State[S, B]) -> State[S, tuple[A, B]]:
|
68
|
+
return self.map2(rb, lambda a, b: (a, b))
|
69
|
+
|
70
|
+
@staticmethod
|
71
|
+
def unit[S1, B](b: B) -> State[S1, B]:
|
72
|
+
"""Create a State action from a value."""
|
73
|
+
return State(lambda s: (b, s))
|
74
|
+
|
75
|
+
@staticmethod
|
76
|
+
def getState[S1]() -> State[S1, S1]:
|
77
|
+
"""Set run action to return the current state
|
78
|
+
|
79
|
+
* the current state is propagated unchanged
|
80
|
+
* current value now set to current state
|
81
|
+
|
82
|
+
"""
|
83
|
+
return State[S1, S1](lambda s: (s, s))
|
84
|
+
|
85
|
+
@staticmethod
|
86
|
+
def setState[S1](s: S1) -> State[S1, tuple[()]]:
|
87
|
+
"""Manually set a state.
|
88
|
+
|
89
|
+
* the run action
|
90
|
+
* ignores previous state and swaps in a new state
|
91
|
+
* assigns a canonically meaningless value to current value
|
92
|
+
|
93
|
+
"""
|
94
|
+
return State(lambda _: ((), s))
|
95
|
+
|
96
|
+
@staticmethod
|
97
|
+
def modifyState[S1](f: Callable[[S1], S1]) -> State[S1, tuple[()]]:
|
98
|
+
return State.getState().bind(lambda a: State.setState(f(a))) #type: ignore
|
99
|
+
|
100
|
+
# @staticmethod
|
101
|
+
# def sequence[S1, A1](sas: list[State[S1, A1]])
|
102
|
+
# """Combine a list of state actions into a state action of a list.
|
103
|
+
|
104
|
+
# * all state actions must be of the same type
|
105
|
+
|
106
|
+
# """
|
107
|
+
|
@@ -0,0 +1,176 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
@@ -0,0 +1,58 @@
|
|
1
|
+
Metadata-Version: 2.3
|
2
|
+
Name: dtools.fp
|
3
|
+
Version: 1.3.0
|
4
|
+
Summary: ### Package dtools.fp - Pythonic Functional Programming
|
5
|
+
Keywords: functional,functional programming,fp,monad,iterators,maybe,either,lazy,non-strict
|
6
|
+
Author-email: "Geoffrey R. Scheller" <geoffrey@scheller.com>
|
7
|
+
Requires-Python: >=3.12
|
8
|
+
Description-Content-Type: text/markdown
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
10
|
+
Classifier: Framework :: Pytest
|
11
|
+
Classifier: Intended Audience :: Developers
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
13
|
+
Classifier: Operating System :: OS Independent
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
15
|
+
Classifier: Typing :: Typed
|
16
|
+
Requires-Dist: pytest >=8.3 ; extra == "test"
|
17
|
+
Requires-Dist: dtools.circular-array >=3.9.0, < 3.10 ; extra == "test"
|
18
|
+
Requires-Dist: dtools.datastructures >=0.25.0, < 0.26 ; extra == "test"
|
19
|
+
Project-URL: Changelog, https://github.com/grscheller/dtools-fp/blob/main/CHANGELOG.md
|
20
|
+
Project-URL: Documentation, https://grscheller.github.io/dtools-docs/fp
|
21
|
+
Project-URL: Source, https://github.com/grscheller/dtools-fp
|
22
|
+
Provides-Extra: test
|
23
|
+
|
24
|
+
# Python Functional Programming (FP)
|
25
|
+
|
26
|
+
Functional programming tools which endeavor to be Pythonic.
|
27
|
+
|
28
|
+
* **Repositories**
|
29
|
+
* [dtools.fp][1] project on *PyPI*
|
30
|
+
* [Source code][2] on *GitHub*
|
31
|
+
* Detailed documentation for dtools.fp
|
32
|
+
* [Detailed API documentation][3] on *GH-Pages*
|
33
|
+
|
34
|
+
### Modules
|
35
|
+
|
36
|
+
* grscheller.fp.iterables
|
37
|
+
* iteration tools implemented in Python
|
38
|
+
* grscheller.fp.nothingness
|
39
|
+
* singleton classes representing either a
|
40
|
+
* missing value
|
41
|
+
* sentinel value
|
42
|
+
* failed calculation
|
43
|
+
* grscheller.fp.err\_handling
|
44
|
+
* monadic tools for handling missing values & unexpected events
|
45
|
+
|
46
|
+
### Benefits of FP
|
47
|
+
|
48
|
+
* improved composability
|
49
|
+
* avoid exception driven code paths
|
50
|
+
* data sharing becomes trivial due to immutability
|
51
|
+
|
52
|
+
---
|
53
|
+
|
54
|
+
[1]: https://pypi.org/project/dtools.fp/
|
55
|
+
[2]: https://github.com/grscheller/dtools-fp/
|
56
|
+
[3]: https://grscheller.github.io/dtools-docs/fp/
|
57
|
+
|
58
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
dtools/fp/__init__.py,sha256=OGd-av_1MLBt40mkyoGzxgIYCb7bxqTdqfRAqiUzV9g,1299
|
2
|
+
dtools/fp/err_handling.py,sha256=PdqWTh9coHKzgK7jJ07OlXQfaDa0z9yu_-gJaZBO4mY,13660
|
3
|
+
dtools/fp/function.py,sha256=TMz8tTy77C7KRVZv12ouumQdJK0dhYUnTYqqgb-hQxw,2455
|
4
|
+
dtools/fp/iterables.py,sha256=gmqjUTrIylyEPzRhI3hOYaMvg5uISIEWHGaCedca38Q,13193
|
5
|
+
dtools/fp/lazy.py,sha256=_DIU3qmwOwCU9m9RfJ4SbLeDSa4XRj2_FbW-MsT-o7E,4358
|
6
|
+
dtools/fp/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
|
+
dtools/fp/singletons.py,sha256=bVp42bME7ym2S9kkC5140rJ5fOqBmTJIVYjQ1cPfsYA,8105
|
8
|
+
dtools/fp/state.py,sha256=E88AJ5ixtjYAYRzzMwU5bZhAwH_l7zmdKPcDOEf9ib4,3570
|
9
|
+
dtools_fp-1.3.0.dist-info/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
|
10
|
+
dtools_fp-1.3.0.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
|
11
|
+
dtools_fp-1.3.0.dist-info/METADATA,sha256=Cgf9symLBGZ1rfGKKUzSlrYSqDRaPi0B-b8HOEfHjlQ,1958
|
12
|
+
dtools_fp-1.3.0.dist-info/RECORD,,
|