Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
nalchevanidze committed Jun 19, 2024
1 parent 8a7abdd commit 6aa8f6b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions hconf/src/HConf/Core/Bounds.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import HConf.Utils.Chalk (Color (Yellow), chalk)
import HConf.Utils.Class (Parse (..))
import HConf.Utils.Core (Name)
import HConf.Utils.Log (Log, field)
import HConf.Utils.Source (getHead, sepByAnd, unconsM)
import HConf.Utils.Source (removeHead, sepByAnd, unconsM)
import Relude hiding
( Undefined,
break,
Expand Down Expand Up @@ -73,7 +73,7 @@ instance Parse Bound where
parse txt = do
(char, str) <- unconsM "unsorted bound type" txt
res <- parseRestriction char
let (isStrict, value) = first (Just '=' ==) (getHead str)
let (isStrict, value) = removeHead '=' str
Bound res isStrict <$> parse value

newtype Bounds = Bounds [Bound]
Expand Down
12 changes: 8 additions & 4 deletions hconf/src/HConf/Utils/Source.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module HConf.Utils.Source
fromByteString,
breakOnSpace,
sepByAnd,
getHead,
removeHead,
unconsM,
)
where
Expand Down Expand Up @@ -54,12 +54,16 @@ breakOnSpace = trimBimap . break isSeparator
sepByAnd :: Text -> [Text]
sepByAnd = T.splitOn "&&" . T.filter (not . isSeparator)

getHead :: Text -> (Maybe Char, Text)
getHead txt = maybe (Nothing, txt) (first Just) (uncons txt)
removeHead :: Char -> Text -> (Bool, Text)
removeHead should txt = maybe (False, txt) has (uncons txt)
where
has (x, xs)
| x == should = (True, xs)
| otherwise = (False, txt)

unconsM :: (MonadFail m) => String -> Text -> m (Char, Text)
unconsM msg x =
maybe
(fail (msg <> "<>: " <> toString x))
pure
(uncons x)
(uncons x)

0 comments on commit 6aa8f6b

Please sign in to comment.