Skip to content
Browse files

remove a fromJust

  • Loading branch information...
1 parent e359c8e commit 089bbed7c78c6b593474afd0e064ba958015d957 @Geal committed Mar 6, 2013
Showing with 7 additions and 5 deletions.
  1. +7 −5 site.hs
View
12 site.hs
@@ -80,25 +80,27 @@ main = hakyll $ do
type PostUrl = Int
type PostContent = String
-type PostData = (PostUrl, PostContent)
+type PostData = (Maybe PostUrl, PostContent)
type Word = String
type WordList = [Word]
-type PostWords = (PostUrl, WordList)
+type PostWords = (Maybe PostUrl, WordList)
type SearchData = [(Word, [PostUrl])]
type UrlList = [PostUrl]
type MapSearchData = M.Map Word UrlList
-- get post title, URL and content
extractPostData :: [Identifier] -> Item String -> PostData
extractPostData posts post =
- let url = fromJust (elemIndex (itemIdentifier post) posts)
+ let url = elemIndex (itemIdentifier post) posts
content = itemBody post
in (url, content)
-addUrlToSearch :: PostUrl -> MapSearchData -> Word -> MapSearchData
-addUrlToSearch url search word = case M.lookup word search of
+addUrlToSearch :: Maybe PostUrl -> MapSearchData -> Word -> MapSearchData
+addUrlToSearch (Just url) search word = case M.lookup word search of
Just urlList -> M.insert word (url : urlList) search
Nothing -> M.insert word [url] search
+addUrlToSearch Nothing search _ = search
+
addPostToSearch :: SearchData -> PostWords -> SearchData
addPostToSearch search post = M.toList (foldl (addUrlToSearch (fst post)) (M.fromList search) (snd post) )

0 comments on commit 089bbed

Please sign in to comment.
Something went wrong with that request. Please try again.