Skip to content

Achxy/operator-converter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A source converter made for fun based off this question on StackOverflow

Examples

Quick examples to demonstrate working of this project :

Before conversion:

def fib(n):
    if n <= 1:
        return n
    return fib(n - 1) + fib(n - 2)

print(fib(5))

After conversion:

from operator import sub, add, le

def fib(n):
    if le(n, 1):
        return n
    return add(fib(sub(n, 1)), fib(sub(n, 2)))

print(fib(5))

---

Before conversion:

def foo(x, y, z):
    z += 1
    y = x >> y
    x @= y
    x, y = y, x
    return (x + y ^ z) or y // x

After conversion:

from operator import xor, imatmul, iadd, rshift, add, floordiv

def foo(x, y, z):
    z = iadd(z, 1)
    y = rshift(x, y)
    x = imatmul(x, y)
    (x, y) = (y, x)
    return xor(add(x, y), z) or floordiv(y, x)

Features

The following conversions are implemented :

  1. Unary Operations
  2. Binary Operations
  3. Comparsion Operators
  4. Subscript Operations [❌TODO]
  5. Augmented Assignmented Operations

Releases

No releases published

Packages

No packages published

Languages