{- |
Module      : Servant.API.Routes.Path
Copyright   : (c) Frederick Pringle, 2024
License     : BSD-3-Clause
Maintainer  : freddyjepringle@gmail.com

Simple representation of URL paths.
-}
module Servant.API.Routes.Path
  ( Path
  , prependPathPart
  , renderPath
  , rootPath
  )
where

import qualified Data.Text as T
import "this" Servant.API.Routes.Internal.Path

-- | @"/"@
rootPath :: Path
rootPath :: Path
rootPath = [Text] -> Path
Path []

-- | Equivalent to @(:)@.
prependPathPart :: T.Text -> Path -> Path
prependPathPart :: Text -> Path -> Path
prependPathPart Text
part (Path [Text]
parts) =
  [Text] -> Path
Path ([Text]
splitParts forall a. Semigroup a => a -> a -> a
<> [Text]
parts)
  where
    splitParts :: [Text]
splitParts = forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Bool
T.null) forall a b. (a -> b) -> a -> b
$ Text -> Text -> [Text]
T.splitOn Text
pathSeparator Text
part