restartWhen :: Coroutine a b -> Coroutine (a, Event e) b
restartWhen co = Coroutine $ step co where
    step c (i, ev) = (o, fmap Coroutine cont) where
        (o, c') = runC c i
        cont
            | null ev   = fmap step c'
            | otherwise = Just $ step co
restartWhen :: Coroutine a b -> Coroutine (a, Event e) b
restartWhen co = Coroutine $ step co where
    step c (i, ev) = (o, fmap Coroutine cont) where
        (o, c') = runC c i
        cont
            | null ev   = fmap step c'
            | otherwise = Just $ step co
restartWhen co = Coroutine $ step co where
    step c (i, ev) = (o, fmap Coroutine cont) where
        (o, c') = runC c i
        cont
            | null ev   = fmap step c'
            | otherwise = Just $ step co