@@ -16,8 +16,11 @@ module Data.Path.Pathy
16
16
, RelPath ()
17
17
, Sandboxed ()
18
18
, Unsandboxed ()
19
+ , appendPath
19
20
, (</>)
21
+ , setExtension
20
22
, (<.>)
23
+ , parentAppend
21
24
, (<..>)
22
25
, runDirName
23
26
, runFileName
@@ -66,7 +69,7 @@ module Data.Path.Pathy
66
69
where
67
70
68
71
import Prelude
69
- import qualified Data.String as S
72
+ import Data.String as S
70
73
import Data.Foldable (foldl )
71
74
import Data.Array ((!!), filter , length , zipWith , range )
72
75
import Data.Tuple (Tuple (..), fst , snd )
@@ -196,7 +199,7 @@ module Data.Path.Pathy
196
199
changeExtension f nm @ (FileName n ) =
197
200
let
198
201
ext = f $ extension nm
199
- in (\(FileName n) -> if ext == "" then FileName n else FileName $ n ++ "." ++ ext ) (dropExtension nm )
202
+ in (\(FileName n) -> if ext == "" then FileName n else FileName $ n <> "." <> ext ) (dropExtension nm )
200
203
201
204
-- | Creates a path which points to a relative directory of the specified name.
202
205
dir :: forall s. String -> Path Rel Dir s
@@ -216,41 +219,41 @@ module Data.Path.Pathy
216
219
pathName :: forall b s. AnyPath b s -> Either (Maybe DirName ) FileName
217
220
pathName = bimap dirName fileName
218
221
219
- infixl 6 </>
220
-
221
222
-- | Given a directory path, appends either a file or directory to the path.
222
- (</>) :: forall a b s. Path a Dir s -> Path Rel b s -> Path a b s
223
- (</>) (Current ) (Current ) = Current
224
- (</>) (Root ) (Current ) = Root
225
- (</>) (ParentIn p1 ) (Current ) = ParentIn (p1 </> Current )
226
- (</>) (FileIn p1 f1 ) (Current ) = FileIn (p1 </> Current ) f1
227
- (</>) (DirIn p1 d1 ) (Current ) = DirIn (p1 </> Current ) d1
228
- (</>) (Current ) (Root ) = Current -- doesn't make sense but cannot exist
229
- (</>) (Root ) (Root ) = Root -- doesn't make sense but cannot exist
230
- (</>) (ParentIn p1 ) (Root ) = ParentIn (p1 </> Current ) -- doesn't make sense but cannot exist
231
- (</>) (FileIn p1 f1 ) (Root ) = FileIn (p1 </> Current ) f1 -- doesn't make sense but cannot exist
232
- (</>) (DirIn p1 d1 ) (Root ) = DirIn (p1 </> Current ) d1 -- doesn't make sense but cannot exist
233
- (</>) (p1 ) (ParentIn p2 ) = ParentIn (p1 </> p2 )
234
- (</>) (p1 ) (FileIn p2 f2 ) = FileIn (p1 </> p2 ) f2
235
- (</>) (p1 ) (DirIn p2 d2 ) = DirIn (p1 </> p2 ) d2
236
-
237
- infixl 6 <. >
223
+ append Path :: forall a b s. Path a Dir s -> Path Rel b s -> Path a b s
224
+ append Path (Current ) (Current ) = Current
225
+ append Path (Root ) (Current ) = Root
226
+ append Path (ParentIn p1 ) (Current ) = ParentIn (p1 </> Current )
227
+ append Path (FileIn p1 f1 ) (Current ) = FileIn (p1 </> Current ) f1
228
+ append Path (DirIn p1 d1 ) (Current ) = DirIn (p1 </> Current ) d1
229
+ append Path (Current ) (Root ) = Current -- doesn't make sense but cannot exist
230
+ append Path (Root ) (Root ) = Root -- doesn't make sense but cannot exist
231
+ append Path (ParentIn p1 ) (Root ) = ParentIn (p1 </> Current ) -- doesn't make sense but cannot exist
232
+ append Path (FileIn p1 f1 ) (Root ) = FileIn (p1 </> Current ) f1 -- doesn't make sense but cannot exist
233
+ append Path (DirIn p1 d1 ) (Root ) = DirIn (p1 </> Current ) d1 -- doesn't make sense but cannot exist
234
+ append Path (p1 ) (ParentIn p2 ) = ParentIn (p1 </> p2 )
235
+ append Path (p1 ) (FileIn p2 f2 ) = FileIn (p1 </> p2 ) f2
236
+ append Path (p1 ) (DirIn p2 d2 ) = DirIn (p1 </> p2 ) d2
237
+
238
+ infixl 6 append Path as </ >
238
239
239
240
-- | Sets the extension of the file to the specified extension.
240
241
-- |
241
242
-- | ```purescript
242
243
-- | file "image" <.> "png"
243
244
-- | ```
244
- (<.>) :: forall a s. Path a File s -> String -> Path a File s
245
- (<.>) p ext = renameFile (changeExtension $ const ext ) p
245
+ set Extension :: forall a s. Path a File s -> String -> Path a File s
246
+ set Extension p ext = renameFile (changeExtension $ const ext ) p
246
247
247
- infixl 6 <. .>
248
+ infixl 6 set Extension as < .>
248
249
249
250
-- | Ascends into the parent of the specified directory, then descends into
250
251
-- | the specified path. The result is always unsandboxed because it may escape
251
252
-- | its previous sandbox.
252
- (<..>) :: forall a b s s'. Path a Dir s -> Path Rel b s' -> Path a b Unsandboxed
253
- (<..>) d p = (parentDir' d ) </> unsandbox p
253
+ parentAppend :: forall a b s s'. Path a Dir s -> Path Rel b s' -> Path a b Unsandboxed
254
+ parentAppend d p = (parentDir' d ) </> unsandbox p
255
+
256
+ infixl 6 parentAppend as <..>
254
257
255
258
-- | Determines if this path is absolutely located.
256
259
isAbsolute :: forall a b s. Path a b s -> Boolean
@@ -385,11 +388,11 @@ module Data.Path.Pathy
385
388
where
386
389
go (Current ) = " ./"
387
390
go (Root ) = " /"
388
- go (ParentIn p ) = go p ++ " ../"
389
- go (DirIn p @ (FileIn _ _ ) (DirName d)) = go p ++ " /" ++ d ++ " /" -- dir inside a file
390
- go (DirIn p (DirName d)) = go p ++ d ++ " /" -- dir inside a dir
391
- go (FileIn p @ (FileIn _ _) (FileName f)) = go p ++ " /" ++ f -- file inside a file
392
- go (FileIn p (FileName f)) = go p ++ f
391
+ go (ParentIn p ) = go p <> " ../"
392
+ go (DirIn p @ (FileIn _ _ ) (DirName d)) = go p <> " /" <> d <> " /" -- dir inside a file
393
+ go (DirIn p (DirName d)) = go p <> d <> " /" -- dir inside a dir
394
+ go (FileIn p @ (FileIn _ _) (FileName f)) = go p <> " /" <> f -- file inside a file
395
+ go (FileIn p (FileName f)) = go p <> f
393
396
394
397
unsafePrintPath :: forall a b s. Path a b s -> String
395
398
unsafePrintPath = unsafePrintPath' posixEscaper
@@ -458,7 +461,7 @@ module Data.Path.Pathy
458
461
segs = S. split " /" p
459
462
last = length segs - 1
460
463
isAbs = S. take 1 p == " /"
461
- isFile = maybe false (/= "") (segs !! last )
464
+ isFile = maybe false (_ /= "") (segs !! last )
462
465
tuples = zipWith Tuple segs (range 0 last )
463
466
464
467
folder :: forall a b s. Path a b s -> Tuple String Int -> Path a b s
@@ -495,15 +498,15 @@ module Data.Path.Pathy
495
498
instance showPath :: Show (Path a b s ) where
496
499
show (Current ) = " currentDir"
497
500
show (Root ) = " rootDir"
498
- show (ParentIn p ) = " (parentDir' " ++ show p ++ " )"
499
- show (FileIn p (FileName f)) = " (" ++ show p ++ " </> file " ++ show f ++ " )"
500
- show (DirIn p (DirName f)) = " (" ++ show p ++ " </> dir " ++ show f ++ " )"
501
+ show (ParentIn p ) = " (parentDir' " <> show p <> " )"
502
+ show (FileIn p (FileName f)) = " (" <> show p <> " </> file " <> show f <> " )"
503
+ show (DirIn p (DirName f)) = " (" <> show p <> " </> dir " <> show f <> " )"
501
504
502
505
instance eqPath :: Eq (Path a b s ) where
503
506
eq p1 p2 = canonicalize p1 `identicalPath ` canonicalize p2
504
507
505
508
instance showFileName :: Show FileName where
506
- show (FileName name ) = " FileName " ++ show name
509
+ show (FileName name ) = " FileName " <> show name
507
510
508
511
instance eqFileName :: Eq FileName where
509
512
eq (FileName n1 ) (FileName n2 ) = n1 == n2
@@ -512,7 +515,7 @@ module Data.Path.Pathy
512
515
compare (FileName n1 ) (FileName n2 ) = compare n1 n2
513
516
514
517
instance showDirName :: Show DirName where
515
- show (DirName name ) = " DirName " ++ show name
518
+ show (DirName name ) = " DirName " <> show name
516
519
517
520
instance eqDirName :: Eq DirName where
518
521
eq (DirName n1 ) (DirName n2 ) = n1 == n2
0 commit comments