Skip to main content

Metafunctions with less repetition

Project description

Warning: Package under development... tons of side effects. Don't rely on it yet!

Metafunctions is an excellent package that allows you to compose functions into metafunctions using a pipe.

Instead of writing:

result = step3(step2(step1(data)))

#or
result_1 = step1(data)
result_2 = step2(result_1)
result_3 = step3(result_2)

You instead write:

pipeline = step1 | step2 | step3
result = pipeline(data)

Here's another example:

# load, parse, clean, validate, and format are functions
preprocess = load | parse | clean | validate | format

# preprocess is now a MetaFunction, and can be reused
clean_data1 = preprocess('path/to/data/file')
clean_data2 = preprocess('path/to/different/file')

# Preprocess can be included in larger pipelines
pipeline = preprocess | step1 | step2 | step3

"Then why are you making a new package?"

The problem is in the repetition:

You have to do this:

from metafunctions import node

@node
def get_name(prompt):
    return input(prompt)

@node
def say_hello(name):
    return 'Hello {}!'.format(name)

And then do this:

greet = get_name | say_hello

Why use the word "@node" over every function? what if I have a big class, or if I'm importing functions from other modules?

Do I have to go and decorate every single function in that module to use this syntax?

No!!111!!1

Unacceptable!

we're developers! We COMPRESS cycles of work, not EXPAND them...

With superfunctions, all you have to do is:

from superfunctions import decorate_all_modules
decorate_all_modules()

Make sure this is at the end of all your imports.

And you're done! That's it!

Wanna use functions from other modules? Piece of cake.

import numpy as np
from superfunctions import decorate_all_modules
decorate_all_modules()

g = np.random.rand | np.squeeze | np.sum | print
g(2,3)

Wanna use functions from files in the same directory/local modules?

greetsomeone.py

def get_name(name):
    return name


def say_hello(name):
    return 'Hello {}!'.format(name)

And importing from your main file:

from greetsomeone import *
from superfunctions import decorate_all_modules
decorate_all_modules()

greet = get_name | say_hello | print

BUT it doesn't yet work with all functions.

This is still alpha, and will break a lot and also give you errors you cannot comprehend or even debug!

What does it do?

It does something dangerous...

It decorates ALL functions in all imported modules with "@node" from metafunctions, and decorates all methods in all classes in all imported modules, and decorates all functions and methods in your current file.

Why is this dangerous?

Because this code hasn't been tested yet, we really have no idea of the side effects.

Why?

Because I've yet to test it!

Want to help me enhance it, test it, maintain it?

Contact me at youssef.avx@gmail.com

Like the package? Make me less broke by donating to

My paypal: youssef.avx@gmail.com

Bitcoin: 15PPdm9SBQAZAwRq6n5q5GLRb7jEZLqsyE

Ethereum: 0xe05e9887bDEa2793A062C2b29908dcd2BE080afA

Psst... if I had it my way I'd want it to get even closer to english like this:

find_first_word_in_titles = get_html parse_html get_titles get_first_word   

where we remove the pipe!

But I don't know how to implement this... oh well.

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

superfunctions-0.1.3.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

superfunctions-0.1.3-py2.py3-none-any.whl (6.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file superfunctions-0.1.3.tar.gz.

File metadata

  • Download URL: superfunctions-0.1.3.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.2

File hashes

Hashes for superfunctions-0.1.3.tar.gz
Algorithm Hash digest
SHA256 42a979af043ad640cc42bf47fac6d6f0bc98bacde4189942731e223fd12b732f
MD5 5623890f705d145cb830b2d396fff2d7
BLAKE2b-256 2c404feb1570468f0196d376ef5d6148987d17ffb938d01505c374342629c2d9

See more details on using hashes here.

File details

Details for the file superfunctions-0.1.3-py2.py3-none-any.whl.

File metadata

  • Download URL: superfunctions-0.1.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.2

File hashes

Hashes for superfunctions-0.1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a092c9da8c26bd44a6f5797a181ab67c60ca2d571547c0f62549e196ec14c867
MD5 5d9f9f8ab59498124a036a7264d1d4c8
BLAKE2b-256 4317d6b76f508d0e4f95d1d6a87a697a3906cc7441aa5394d72491d0a73a3baa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page