Skip to content

Commit 8a4a7f0

Browse files
committed
Use cons x y instead of singleton x <> y
1 parent a80bd07 commit 8a4a7f0

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

System/FilePath/Internal.hs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ getSearchPath = fmap splitSearchPath (getEnv "PATH")
293293
splitExtension :: FILEPATH -> (STRING, STRING)
294294
splitExtension x = if null nameDot
295295
then (x, mempty)
296-
else (dir <> init nameDot, singleton extSeparator <> ext)
296+
else (dir <> init nameDot, extSeparator `cons` ext)
297297
where
298298
(dir,file) = splitFileName_ x
299299
(nameDot,ext) = breakEnd isExtSeparator file
@@ -358,7 +358,7 @@ addExtension file xs = case uncons xs of
358358
Just (x, _) -> joinDrive a res
359359
where
360360
res = if isExtSeparator x then b <> xs
361-
else b <> singleton extSeparator <> xs
361+
else b <> (extSeparator `cons` xs)
362362

363363
(a,b) = splitDrive file
364364

@@ -383,7 +383,7 @@ isExtensionOf :: STRING -> FILEPATH -> Bool
383383
isExtensionOf ext = \fp -> case uncons ext of
384384
Just (x, _)
385385
| x == _period -> isSuffixOf ext . takeExtensions $ fp
386-
_ -> isSuffixOf (singleton _period <> ext) . takeExtensions $ fp
386+
_ -> isSuffixOf (_period `cons` ext) . takeExtensions $ fp
387387

388388
-- | Drop the given extension from a FILEPATH, and the @\".\"@ preceding it.
389389
-- Returns 'Nothing' if the FILEPATH does not have the given extension, or
@@ -403,7 +403,7 @@ isExtensionOf ext = \fp -> case uncons ext of
403403
-- > stripExtension "" x == Just x
404404
stripExtension :: STRING -> FILEPATH -> Maybe FILEPATH
405405
stripExtension ext path = case uncons ext of
406-
Just (x, _) -> let dotExt = if isExtSeparator x then ext else singleton _period <> ext
406+
Just (x, _) -> let dotExt = if isExtSeparator x then ext else _period `cons` ext
407407
in stripSuffix dotExt path
408408
Nothing -> Just path
409409

@@ -520,7 +520,7 @@ readDriveShare :: STRING -> Maybe (FILEPATH, FILEPATH)
520520
readDriveShare bs = case unpack bs of
521521
(s1:s2:xs) | isPathSeparator s1 && isPathSeparator s2 ->
522522
let (a, b) = readDriveShareName (pack xs)
523-
in Just (singleton s1 <> singleton s2 <> a,b)
523+
in Just (s1 `cons` (s2 `cons` a), b)
524524
_ -> Nothing
525525

526526
{- assume you have already seen \\ -}
@@ -596,7 +596,7 @@ splitFileName x = if null path
596596
else (path, file)
597597
where
598598
(path, file) = splitFileName_ x
599-
dotSlash = singleton _period <> singleton _slash
599+
dotSlash = _period `cons` singleton _slash
600600

601601
-- version of splitFileName where, if the FILEPATH has no directory
602602
-- component, the returned directory is "" rather than "./". This
@@ -738,7 +738,7 @@ combineAlways a b | null a = b
738738
[a1, a2] | isWindows
739739
, isLetter a1
740740
, a2 == _colon -> a <> b
741-
_ -> a <> singleton pathSeparator <> b
741+
_ -> a <> (pathSeparator `cons` b)
742742

743743

744744
-- | Combine two paths with a path separator.
@@ -1070,7 +1070,7 @@ makeValid path
10701070
| isPosix = map (\x -> if x == _nul then _underscore else x) path
10711071
| isJust (readDriveShare drv) && all isPathSeparator drv = take 2 drv <> fromString "drive"
10721072
| isJust (readDriveUNC drv) && not (hasTrailingPathSeparator drv) =
1073-
makeValid (drv <> singleton pathSeparator <> pth)
1073+
makeValid (drv <> (pathSeparator `cons` pth))
10741074
| otherwise = joinDrive drv $ validElements $ validCHARs pth
10751075

10761076
where
@@ -1145,6 +1145,8 @@ breakEnd p = spanEnd (not . p)
11451145
stripSuffix :: Eq a => [a] -> [a] -> Maybe [a]
11461146
stripSuffix xs ys = reverse P.<$> stripPrefix (reverse xs) (reverse ys)
11471147

1148+
cons :: a -> [a] -> [a]
1149+
cons = (:)
11481150

11491151
unsnoc :: [a] -> Maybe ([a], a)
11501152
unsnoc = L.foldr (\x -> Just . maybe ([], x) (first (x :))) Nothing

0 commit comments

Comments
 (0)