Commit d53d571c authored by Bas Lijnse's avatar Bas Lijnse

Merge branch 'transform-error' into 'master'

Modify transform so it can create an exception

See merge request !176
parents f1adf579 f6040c46
Pipeline #13510 passed with stage
in 9 minutes and 16 seconds
......@@ -4,6 +4,7 @@ definition module iTasks.WF.Combinators.Core
*/
import iTasks.WF.Definition
from iTasks.SDS.Definition import :: SDS
from Data.Error import :: MaybeError(Ok)
from Data.Maybe import :: Maybe
//* Next task actions
......@@ -78,16 +79,29 @@ ActionClose :== Action "Close"
derive class iTask AttachException
instance toString AttachException
/**
* Adds a result transformation function to a task.
* The resulting task is still considered a single step in the workflow.
*
* @param Function: The transformation function.
* @param Task: The task to which the transformation function is added
*
* @return The transformed task
*/
transformError :: ((TaskValue a) -> MaybeError TaskException (TaskValue b)) !(Task a) -> Task b
/**
* Adds a result transformation function to a task.
* The resulting task is still considered a single step in the workflow.
*
* @param Function: The transformation function. It works on maybe's to also map over instable tasks.
* @param Function: The transformation function.
* @param Task: The task to which the transformation function is added
*
* @return The transformed task
* @type ((TaskValue a) -> TaskValue b) !(Task a) -> Task b
*/
transform :: ((TaskValue a) -> TaskValue b) !(Task a) -> Task b
transform f :== transformError (\tv->Ok (f tv))
/**
* The generic sequential combinator.
......
......@@ -72,12 +72,13 @@ where
derive class iTask AttachException
transform :: ((TaskValue a) -> TaskValue b) !(Task a) -> Task b
transform f (Task evala) = Task eval
transformError :: ((TaskValue a) -> MaybeError TaskException (TaskValue b)) !(Task a) -> Task b
transformError f (Task evala) = Task eval
where
eval event evalOpts tree iworld = case evala event evalOpts tree iworld of
//TODO: guarantee stability
(ValueResult val lastEvent rep tree,iworld) = (ValueResult (f val) lastEvent rep tree, iworld)
(ValueResult val lastEvent rep tree,iworld) = case f val of
Error e = (ExceptionResult e, iworld)
Ok v = (ValueResult v lastEvent rep tree, iworld)
(ExceptionResult e, iworld) = (ExceptionResult e, iworld)
(DestroyedResult, iworld) = (DestroyedResult, iworld)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment