{-|
Module      : Polysemy.Path
License     : MIT
Maintainer  : dan.firth@homotopic.tech
Stability   : experimental

Polysemy versions of functions in the path library.
-}
{-# LANGUAGE DataKinds           #-}
{-# LANGUAGE GADTs               #-}
{-# LANGUAGE PolyKinds           #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -fplugin=Polysemy.Plugin #-}

module Polysemy.Path (
  Path
, Rel
, Abs
, File
, Dir
, PathException
, parseRelFile
, parseAbsFile
, parseRelDir
, parseAbsDir
, stripProperPrefix
) where

import qualified Path
import Path (Path, Rel, Abs, File, Dir, PathException)
import Polysemy
import Polysemy.Error
import Polysemy.Extra

-- | Polysemy version of `Path.parseRelFile`.
--
-- @since 0.1.0.0
parseRelFile :: Members '[Error PathException] r
             => FilePath
             -> Sem r (Path Rel File)
parseRelFile :: FilePath -> Sem r (Path Rel File)
parseRelFile FilePath
x = (forall (m :: * -> *). MonadThrow m => m (Path Rel File))
-> Sem r (Path Rel File)
forall e (r :: [(* -> *) -> * -> *]) a.
(Exception e, Members '[Error e] r) =>
(forall (m :: * -> *). MonadThrow m => m a) -> Sem r a
irrefutableAbsorbThrow (FilePath -> m (Path Rel File)
forall (m :: * -> *). MonadThrow m => FilePath -> m (Path Rel File)
Path.parseRelFile FilePath
x)

-- | Polysemy version of `Path.parseAbsFile`.
--
-- @since 0.1.0.0
parseAbsFile :: Members '[Error PathException] r
             => FilePath
             -> Sem r (Path Abs File)
parseAbsFile :: FilePath -> Sem r (Path Abs File)
parseAbsFile FilePath
x = (forall (m :: * -> *). MonadThrow m => m (Path Abs File))
-> Sem r (Path Abs File)
forall e (r :: [(* -> *) -> * -> *]) a.
(Exception e, Members '[Error e] r) =>
(forall (m :: * -> *). MonadThrow m => m a) -> Sem r a
irrefutableAbsorbThrow (FilePath -> m (Path Abs File)
forall (m :: * -> *). MonadThrow m => FilePath -> m (Path Abs File)
Path.parseAbsFile FilePath
x)

-- | Polysemy version of `Path.parseRelDir`.
--
-- @since 0.1.0.0
parseRelDir :: Members '[Error PathException] r
            => FilePath
            -> Sem r (Path Rel Dir)
parseRelDir :: FilePath -> Sem r (Path Rel Dir)
parseRelDir FilePath
x = (forall (m :: * -> *). MonadThrow m => m (Path Rel Dir))
-> Sem r (Path Rel Dir)
forall e (r :: [(* -> *) -> * -> *]) a.
(Exception e, Members '[Error e] r) =>
(forall (m :: * -> *). MonadThrow m => m a) -> Sem r a
irrefutableAbsorbThrow (FilePath -> m (Path Rel Dir)
forall (m :: * -> *). MonadThrow m => FilePath -> m (Path Rel Dir)
Path.parseRelDir FilePath
x)

-- | Polysemy version of `Path.parseAbsDir`.
--
-- @since 0.1.0.0
parseAbsDir :: Members '[Error PathException] r
            => FilePath
            -> Sem r (Path Abs Dir)
parseAbsDir :: FilePath -> Sem r (Path Abs Dir)
parseAbsDir FilePath
x = (forall (m :: * -> *). MonadThrow m => m (Path Abs Dir))
-> Sem r (Path Abs Dir)
forall e (r :: [(* -> *) -> * -> *]) a.
(Exception e, Members '[Error e] r) =>
(forall (m :: * -> *). MonadThrow m => m a) -> Sem r a
irrefutableAbsorbThrow (FilePath -> m (Path Abs Dir)
forall (m :: * -> *). MonadThrow m => FilePath -> m (Path Abs Dir)
Path.parseAbsDir FilePath
x)

-- | Polysemy version of `Path.stripProperPrefix`.
--
-- @since 0.1.0.0
stripProperPrefix :: Members '[Error PathException] r
                  => Path b Dir
                  -> Path b t
                  -> Sem r (Path Rel t)
stripProperPrefix :: Path b Dir -> Path b t -> Sem r (Path Rel t)
stripProperPrefix Path b Dir
x Path b t
y = (forall (m :: * -> *). MonadThrow m => m (Path Rel t))
-> Sem r (Path Rel t)
forall e (r :: [(* -> *) -> * -> *]) a.
(Exception e, Members '[Error e] r) =>
(forall (m :: * -> *). MonadThrow m => m a) -> Sem r a
irrefutableAbsorbThrow (Path b Dir -> Path b t -> m (Path Rel t)
forall (m :: * -> *) b t.
MonadThrow m =>
Path b Dir -> Path b t -> m (Path Rel t)
Path.stripProperPrefix Path b Dir
x Path b t
y)