Skip to content

Commit

Permalink
Added graphcat.passthrough(). Closes #6.
Browse files Browse the repository at this point in the history
  • Loading branch information
tshead committed Oct 26, 2020
1 parent dddfca1 commit c1f4081
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions features/graph.feature
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,12 @@ Feature: Graph
And testing if the graph contains task "A" should return True
And testing if the graph contains task "C" should return False


Scenario: Passthrough
Given an empty graph
When adding tasks ["A", "B", "C"] with functions [graphcat.constant(42), graphcat.constant(10), graphcat.passthrough("lhs")]
And adding links [("A", ("C", "lhs")), ("B", ("C", "rhs"))]
And updating tasks ["C"]
Then the task ["A", "B", "C"] outputs should be [42, 10, 42]


22 changes: 22 additions & 0 deletions graphcat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,28 @@ def null(name, inputs):
pass


def passthrough(input, index=0):
"""Factory for task functions that pass-through incoming data.
Callers can use this function to temporarily bypass tasks in the graph.
Parameters
----------
input: hashable object, required
The named input that will pass-through to the task output.
index: integer, required
Index of the named inputs that will pass-through to the task output.
Returns
-------
fn: function
Task function that will pass input `input` index `index` to its output.
"""
def implementation(name, inputs):
return inputs[input][index]
return implementation


def raise_exception(exception):
"""Factory for task functions that raise an exception when executed.
Expand Down

0 comments on commit c1f4081

Please sign in to comment.