walk :: [FilePattern] -> (Bool, Walk)
walk ps = (any (\p -> isEmpty p || not (null $ match p [""])) ps2, f ps2)
    where
        ps2 = map (filter (/= Lit ".") . optimise . parse) ps

        f (nubOrd -> ps)
            | Just fin <- mapM fromLit fin
            , Just nxt <- mapM (\(a,b) -> (,f b) <$> fromLit a) nxt
            = WalkTo (fin, nxt)
            | otherwise = Walk $ \xs ->
                (if finStar then xs else filter (\x -> any (`matchOne` x) fin) xs
                ,[(x, f ys) | x <- xs, let ys = concat [b | (a,b) <- nxt, matchOne a x], not $ null ys])
            where
                finStar = Star `elem` fin
                fin = nubOrd $ mapMaybe final ps
                nxt = groupSort $ concatMap next ps
walk :: [FilePattern] -> (Bool, Walk)
walk ps = (any (\p -> isEmpty p || not (null $ match p [""])) ps2, f ps2)
    where
        ps2 = map (filter (/= Lit ".") . optimise . parse) ps

        f (nubOrd -> ps)
            | Just fin <- mapM fromLit fin
            , Just nxt <- mapM (\(a,b) -> (,f b) <$> fromLit a) nxt
            = WalkTo (fin, nxt)
            | otherwise = Walk $ \xs ->
                (if finStar then xs else filter (\x -> any (`matchOne` x) fin) xs
                ,[(x, f ys) | x <- xs, let ys = concat [b | (a,b) <- nxt, matchOne a x], not $ null ys])
            where
                finStar = Star `elem` fin
                fin = nubOrd $ mapMaybe final ps
                nxt = groupSort $ concatMap next ps
walk ps = (any (\p -> isEmpty p || not (null $ match p [""])) ps2, f ps2)
    where
        ps2 = map (filter (/= Lit ".") . optimise . parse) ps

        f (nubOrd -> ps)
            | Just fin <- mapM fromLit fin
            , Just nxt <- mapM (\(a,b) -> (,f b) <$> fromLit a) nxt
            = WalkTo (fin, nxt)
            | otherwise = Walk $ \xs ->
                (if finStar then xs else filter (\x -> any (`matchOne` x) fin) xs
                ,[(x, f ys) | x <- xs, let ys = concat [b | (a,b) <- nxt, matchOne a x], not $ null ys])
            where
                finStar = Star `elem` fin
                fin = nubOrd $ mapMaybe final ps
                nxt = groupSort $ concatMap next ps