Skip to main content

match_func

Pattern matching as a function.

from match_func import match

# Use ranges!
age = 20
match(age,
      {range(0, 3):   'Toddler',
       range(3, 14):  'Child',
       range(14, 18): 'Teen',
       range(18, 65): 'Adult'},
      default =       'Elder')
>> 'Adult'

# Use tuples!
name = 'Clara'
match(name,
      {('Laura', 'John', 'Luke'): 'First class',
       ('Clara', 'Nathan'):       'Business',
       ('Jason', 'Mary'):         'Economy'},
      default =                   'Non customer')
>> 'Business'

# Use conditions!
value = 5
match(value,
      {value < 10:        'Small',
       10 <= value <= 20: 'Medium',
       value > 20:        'Large'})
>> 'Small'

# Use types!
something = 'Hello'
match(something,
      {int:     'Its an integer',
       str:     'Its a string'},
      default = 'Its something else')
>> 'Its a string'

# Mix and match!
earnings = 10_000
match(earnings,
      {str:              'Invalid type: str',
       range(0, 5_000):  'Too low',
       5_000:            'Exactly 5k',
       earnings > 5_000: 'Over the top!'},
      default =         f'Invalid value: {earnings}')
>> 'Over the top!'

Metadata

Release files for match-func 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for match-func 1.0.0
File Size Uploaded Provenance Actions
match_func-1.0.0.tar.gz 9.1 kB Without provenance Details for match_func-1.0.0.tar.gz

Release files / match_func-1.0.0.tar.gz

Download URL match_func-1.0.0.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0ef85e25ce8ed9bc7fe182df9a9702529eb28a0104f528623fcb5fc96b91fd07
BLAKE2b-256 checksum
How to use checksums
10b5266b608c4769b63440954e7bcf6004ca215dbc5fffae4e19fc7c3b4e4382
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Security for match-func 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page