Skip to content

Pipelining

Jordan Welsman edited this page Feb 16, 2023 · 4 revisions

This sub-module contains classes designed to allow users to construct a pipeline from user-defined functions.

DataPipeline()

This class allows the user to construct a multiple-data pipeline from user-defined functions.

Usage

from jutl.pipelining import DataPipeline

# Example user-defined functions
def add_ten(num):
    return num + 10

def subtract_five(num):
    return num - 5

pipeline = DataPipeline(add_ten, subtract_five)

result = pipeline(20, 30, 50, 80, 120) # result = [25, 35, 55, 85, 125]

Arguments

Argument Data type Default Description
*functions objects n Functions to construct the pipeline from
name string None Optional identifier to be given to pipeline

*functions

This is a series of function objects passed directly to the pipeline class upon object instantiation. Passing multiple of the same object is permitted.

Note You must ensure the passed functions' returns are compatible with each others' arguments.

Accepted arguments

Argument Required Accepted values
*functions Any number of function objects
name Any string

Returns

When called with parentheses and data passed, the pipeline object will compute the result of the data after passing through all functional elements of the pipeline. If called without parentheses, the pipeline will output its representation as its name with the number of functions in its pipeline.

Side-effects

This object computes and returns the result of the inputted data series having passed through the functional components, thus its only side-effect is what it outputs if it is called with no parentheses.

InstructionPipeline()

This class allows the user to construct a single-data pipeline from user-defined functions.

Usage

from jutl.pipelining import InstructionPipeline

# Example user-defined functions
def add_ten(num):
    return num + 10

def subtract_five(num):
    return num - 5

pipeline = InstructionPipeline(add_ten, subtract_five)

result = pipeline(20) # result = 25

Arguments

Argument Data type Default Description
*functions objects n Functions to construct the pipeline from
name string None Optional identifier to be given to pipeline

*functions

This is a series of function objects passed directly to the pipeline class upon object instantiation. Passing multiple of the same object is permitted.

Note You must ensure the passed functions' returns are compatible with each others' arguments.

Accepted arguments

Argument Required Accepted values
*functions Any number of function objects
name Any string

Returns

When called with parentheses and data passed, the pipeline object will compute the result of the data after passing through all functional elements of the pipeline. If called without parentheses, the pipeline will output its representation as its name with the number of functions in its pipeline.

Side-effects

This object computes and returns the result of the input data having passed through the functional components, thus its only side-effect is what it outputs if it is called with no parentheses.