breadcrumbs: guard refactor

This commit is contained in:
Tom Sydney Kerckhove 2021-05-21 08:41:42 +02:00
parent 884d937792
commit 0db056534c

View File

@ -16,7 +16,7 @@ class YesodBreadcrumbs site where
-- | Gets the title of the current page and the hierarchy of parent pages, -- | Gets the title of the current page and the hierarchy of parent pages,
-- along with their respective titles. -- along with their respective titles.
breadcrumbs :: (YesodBreadcrumbs site, Eq (Route site)) => HandlerFor site (Text, [(Route site, Text)]) breadcrumbs :: (YesodBreadcrumbs site, Show (Route site), Eq (Route site)) => HandlerFor site (Text, [(Route site, Text)])
breadcrumbs = do breadcrumbs = do
x <- getCurrentRoute x <- getCurrentRoute
case x of case x of
@ -27,10 +27,8 @@ breadcrumbs = do
return (title, z) return (title, z)
where where
go back Nothing = return back go back Nothing = return back
go back (Just this) = do go back (Just this)
(title, next) <- breadcrumb this | this `elem` map fst back = error $ "yesod-core: infinite recursion in breadcrumbs at " ++ show this
if this `elem` map fst back | otherwise = do
then (title, next) <- breadcrumb this
error $ "yesod-core: infinite recursion in breadcrumbs at " ++ show title
else
go ((this, title) : back) next go ((this, title) : back) next