Skip to main content

Ordering enumeration and protocols.

Project description

orderings

License Version Downloads Discord

Documentation Check Test Coverage

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.1"

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

orderings-1.3.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

orderings-1.3.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file orderings-1.3.1.tar.gz.

File metadata

  • Download URL: orderings-1.3.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.0 CPython/3.10.12 Linux/6.2.0-1019-azure

File hashes

Hashes for orderings-1.3.1.tar.gz
Algorithm Hash digest
SHA256 fdf2b2d7d450a99a31c95ae08731a7c0bb5713212bd37a9086c36f8cfb1bb289
MD5 c7ffbb35ccbc9cd62134e09a2c6d4048
BLAKE2b-256 73b14c912b843b4bb5e94cc8aa655356b838f49e5fa02b8f650d0014f6cf5e54

See more details on using hashes here.

File details

Details for the file orderings-1.3.1-py3-none-any.whl.

File metadata

  • Download URL: orderings-1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.0 CPython/3.10.12 Linux/6.2.0-1019-azure

File hashes

Hashes for orderings-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fc110d22c18b6c83e090b61cad7afbfdb6fe15502a76cba587cdb97b08f009eb
MD5 03aaf93fc94d0c850ab5b032a729396f
BLAKE2b-256 5dda00e7e058fd9a2faabb21b88e78a687532eddee817968f652a2ffe7c15a16

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page