Skip to content

Commit b302b7a

Browse files
Add signatures for splitFirst and splitLast
1 parent 2fb4a16 commit b302b7a

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,15 +718,15 @@ splitPath = splitPathUsing True
718718
-- /Unimplemented/
719719
{-# INLINE splitHead #-}
720720
splitHead :: -- (Unbox a, Integral a) =>
721-
OS -> Array a -> (Array a, Array a)
721+
OS -> Array a -> (Array a, Maybe (Array a))
722722
splitHead _os _arr = undefined
723723

724724
-- | Split the last non-empty path component.
725725
--
726726
-- /Unimplemented/
727727
{-# INLINE splitTail #-}
728728
splitTail :: -- (Unbox a, Integral a) =>
729-
OS -> Array a -> (Array a, Array a)
729+
OS -> Array a -> (Maybe (Array a), Array a)
730730
splitTail _os _arr = undefined
731731

732732
------------------------------------------------------------------------------

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ module Streamly.Internal.FileSystem.OS_PATH
150150
, splitPath_
151151
, splitFile
152152

153+
, splitFirst
154+
, splitLast
155+
153156
, splitExtension
154157
, dropExtension
155158
, addExtension
@@ -886,6 +889,25 @@ splitFile :: OS_PATH -> Maybe (Maybe OS_PATH, OS_PATH)
886889
splitFile (OS_PATH a) =
887890
fmap (bimap (fmap OS_PATH) OS_PATH) $ Common.splitFile Common.OS_NAME a
888891

892+
-- | Split the path into the first component and rest of the path. Treats the
893+
-- entire root or share name, if present, as the first component.
894+
--
895+
-- /Unimplemented/
896+
splitFirst :: OS_PATH -> (OS_PATH, Maybe OS_PATH)
897+
splitFirst (OS_PATH a) =
898+
bimap OS_PATH (fmap OS_PATH) $ Common.splitHead Common.OS_NAME a
899+
900+
-- | Split the path into the last component and rest of the path. Treats the
901+
-- entire root or share name, if present, as the first component.
902+
--
903+
-- >>> basename = snd . Path.splitLast -- Posix basename
904+
-- >>> dirname = fst . Path.splitLast -- Posix dirname
905+
--
906+
-- /Unimplemented/
907+
splitLast :: OS_PATH -> (Maybe OS_PATH, OS_PATH)
908+
splitLast (OS_PATH a) =
909+
bimap (fmap OS_PATH) OS_PATH $ Common.splitTail Common.OS_NAME a
910+
889911
#ifndef IS_WINDOWS
890912
-- Note: In the cases of "x.y." and "x.y.." we return no extension rather
891913
-- than ".y." or ".y.." as extensions. That is they considered to have no

0 commit comments

Comments
 (0)