@@ -194,7 +194,7 @@ import Streamly.Internal.Data.Path
194194{- $setup
195195>>> :m
196196>>> :set -XQuasiQuotes
197- >>> import Data.Maybe (fromJust, isJust)
197+ >>> import Data.Maybe (fromJust, isNothing, isJust)
198198>>> import qualified Streamly.Data.Stream as Stream
199199
200200For APIs that have not been released yet.
@@ -675,46 +675,50 @@ unsafeJoinPaths = undefined
675675
676676#ifndef IS_WINDOWS
677677-- | If a path is rooted then separate the root and the remaining path,
678- -- otherwise root is returned as empty . If the path is rooted then the non-root
679- -- part is guaranteed to not start with a separator.
678+ -- otherwise return 'Nothing' . If the path is rooted then the non-root
679+ -- part is guaranteed to NOT start with a separator.
680680--
681681-- Some filepath package equivalent idioms:
682682--
683683-- >>> splitDrive = Path.splitRoot
684684-- >>> joinDrive = Path.unsafeAppend
685- -- >>> takeDrive = fst . Path.splitRoot
686- -- >>> dropDrive = snd . Path.splitRoot
685+ -- >>> takeDrive = fmap fst . Path.splitRoot
686+ -- >>> dropDrive x = Path.splitRoot x >>= snd
687+ -- >>> hasDrive = isJust . Path.splitRoot
688+ -- >>> isDrive = isNothing . dropDrive
687689--
688- -- >> hasDrive = not . null . takeDrive -- TODO
689- -- >> isDrive = null . dropDrive -- TODO
690- --
691- -- >>> toList (a,b) = (Path.toString a, Path.toString b)
692- -- >>> split = toList . Path.splitRoot . pack
690+ -- >>> toList (a,b) = (Path.toString a, fmap Path.toString b)
691+ -- >>> split = fmap toList . Path.splitRoot . pack
693692--
694693-- >>> split "/"
695- -- ("/","" )
694+ -- Just ("/",Nothing )
696695--
697696-- >>> split "."
698- -- (".","" )
697+ -- Just (".",Nothing )
699698--
700699-- >>> split "./"
701- -- ("./","" )
700+ -- Just ("./",Nothing )
702701--
703702-- >>> split "/home"
704- -- ("/","home")
703+ -- Just ("/",Just "home")
705704--
706705-- >>> split "//"
707- -- ("//","" )
706+ -- Just ("//",Nothing )
708707--
709708-- >>> split "./home"
710- -- ("./","home")
709+ -- Just ("./",Just "home")
711710--
712711-- >>> split "home"
713- -- ("","home")
712+ -- Nothing
714713--
715- splitRoot :: OS_PATH -> (OS_PATH , OS_PATH )
716- splitRoot (OS_PATH a) =
717- bimap OS_PATH OS_PATH $ Common. splitRoot Common. OS_NAME a
714+ splitRoot :: OS_PATH -> Maybe (OS_PATH , Maybe OS_PATH )
715+ splitRoot (OS_PATH x) =
716+ let (a,b) = Common. splitRoot Common. OS_NAME x
717+ in if Array. null a
718+ then Nothing
719+ else if Array. null b
720+ then Just (OS_PATH a, Nothing )
721+ else Just (OS_PATH a, Just (OS_PATH b))
718722
719723-- | Split the path components keeping separators between path components
720724-- attached to the dir part. Redundant separators are removed, only the first
0 commit comments