Skip to main content

Easy implementation of Python 3.10's structural pattern matching.

Project description

Match-Case Library

a.k.a. matchcaselib


Welcome to matchcaselib, an easy implementation of Python 3.10's new feature of structural pattern matching.

This project is currently in a BETA STAGE.

Installation

You can install this package by running the following command in your terminal:

pip install matchcaselib

or update it with the command

pip install --upgrade matchcaselib


Usage

from matchcaselib import match

a = input("Enter in a number: ")
a = int(a)
b = input("Enter in another number: ")
b = int(b)

with match(a, b) as m:
  if(m.case(1, 1)):
    print("All ones.")
  if(m.case(1, 2)):
    print("One and two.")
  if(m.case(a, 1)):
    print("The value of A can be anything!  A was {} and b was 1.".format(a))
  if(m.default):
    print("I don't know what you mean...")

What you can do:

  • Compare as many sets of variables as you would like (the amount you provide with the initialization of the class must be consistent with the amount you use for the case method.)
  • Make a "default" response - Run a block if default is true (no matches were found)

Work in Progress features:

  • Multi-pattern matching (test for multiple patterns)
  • Break function - leave the current match

What not to do:

  • Use different amounts of variables for the class initialization and the use of the case method
  • I don't know, there aren't many bugs right now LOL

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

matchcaselib-0.0.1b0.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

matchcaselib-0.0.1b0-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file matchcaselib-0.0.1b0.tar.gz.

File metadata

  • Download URL: matchcaselib-0.0.1b0.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/3.10.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.12

File hashes

Hashes for matchcaselib-0.0.1b0.tar.gz
Algorithm Hash digest
SHA256 46f62ae1a58bcb6c0a5a5087e823136e6f67a3a46e5c3acafb20dc0c13517b04
MD5 f5fa2933265a034872a059ec0a2bc002
BLAKE2b-256 8f269ab8bd047338481a9564ab3586a2db338e2020b811ccd72de7c4bf7985c8

See more details on using hashes here.

File details

Details for the file matchcaselib-0.0.1b0-py3-none-any.whl.

File metadata

  • Download URL: matchcaselib-0.0.1b0-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/3.10.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.12

File hashes

Hashes for matchcaselib-0.0.1b0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b37016f1f1860686151ade474a7df38f32a10095ec6a06956c65e42aeaf4153
MD5 2def06c43dda749dd568effd6450b807
BLAKE2b-256 5bd55f12db8f2c895b5783960b5da74ed8e02605d29474222c2f5d9d5235c303

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