charon-0.1: Template
Safe HaskellSafe-Inferred
LanguageGHC2021

Charon.Utils

Description

Provides internal utility functions

Synopsis

FAM combinators

throwIfEx :: (MonadIORef m, MonadThrow m) => IORef (Maybe SomeException) -> m () Source #

Throws the exception if it exists in the ref.

whenM :: Monad m => m Bool -> m () -> m () Source #

When for monadic bool.

Text

matchesWildcards :: Text -> Text -> Bool Source #

matchesWildcards matchStr toMatch returns true if toMatch "matches" the matchStr, where unescaped asterisks in matchStr are interpreted as wildcards.

stripInfix :: Text -> Text -> Maybe (Text, Text) Source #

stripInfix text needle strips the _first_ occurrence of needle from the text.

ByteString

breakEqBS :: ByteString -> (ByteString, ByteString) Source #

Breaks a bytestring on the first '='. The '=' is removed from the second element.

Percent encoding

percentEncode :: ByteString -> ByteString Source #

Percent encoded a bytestring.

percentDecode :: ByteString -> ByteString Source #

Percent decodes a bytestring.

Optics

mergeAlt :: Alternative f => Lens' s (f a) -> Lens' t (f a) -> s -> t -> f a Source #

Merge two fields using the Alternative instance.

merge :: (a -> a -> a) -> Lens' s a -> Lens' t a -> s -> t -> a Source #

Merge two fields using the given function.

Bytes formatting

normalizedFormat :: Bytes B Natural -> Text Source #

Normalizes and formats the bytes.

Logs

logLevelStrings :: String Source #

String description of possible log levels parsed by readLogLevel.

PathSize

Misc

filterSeqM :: forall m a. Monad m => (a -> m Bool) -> Seq a -> m (Seq a) Source #

Filter a sequence monadically.

renderPretty :: Pretty a => a -> Text Source #

Renders via pretty instance.

setRefIfJust :: MonadIORef m => IORef (Maybe a) -> Maybe a -> m () Source #

Sets the ioref if the maybe is non-empty.

noBuffering :: (HasCallStack, MonadHandleWriter m) => m () Source #

Sets NoBuffering.