This repository has been archived by the owner on Jun 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from safareli/pathy
update pathy
- Loading branch information
Showing
5 changed files
with
42 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,58 @@ | ||
module SqlSquared.Path | ||
( AnyFilePath | ||
, AnyDirPath | ||
, parseAnyFilePath | ||
( parseAnyFilePath | ||
, printAnyFilePath | ||
, parseAnyDirPath | ||
, printAnyDirPath | ||
, genAnyFilePath | ||
, genAnyDirPath | ||
, module PathyTypeReexprts | ||
) where | ||
|
||
import Prelude | ||
import Data.Either as E | ||
import Data.NonEmpty ((:|)) | ||
import Data.Path.Pathy as Pt | ||
import Data.Path.Pathy.Gen as PtGen | ||
|
||
import Control.Monad.Gen as Gen | ||
import Control.Monad.Rec.Class (class MonadRec) | ||
import Data.Either as E | ||
import Data.NonEmpty ((:|)) | ||
import Pathy as Pt | ||
import Pathy (AnyDir, AnyFile) as PathyTypeReexprts | ||
import Pathy (AnyDir, AnyFile) | ||
import Pathy.Gen as PtGen | ||
import SqlSquared.Utils ((∘)) | ||
|
||
type AnyDirPath = E.Either (Pt.AbsDir Pt.Unsandboxed) (Pt.RelDir Pt.Unsandboxed) | ||
type AnyFilePath = E.Either (Pt.AbsFile Pt.Unsandboxed) (Pt.RelFile Pt.Unsandboxed) | ||
|
||
printAnyDirPath :: AnyDirPath -> String | ||
printAnyDirPath = E.either Pt.unsafePrintPath Pt.unsafePrintPath | ||
printAnyDirPath :: AnyDir -> String | ||
printAnyDirPath = E.either | ||
(Pt.sandboxAny >>> Pt.unsafePrintPath Pt.posixPrinter) | ||
(Pt.sandboxAny >>> Pt.unsafePrintPath Pt.posixPrinter) | ||
|
||
parseAnyDirPath :: forall m. Applicative m => (forall a. String -> m a) -> String -> m AnyDirPath | ||
parseAnyDirPath fail = Pt.parsePath | ||
parseAnyDirPath :: forall m. Applicative m => (forall a. String -> m a) -> String -> m AnyDir | ||
parseAnyDirPath fail = Pt.parsePath Pt.posixParser | ||
(pure ∘ E.Right) | ||
(pure ∘ E.Left) | ||
(const $ fail "Expected a directory path") | ||
(const $ fail "Expected a directory path") | ||
(fail "Expected valid path") | ||
|
||
printAnyFilePath :: AnyFilePath -> String | ||
printAnyFilePath = E.either Pt.unsafePrintPath Pt.unsafePrintPath | ||
printAnyFilePath :: AnyFile -> String | ||
printAnyFilePath = E.either | ||
(Pt.sandboxAny >>> Pt.unsafePrintPath Pt.posixPrinter) | ||
(Pt.sandboxAny >>> Pt.unsafePrintPath Pt.posixPrinter) | ||
|
||
parseAnyFilePath :: forall m. Applicative m => (forall a. String -> m a) -> String -> m AnyFilePath | ||
parseAnyFilePath fail = Pt.parsePath | ||
parseAnyFilePath :: forall m. Applicative m => (forall a. String -> m a) -> String -> m AnyFile | ||
parseAnyFilePath fail = Pt.parsePath Pt.posixParser | ||
(const $ fail "Expected a file path") | ||
(const $ fail "Expected a file path") | ||
(pure ∘ E.Right) | ||
(pure ∘ E.Left) | ||
(fail "Expected valid path") | ||
|
||
genAnyFilePath :: forall m. Gen.MonadGen m => MonadRec m => m AnyFilePath | ||
genAnyFilePath :: forall m. Gen.MonadGen m => MonadRec m => m AnyFile | ||
genAnyFilePath = Gen.oneOf | ||
$ (E.Left ∘ Pt.unsandbox <$> PtGen.genAbsFilePath) | ||
:| [E.Right ∘ Pt.unsandbox <$> PtGen.genRelFilePath] | ||
$ (E.Left <$> PtGen.genAbsFilePath) | ||
:| [E.Right <$> PtGen.genRelFilePath] | ||
|
||
genAnyDirPath :: forall m. Gen.MonadGen m => MonadRec m => m AnyDirPath | ||
genAnyDirPath :: forall m. Gen.MonadGen m => MonadRec m => m AnyDir | ||
genAnyDirPath = Gen.oneOf | ||
$ (E.Left ∘ Pt.unsandbox <$> PtGen.genAbsDirPath) | ||
:| [E.Right ∘ Pt.unsandbox <$> PtGen.genRelDirPath] | ||
$ (E.Left <$> PtGen.genAbsDirPath) | ||
:| [E.Right <$> PtGen.genRelDirPath] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters