-- | A given step might not have been reached yet. It it has been reached,
-- either it has been skipped at a certain time, or started at a certain time.
-- If if has been started, maybe it has already finished, too.
--
-- This function can be used in combination with 'toForest' and
-- 'Data.Tree.drawForest' to render the state of each step for a 'Tick'.
completedness :: Tick s t ->  Tick (Maybe (Either t (t,Maybe t)),s) t
completedness (Tick (Context {completed,current,pending}:|contexts) progress) = 
    let startingTime = extract completed
        (progress',time') = progressCompletedness startingTime progress
    in  Tick (Context (adapt (instants completed))
                      (time',current)
                      (fmap (fmap (\s -> (Nothing,s))) pending)
              :| map (contextCompletedness (\t -> Right (t,Nothing))) contexts)  
             progress'
completedness :: Tick s t ->  Tick (Maybe (Either t (t,Maybe t)),s) t
completedness (Tick (Context {completed,current,pending}:|contexts) progress) = 
    let startingTime = extract completed
        (progress',time') = progressCompletedness startingTime progress
    in  Tick (Context (adapt (instants completed))
                      (time',current)
                      (fmap (fmap (\s -> (Nothing,s))) pending)
              :| map (contextCompletedness (\t -> Right (t,Nothing))) contexts)  
             progress'
completedness (Tick (Context {completed,current,pending}:|contexts) progress) = 
    let startingTime = extract completed
        (progress',time') = progressCompletedness startingTime progress
    in  Tick (Context (adapt (instants completed))
                      (time',current)
                      (fmap (fmap (\s -> (Nothing,s))) pending)
              :| map (contextCompletedness (\t -> Right (t,Nothing))) contexts)  
             progress'