Skip to content

Commit 745f742

Browse files
Rename some Path APIs and fix docs, doctests of some
1 parent 1be8b88 commit 745f742

File tree

13 files changed

+714
-417
lines changed

13 files changed

+714
-417
lines changed

bench-test-lib/src/BenchTestLib/DirIO.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ import qualified Streamly.Internal.Data.Unfold as Unfold
6161
import qualified Streamly.Internal.FileSystem.DirIO as Dir
6262
import qualified Streamly.FileSystem.Path as Path
6363
#if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
64-
import qualified Streamly.Internal.FileSystem.Path as Path (toChunk)
6564
import qualified Streamly.Internal.FileSystem.Posix.ReadDir as Dir
6665
#endif
6766

@@ -165,7 +164,7 @@ listDirChunkedWith
165164
-> [Char] -> Stream IO Word8
166165
listDirChunkedWith act inp = do
167166
Stream.unfoldEachEndBy 10 Array.reader
168-
$ fmap (Array.asBytes . Path.toChunk)
167+
$ fmap (Array.asBytes . Path.toArray)
169168
$ Stream.unfoldEach Unfold.fromList
170169
$ fmap (either id id)
171170
$ act
@@ -177,7 +176,7 @@ listDirWith
177176
-> [Char] -> Stream IO Word8
178177
listDirWith act inp = do
179178
Stream.unfoldEachEndBy 10 Array.reader
180-
$ fmap (Array.asBytes . Path.toChunk . either id id)
179+
$ fmap (Array.asBytes . Path.toArray . either id id)
181180
$ act
182181
$ Stream.fromPure (Left (fromJust $ Path.fromString inp))
183182

core/src/DocTestFileSystemPath.hs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{- $setup
2+
>>> :m
3+
>>> :set -XQuasiQuotes
4+
>>> import Control.Exception (SomeException, evaluate, try)
5+
>>> import Data.Either (Either, isLeft)
6+
>>> import Data.Maybe (fromJust, isJust, isNothing)
7+
>>> import Streamly.FileSystem.Path (Path, path)
8+
>>> import qualified Streamly.Data.Array as Array
9+
>>> import qualified Streamly.Data.Stream as Stream
10+
>>> import qualified Streamly.FileSystem.Path as Path
11+
>>> import qualified Streamly.Unicode.Stream as Unicode
12+
13+
For APIs that have not been released yet.
14+
15+
>>> import qualified Streamly.Internal.FileSystem.Path as Path
16+
17+
Utilities:
18+
19+
>>> fails x = isLeft <$> (try (evaluate x) :: IO (Either SomeException String))
20+
-}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{- $setup
2+
>>> :m
3+
>>> :set -XQuasiQuotes
4+
>>> import Control.Exception (SomeException, evaluate, try)
5+
>>> import Data.Either (Either, isLeft)
6+
>>> import Data.Maybe (isNothing, isJust)
7+
>>> import qualified Streamly.Data.Array as Array
8+
>>> import qualified Streamly.Data.Stream as Stream
9+
>>> import qualified Streamly.Unicode.Stream as Unicode
10+
11+
For APIs that have not been released yet.
12+
13+
>>> import Streamly.Internal.FileSystem.PosixPath (PosixPath, path)
14+
>>> import qualified Streamly.Internal.FileSystem.PosixPath as Path
15+
16+
Utilities:
17+
18+
>>> fails x = isLeft <$> (try (evaluate x) :: IO (Either SomeException String))
19+
-}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{- $setup
2+
>>> :m
3+
>>> :set -XQuasiQuotes
4+
>>> import Control.Exception (SomeException, evaluate, try)
5+
>>> import Data.Either (Either, isLeft)
6+
>>> import Data.Maybe (fromJust, isNothing, isJust)
7+
>>> import Data.Word (Word16)
8+
>>> import Streamly.Data.Array (Array)
9+
>>> import qualified Streamly.Data.Array as Array
10+
>>> import qualified Streamly.Data.Stream as Stream
11+
>>> import qualified Streamly.Unicode.Stream as Unicode
12+
13+
For APIs that have not been released yet.
14+
15+
>>> import Streamly.Internal.FileSystem.WindowsPath (WindowsPath, path)
16+
>>> import qualified Streamly.Internal.FileSystem.WindowsPath as Path
17+
18+
Utilities:
19+
20+
>>> fails x = isLeft <$> (try (evaluate x) :: IO (Either SomeException String))
21+
-}

core/src/Streamly/FileSystem/Path.hs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
-- |
23
-- Module : Streamly.FileSystem.Path
34
-- Copyright : (c) 2023 Composewell Technologies
@@ -10,9 +11,11 @@
1011
--
1112
-- The 'Path' type is built on top of Streamly's 'Array' type, leveraging all
1213
-- its operations — including support for both pinned and unpinned
13-
-- representations. It is designed for extensibility and fine-grained type
14-
-- safety. For type-safe adaptations, see the
15-
-- "Streamly.Internal.FileSystem.Path.*" modules.
14+
-- representations. The API integrates with streaming, prioritizes safety,
15+
-- flexibility, and performance. It supports configurable equality for
16+
-- cross-platform compatibility and user-defined path matching. It is designed
17+
-- for extensibility and fine-grained type safety as well. For type-safe
18+
-- adaptations, see the "Streamly.Internal.FileSystem.Path.*" modules.
1619
--
1720
-- 'Path' is interconvertible with the 'OsPath' type from the @filepath@
1821
-- package at zero runtime cost. While the API is mostly compatible with that
@@ -68,11 +71,19 @@
6871

6972
module Streamly.FileSystem.Path
7073
(
74+
-- * Setup
75+
-- | To execute the code examples provided in this module in ghci, please
76+
-- run the following commands first.
77+
--
78+
-- $setup
79+
7180
-- * Type
7281
Path
82+
, OsWord
7383

7484
-- * Construction
75-
, fromChunk
85+
, validatePath
86+
, fromArray
7687
, fromString
7788

7889
-- * Statically Verified String Literals
@@ -84,20 +95,15 @@ module Streamly.FileSystem.Path
8495
, pathE
8596

8697
-- * Elimination
87-
, toChunk
88-
, toChars
98+
, toArray
99+
-- , toChars -- need fromChars as well
89100
, toString
90-
, asOsCString
101+
-- , asOsCString
91102

92103
-- * Path Info
93104
, isRooted
94105
, isBranch
95106

96-
-- * Separators
97-
, dropTrailingSeparators
98-
, hasTrailingSeparator
99-
, addTrailingSeparator
100-
101107
-- * Joining
102108
, unsafeExtend
103109
, extend
@@ -123,14 +129,11 @@ module Streamly.FileSystem.Path
123129

124130
-- * Equality
125131
, EqCfg
126-
, eqPath
127-
128-
#ifndef IS_WINDOWS
129-
-- ** Config options (Posix)
130132
, ignoreTrailingSeparators
131133
, ignoreCase
132134
, allowRelativeEquality
133-
#endif
135+
136+
, eqPath
134137
)
135138
where
136139

@@ -186,3 +189,5 @@ where
186189
-}
187190

188191
import Streamly.Internal.FileSystem.Path
192+
193+
#include "DocTestFileSystemPath.hs"

core/src/Streamly/Internal/FileSystem/Path.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
-- |
23
-- Module : Streamly.Internal.FileSystem.Path
34
-- Copyright : (c) 2023 Composewell Technologies

0 commit comments

Comments
 (0)