git.iko.soy/typeable/pandoc
on master help sign in
Shared: Added ordNub.
2a627f8John MacFarlane
src/Text/Pandoc/Shared.hs+9
@@ -35,6 +35,7 @@ module Text.Pandoc.Shared (
35 splitByIndices,
35 splitByIndices,
36 splitStringByIndices,
36 splitStringByIndices,
37 substitute,
37 substitute,
38+ ordNub,
38 -- * Text processing
39 -- * Text processing
39 backslashEscapes,
40 backslashEscapes,
40 escapeStringUsing,
41 escapeStringUsing,
@@ -94,6 +95,7 @@ import Data.List ( find, isPrefixOf, intercalate )
94import qualified Data.Map as M
95import qualified Data.Map as M
95import Network.URI ( escapeURIString, isURI, nonStrictRelativeTo,
96import Network.URI ( escapeURIString, isURI, nonStrictRelativeTo,
96 unEscapeString, parseURIReference )
97 unEscapeString, parseURIReference )
98+import qualified Data.Set as Set
97import System.Directory
99import System.Directory
98import Text.Pandoc.MIME (getMimeType)
100import Text.Pandoc.MIME (getMimeType)
99import System.FilePath ( (</>), takeExtension, dropExtension )
101import System.FilePath ( (</>), takeExtension, dropExtension )
@@ -174,6 +176,13 @@ substitute target replacement lst@(x:xs) =
174 then replacement ++ substitute target replacement (drop (length target) lst)
176 then replacement ++ substitute target replacement (drop (length target) lst)
175 else x : substitute target replacement xs
177 else x : substitute target replacement xs
176
178
179+ordNub :: (Ord a) => [a] -> [a]
180+ordNub l = go Set.empty l
181+ where
182+ go _ [] = []
183+ go s (x:xs) = if x `Set.member` s then go s xs
184+ else x : go (Set.insert x s) xs
185+
177--
186--
178-- Text processing
187-- Text processing
179--
188--