PrimeStructs is a library for python containing many cool functions and classes for easier and prettier code or just to have fun with.
This repository has been archived on 2025-12-03. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
Find a file
2020-06-23 16:02:41 +02:00
PrimeStructs Initial commit 2020-06-23 15:52:37 +02:00
.gitignore Initial commit 2020-06-23 15:52:37 +02:00
README.md Added README.md 2020-06-23 16:02:41 +02:00
setup.py Initial commit 2020-06-23 15:52:37 +02:00

Installation

pip3 install --upgrade "git+https://git.leon.wtf/leon/primestructs"

Example code (both switch case emulators)

from PrimeStructs.switchcase import Switch, switch

fruit = "apple"

### METHOD 1 ###
for case in Switch(fruit):
    if case("apple"):
        print("That's an apple")
        break   # supports fallthrough
    if case("peach", "Peach")   # supports multiple cases in one case call
        print("That's a peach")
        break
    if case():  # default case
        print("Don't know what it is")

### METHOD 2 ###
switch(fruit)(
    ("apple", "print(\"That's an apple\")"),                    # case is defined in first tuple field
    ("peach", "print(\"That's a peach\")", "print('cool!')"),   # expressions are defined in the following fields
    default="print(\"That's a peach\")"
)