module test import StdMisc import iTasks import Data.Either import StdEnv import Data.Func import Data.Functor Start w = flip doTasks w $ updateInformation () [] 42 >>* [OnAction (Action "Continue") (always (return 43))] (>>*) infixl 1// :: !(Task a) ![TaskCont a (Task b)] -> Task b | iTask a & iTask b (>>*) task steps :== step task (const Nothing) steps step :: !(Task a) ((Maybe a) -> Maybe b) [TaskCont a (Task b)] -> Task b | iTask a & iTask b step lhs lhsValFun conts = parallel [(Embedded, \stl->lhs @? \v->case v of NoValue = Value (Left Nothing) False (Value v s) = Value (Left (Just v)) s )] (map stepCont conts) @? stepVal lhsValFun where stepVal :: ((Maybe a) -> Maybe b) (TaskValue [(Int, TaskValue (Either (Maybe a) b))]) -> TaskValue b stepVal tfun NoValue = NoValue stepVal tfun (Value [(_, x):_] _) = case x of //Not yet stepped: Value (Left l) s = case tfun l of Nothing = NoValue Just v = Value v False //Stepped but no value NoValue = NoValue Value (Right r) s = Value r s stepVal _ _ = abort "cannot happen" stepCont (OnValue f) = OnValue (transform f) stepCont (OnAction a f) = OnAction a (transform f) stepCont (OnException f) = OnException \e->add (f e) stepCont (OnAllExceptions f) = OnAllExceptions \e->add (f e) transform f v # v = case v of Value [(_, v)] _ = case v of NoValue = NoValue Value (Left (Just v)) s = Value v s Value _ _ = NoValue NoValue = NoValue = add <$> f v add t = (Embedded, \stl-> get (sdsFocus {onlyIndex=Nothing,onlyTaskId=Nothing,onlySelf=False,includeValue=False,includeProgress=False,includeAttributes=False} stl) >>- \(_, pts)->case pts of [tli:_] = removeTask tli.TaskListItem.taskId stl >-| t @ Right _ = abort "shouldn't happen" )