{"action":"created","issue":{"url":"https://api.github.com/repos/haskell/directory/issues/46","repository_url":"https://api.github.com/repos/haskell/directory","labels_url":"https://api.github.com/repos/haskell/directory/issues/46/labels{/name}","comments_url":"https://api.github.com/repos/haskell/directory/issues/46/comments","events_url":"https://api.github.com/repos/haskell/directory/issues/46/events","html_url":"https://github.com/haskell/directory/pull/46","id":136152863,"number":46,"title":"Fix laziness issue in findExecutable and findFile, add findFileWith","user":{"login":"sjakobi","id":3664523,"avatar_url":"https://avatars.githubusercontent.com/u/3664523?v=3","gravatar_id":"","url":"https://api.github.com/users/sjakobi","html_url":"https://github.com/sjakobi","followers_url":"https://api.github.com/users/sjakobi/followers","following_url":"https://api.github.com/users/sjakobi/following{/other_user}","gists_url":"https://api.github.com/users/sjakobi/gists{/gist_id}","starred_url":"https://api.github.com/users/sjakobi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sjakobi/subscriptions","organizations_url":"https://api.github.com/users/sjakobi/orgs","repos_url":"https://api.github.com/users/sjakobi/repos","events_url":"https://api.github.com/users/sjakobi/events{/privacy}","received_events_url":"https://api.github.com/users/sjakobi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-24T18:52:25Z","updated_at":"2016-02-27T03:05:32Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/haskell/directory/pulls/46","html_url":"https://github.com/haskell/directory/pull/46","diff_url":"https://github.com/haskell/directory/pull/46.diff","patch_url":"https://github.com/haskell/directory/pull/46.patch"},"body":"Fixes https://github.com/haskell/directory/issues/43"},"comment":{"url":"https://api.github.com/repos/haskell/directory/issues/comments/189564770","html_url":"https://github.com/haskell/directory/pull/46#issuecomment-189564770","issue_url":"https://api.github.com/repos/haskell/directory/issues/46","id":189564770,"user":{"login":"Rufflewind","id":6571068,"avatar_url":"https://avatars.githubusercontent.com/u/6571068?v=3","gravatar_id":"","url":"https://api.github.com/users/Rufflewind","html_url":"https://github.com/Rufflewind","followers_url":"https://api.github.com/users/Rufflewind/followers","following_url":"https://api.github.com/users/Rufflewind/following{/other_user}","gists_url":"https://api.github.com/users/Rufflewind/gists{/gist_id}","starred_url":"https://api.github.com/users/Rufflewind/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rufflewind/subscriptions","organizations_url":"https://api.github.com/users/Rufflewind/orgs","repos_url":"https://api.github.com/users/Rufflewind/repos","events_url":"https://api.github.com/users/Rufflewind/events{/privacy}","received_events_url":"https://api.github.com/users/Rufflewind/received_events","type":"User","site_admin":false},"created_at":"2016-02-27T03:05:32Z","updated_at":"2016-02-27T03:05:32Z","body":"Perhaps, instead of using a flag to control the laziness, one could write a lookup function for a single directory (`findFileWithIn`):\r\n\r\n~~~hs\r\nfindFilesWithIn :: (FilePath -> IO Bool) -> String -> FilePath -> IO (Maybe FilePath)\r\nfindFilesWithIn f name d = do\r\n    let path = d </> name\r\n    exist <- doesFileExist path\r\n    if exist\r\n      then do\r\n        ok <- f path\r\n        if ok\r\n          then return (Just path)\r\n          else return Nothing\r\n      else return Nothing\r\n~~~\r\n\r\nand then use combinators to construct `findFilesWith` and `findFileWith`:\r\n\r\n~~~hs\r\nfindFilesWith f ds name = catMaybes <$> traverse (findFilesWithIn f name) ds\r\nfindFileWith f ds name = asumMaybeT (findFilesWithIn f name <$> ds)\r\n~~~\r\n\r\nThe combinator `asumMaybeT` would be written as:\r\n\r\n~~~hs\r\nasumMaybeT :: (Foldable t, Monad m) => t (m (Maybe a)) -> m (Maybe a)\r\nasumMaybeT = foldr attempt (return Nothing)\r\n  where attempt mmx mx' = do\r\n          mx <- mmx\r\n          case mx of\r\n            Nothing -> mx'\r\n            Just _  -> return mx\r\n~~~\r\n\r\nwhich is essentially `asum` for `MaybeT`.\r\n"}}