PrimeStructs is a library for python containing many cool functions and classes for easier and prettier code or just to have fun with.
| PrimeStructs | ||
| .gitignore | ||
| README.md | ||
| setup.py | ||
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\")"
)