Skip to main content

Add your description here

Project description

matchtoolz

utilities for structural pattern matching

re.match

The Regex helper provides a convenient way to use regular expressions in Python's structural pattern matching. It allows you to match strings against regex patterns within match statements. There is als RegexBytes for bytes based regular expressions.

Example:

match Regex("hello"):
    case r"world":
        assert False
    case r"^h.?l+o$":
        assert True
    case _:
        assert False

__contains__

The IsIn and Contains helpers assist in membership tests.

IsIn is the "match" side helper

The IsIn helper is probably the easier to use for most use cases, but it may be less performat than Contains. IsIn checks for membership in the collection without modification, so you may be looking at O(1) for lookups.

lotr = Characters(hobbits, dwarves)

match IsIn("Frodo"):
    case lotr.hobbits:
        assert True
    case lotr.dwarves:
        assert False
    case _:
        assert False

Contains is the "case" side helper

Contains attempts to conver the collection to a frozenset, so for re-used lookups this will be more performant, but you have to build the set, so it isn't worth it unless the collection will be matched multiple times.

lotr = Characters(Contains(hobbits), Contains(dwarves))

match "Frodo":
    case lotr.hobbits:
        assert True
    case lotr.dwarves:
        assert False
    case _:
        assert False

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

matchtoolz-0.1.0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

matchtoolz-0.1.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: matchtoolz-0.1.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.24

File hashes

Hashes for matchtoolz-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e04dd006018aadab530c86bc9a170c18b4f32b30f032ab09f31ae468831b8fff
MD5 64b9d41b5c439cb2aa67d586b4a6c451
BLAKE2b-256 3ca3e07dd77e169f1c7ccc75ffe6f8dbe5ecabca7cc97c82caf25643e1032aae

See more details on using hashes here.

File details

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

File metadata

  • Download URL: matchtoolz-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.24

File hashes

Hashes for matchtoolz-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 64e566d0b77ef07ff6d3307a53ce2c84adb2f12b6f5e0915ab56a3eb59167081
MD5 c74441f19c77d08fa95cd30626f66218
BLAKE2b-256 c1e2c3788973f5732b1ad5e12eede8f2677648feed80d0b149fdee680766a754

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