Skip to main content

Serpentine Oxidation: Rusty abstractions for Python.

Project description

Serox

Rusty abstractions for Python.

Serox defines a emulates a suite of commonly-used Rust abstractions in a manner that is near-fully static-type-checker compliant, the exceptions being cases involving higher-kinded types (HKTs; e.g. Iterator.collect) as these are not currently supported by Python's type system. Namely:

  1. Iterator combinators that allow for the seamless chaining of operations over data with rayon-inspired functionality for effortless parallelism.

  2. A Result pseudo-enum comprising Some and Null pseudo-variants. We say 'pseudo' as the Python analogue to Rust's tagged union is the union (A | B) type; since this type is not a data structure, we cannot implement methods on it directly and instead have to resort to some legerdemain.

  3. An Option pseudo-enum. The T | None pattern is ubiquitous in Python yet, frustratingly, is not treated as a first-class citizen within the language; Option is a drop-in replacement that redresses this.

  4. The qmark decorator emulates the '?' (error/null short-circuiting) operator, allowing for propagation of error and null values without interrupting the control flow. Without this, one has to resort to awkward pattern-matching to perform common operations such as unwrap_or (setting Null to a default value) or map (applying a function to the contained value if Some).

from serox import Option, qmark

@qmark
def some_function(foo: Option[str]) -> Option[str]:
    foo_bar: str = value.map(lambda x: x + "bar").q
    return Some(foo_bar + "_baz")

Acknowledgements

Credit to result and rustshed for laying the groundwork for the Result and qmark implementations.

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

serox-0.1.0.tar.gz (45.3 kB view details)

Uploaded Source

Built Distribution

serox-0.1.0-py3-none-any.whl (26.5 kB view details)

Uploaded Python 3

File details

Details for the file serox-0.1.0.tar.gz.

File metadata

  • Download URL: serox-0.1.0.tar.gz
  • Upload date:
  • Size: 45.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for serox-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d572eb688464e7e9a5c7c7f56168be5692b1de44d7e563f703569666d825e8ac
MD5 efcf9e75be37ee3cad334f6edfd8b8e7
BLAKE2b-256 442993b2c75149fb18acaa260c76ec423e639605e1a358450eee517ba27c0315

See more details on using hashes here.

File details

Details for the file serox-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: serox-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 26.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for serox-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9d350e7e0c009dc945a824c365da8215e0c0aabb2aea007e44693f4a2d38d65
MD5 f75c7b09e64455db1c08bf2731b60aba
BLAKE2b-256 647e351baa4191d4ac6e969d4c4db3b9ea614e8ab68008736c73345251b227b2

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