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.1.tar.gz (45.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: serox-0.1.1.tar.gz
  • Upload date:
  • Size: 45.9 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.1.tar.gz
Algorithm Hash digest
SHA256 e2d6d126666b284d373a5ceb3864cf8e194fe5261d924d048b192bae13927e13
MD5 3dc4ae38cf6a0836195555f904230fd7
BLAKE2b-256 cad9926a50fe1735f181d912ca04c5753f064f5119232800a19328a26d38b2af

See more details on using hashes here.

File details

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

File metadata

  • Download URL: serox-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 60b8d427b02f929cdb4fe4c10dc931d45045627551b477018d8bdb12ff73b4d0
MD5 b5cd7d608ccf679814e7c31360dfd1f8
BLAKE2b-256 2bf0b23c6f0abc2ec6b686e21f5f4f98b57f76e0c570b0b3465eb31127c92891

See more details on using hashes here.

Supported by

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