summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2022-10-19 13:07:19 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2022-10-19 13:07:19 -0700
commit69485b0c0d1c55ccee28fd09d0eca6dc3089b0fb (patch)
treec66d222c9d49e77c149165100871d80e9c05eb2d
parentfc8b0c4540dc7c9f6b89e10072414cb9872cd370 (diff)
Text.Pandoc.Shared: remove `findM` [API change].
This was only used in one place, and can be replaced with simpler code.
-rw-r--r--src/Text/Pandoc/App/Opt.hs10
-rw-r--r--src/Text/Pandoc/Shared.hs13
2 files changed, 8 insertions, 15 deletions
diff --git a/src/Text/Pandoc/App/Opt.hs b/src/Text/Pandoc/App/Opt.hs
index 710df3200..2c0cef5cd 100644
--- a/src/Text/Pandoc/App/Opt.hs
+++ b/src/Text/Pandoc/App/Opt.hs
@@ -43,7 +43,6 @@ import Text.Pandoc.Options (TopLevelDivision (TopLevelDefault),
import Text.Pandoc.Class (readFileStrict, fileExists, setVerbosity, report,
PandocMonad(lookupEnv), getUserDataDir)
import Text.Pandoc.Error (PandocError (PandocParseError, PandocSomeError))
-import Text.Pandoc.Shared (findM)
import Data.Containers.ListUtils (nubOrd)
import Text.Pandoc.Data (defaultUserDataDir)
import qualified Text.Pandoc.Parsing as P
@@ -802,7 +801,14 @@ fullDefaultsPath dataDir file = do
else file
defaultDataDir <- liftIO defaultUserDataDir
let defaultFp = fromMaybe defaultDataDir dataDir </> "defaults" </> fp
- fromMaybe fp <$> findM fileExists [fp, defaultFp]
+ fpExists <- fileExists fp
+ if fpExists
+ then return fp
+ else do
+ defaultFpExists <- fileExists defaultFp
+ if defaultFpExists
+ then return defaultFp
+ else return fp
-- | In a list of lists, append another list in front of every list which
-- starts with specific element.
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index f60d2708f..3efe8a538 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -22,7 +22,6 @@ module Text.Pandoc.Shared (
splitBy,
splitTextBy,
splitTextByIndices,
- findM,
-- * Text processing
inquotes,
tshow,
@@ -153,18 +152,6 @@ splitAt' n xs | n <= 0 = ([],xs)
splitAt' n (x:xs) = (x:ys,zs)
where (ys,zs) = splitAt' (n - charWidth x) xs
--- | Returns the first element in a foldable structure for that the
--- monadic predicate holds true, and @Nothing@ if no such element
--- exists.
-findM :: forall m t a. (Monad m, Foldable t)
- => (a -> m Bool) -> t a -> m (Maybe a)
-findM p = foldr go (pure Nothing)
- where
- go :: a -> m (Maybe a) -> m (Maybe a)
- go x acc = do
- b <- p x
- if b then pure (Just x) else acc
-
--
-- Text processing
--