Ordering enumeration and protocols.
Project description
orderings
Ordering enumeration and protocols.
Installing
Python 3.8 or above is required.
pip
Installing the library with pip
is quite simple:
$ pip install orderings
Alternatively, the library can be installed from source:
$ git clone https://github.com/nekitdev/orderings.git
$ cd orderings
$ python -m pip install .
poetry
You can add orderings
as a dependency with the following command:
$ poetry add orderings
Or by directly specifying it in the configuration like so:
[tool.poetry.dependencies]
orderings = "^1.3.0"
Alternatively, you can add it directly from the source:
[tool.poetry.dependencies.orderings]
git = "https://github.com/nekitdev/orderings.git"
Motivation
Sometimes it's simpler to handle ordering in one method, for example when comparing iterators;
then it's trivial to implement the regular ordering methods using the compare
method.
Examples
Core
The core of orderings
is the Ordering
enumeration
and the Compare
protocol:
from typing import Generic, TypeVar
from attrs import frozen
from orderings import Compare, Ordering, StrictOrdered
from typing_extensions import Self
T = TypeVar("T", bound=StrictOrdered)
@frozen()
class Wrap(Compare, Generic[T]):
value: T
def compare(self, other: Self) -> Ordering:
self_value = self.value
other_value = other.value
if self_value < other_value:
return Ordering.LESS
if self_value > other_value:
return Ordering.GREATER
return Ordering.EQUAL
Compare
implements all ordering operations
(==
, !=
, <
, >
, <=
, >=
) using the compare
method.
Documentation
You can find the documentation here.
Support
If you need support with the library, you can send an email or refer to the official Discord server.
Changelog
You can find the changelog here.
Security Policy
You can find the Security Policy of orderings
here.
Contributing
If you are interested in contributing to orderings
, make sure to take a look at the
Contributing Guide, as well as the Code of Conduct.
License
orderings
is licensed under the MIT License terms. See License for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file orderings-1.3.0.tar.gz
.
File metadata
- Download URL: orderings-1.3.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/6.2.0-1019-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72b165fd1ea81db570a2a9e907e3eb36f8a7f8834410292cfa17b68b63cd9acd |
|
MD5 | fb36241c7bb81849909b9c0019eeb7d1 |
|
BLAKE2b-256 | d2226d7ee092616e5158526ce15cef97bdd10b4484def4a8cdb0616294174856 |
File details
Details for the file orderings-1.3.0-py3-none-any.whl
.
File metadata
- Download URL: orderings-1.3.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/6.2.0-1019-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 720f4f40f0cdb6d30b9abd7f6db0003798806437513c3a49ce2edf9b14fb832b |
|
MD5 | a5d05d725dd21eb517875c8bfd3863e1 |
|
BLAKE2b-256 | b1d2289758d7f5d9b5e7b11d475df520862ea2104ca853fd33030b3e822f6de7 |