JeffersonLab / jlab_datascience_core

2 stars 1 forks source link

function-to-module builder #44

Open sgoldenCS opened 1 month ago

sgoldenCS commented 1 month ago

A thought about making implementation easier, specifically for very simple transformations/functions.

The general idea is to make a decorator or class that can take in a function and "modularize" it without worrying about boilerplate code for things like configurations, saving/loading.

I'm not exactly sure how this would work, but if you have a simple transformation or plot, you could create a module with something like

@modularize
def my_transform(data, alpha=0, beta=1.2):
    # Write code here
    return transformed_data

In this example, the configuration would simply be the kwargs passed to my_transform and the run() or transform() function in the module class would simply call my_transform(). I'm not sure if this can really be done in a decorator, or if it needs to be a special class that takes a function for the __init__()...

This might not be a good idea, just wanted to document it somewhere...