{-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MagicHash #-}
module PossehlAnalyticsPrelude
(
Text,
ByteString,
Word8,
fmt,
textToString,
stringToText,
showToText,
textToBytesUtf8,
textToBytesUtf8Lazy,
bytesToTextUtf8,
bytesToTextUtf8Lazy,
bytesToTextUtf8Lenient,
bytesToTextUtf8LenientLazy,
bytesToTextUtf8Unsafe,
bytesToTextUtf8UnsafeLazy,
toStrict,
toLazy,
toStrictBytes,
toLazyBytes,
charToWordUnsafe,
putStrLn,
putStderrLn,
exitWithMessage,
todo,
HasField,
doAs,
(&),
(<&>),
(<|>),
foldMap1,
foldMap',
join,
when,
unless,
guard,
ExceptT (..),
runExceptT,
MonadThrow,
throwM,
MonadIO,
liftIO,
MonadReader,
asks,
Bifunctor,
first,
second,
bimap,
both,
foldMap,
fold,
foldl',
fromMaybe,
mapMaybe,
findMaybe,
Traversable,
for,
for_,
traverse,
traverse_,
traverseFold,
traverseFold1,
traverseFoldDefault,
MonadTrans,
lift,
Coercible,
coerce,
Proxy (Proxy),
Map,
annotate,
Validation (Success, Failure),
failure,
successes,
failures,
traverseValidate,
traverseValidateM,
traverseValidateM_,
eitherToValidation,
eitherToListValidation,
validationToEither,
These (This, That, These),
eitherToThese,
eitherToListThese,
validationToThese,
thenThese,
thenValidate,
NonEmpty ((:|)),
singleton,
nonEmpty,
nonEmptyDef,
toList,
toNonEmptyDefault,
maximum1,
minimum1,
Generic,
Semigroup,
sconcat,
Monoid,
mconcat,
ifTrue,
ifExists,
Void,
absurd,
Identity (Identity, runIdentity),
Natural,
intToNatural,
Contravariant,
contramap,
(>$<),
(>&<),
Profunctor,
dimap,
lmap,
rmap,
Semigroupoid,
Category,
(>>>),
(&>>),
Any,
inverseFunction,
inverseMap,
enumerateAll,
mapFromListOn,
mapFromListOnMerge,
HasCallStack,
module Data.Error,
)
where
import Control.Applicative ((<|>))
import Control.Category (Category, (>>>))
import Control.Monad (guard, join, unless, when)
import Control.Monad.Catch (MonadThrow (throwM))
import Control.Monad.Except
( ExceptT (..),
runExceptT,
)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Identity (Identity (Identity))
import Control.Monad.Reader (MonadReader, asks)
import Control.Monad.Trans (MonadTrans (lift))
import Data.Bifunctor (Bifunctor, bimap, first, second)
import Data.ByteString
( ByteString,
)
import Data.ByteString.Lazy qualified
import Data.Char qualified
import Data.Coerce (Coercible, coerce)
import Data.Data (Proxy (Proxy))
import Data.Error
import Data.Foldable (Foldable (foldMap', toList), fold, foldl', for_, sequenceA_, traverse_)
import Data.Foldable qualified as Foldable
import Data.Function ((&))
import Data.Functor ((<&>))
import Data.Functor.Contravariant (Contravariant (contramap), (>$<))
import Data.Functor.Identity (Identity (runIdentity))
import Data.List.NonEmpty (NonEmpty ((:|)), nonEmpty)
import Data.Map.Strict
( Map,
)
import Data.Map.Strict qualified as Map
import Data.Maybe (fromMaybe, mapMaybe)
import Data.Maybe qualified as Maybe
import Data.Profunctor (Profunctor, dimap, lmap, rmap)
import Data.Semigroup (Max (Max, getMax), Min (Min, getMin), sconcat)
import Data.Semigroup.Foldable (Foldable1 (fold1), foldMap1)
import Data.Semigroup.Traversable (Traversable1)
import Data.Semigroupoid (Semigroupoid (o))
import Data.Text
( Text,
)
import Data.Text qualified
import Data.Text.Encoding qualified
import Data.Text.Encoding.Error qualified
import Data.Text.Lazy qualified
import Data.Text.Lazy.Encoding qualified
import Data.These (These (That, These, This))
import Data.Traversable (for)
import Data.Void (Void, absurd)
import Data.Word (Word8)
import GHC.Exception (errorCallWithCallStackException)
import GHC.Exts (Any, RuntimeRep, TYPE, raise#)
import GHC.Generics (Generic)
import GHC.Natural (Natural)
import GHC.Records (HasField)
import GHC.Stack (HasCallStack)
import PyF (fmt)
import System.Exit qualified
import System.IO qualified
import Validation
( Validation (Failure, Success),
eitherToValidation,
failure,
failures,
successes,
validationToEither,
)
doAs :: forall m a. m a -> m a
doAs :: forall {k} (m :: k -> Type) (a :: k). m a -> m a
doAs = forall a. a -> a
id
(>&<) :: Contravariant f => f b -> (a -> b) -> f a
>&< :: forall (f :: Type -> Type) b a.
Contravariant f =>
f b -> (a -> b) -> f a
(>&<) = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (f :: Type -> Type) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap
infixl 5 >&<
(&>>) :: Semigroupoid s => s a b -> s b c -> s a c
&>> :: forall {k} (s :: k -> k -> Type) (a :: k) (b :: k) (c :: k).
Semigroupoid s =>
s a b -> s b c -> s a c
(&>>) = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall {k} (c :: k -> k -> Type) (j :: k) (k1 :: k) (i :: k).
Semigroupoid c =>
c j k1 -> c i j -> c i k1
Data.Semigroupoid.o
infixr 1 &>>
textToBytesUtf8 :: Text -> ByteString
textToBytesUtf8 :: Text -> ByteString
textToBytesUtf8 = Text -> ByteString
Data.Text.Encoding.encodeUtf8
textToBytesUtf8Lazy :: Data.Text.Lazy.Text -> Data.ByteString.Lazy.ByteString
textToBytesUtf8Lazy :: Text -> ByteString
textToBytesUtf8Lazy = Text -> ByteString
Data.Text.Lazy.Encoding.encodeUtf8
bytesToTextUtf8 :: ByteString -> Either Error Text
bytesToTextUtf8 :: ByteString -> Either Error Text
bytesToTextUtf8 = forall (p :: Type -> Type -> Type) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first forall exc. Exception exc => exc -> Error
exceptionToError forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either UnicodeException Text
Data.Text.Encoding.decodeUtf8'
bytesToTextUtf8Lazy :: Data.ByteString.Lazy.ByteString -> Either Error Data.Text.Lazy.Text
bytesToTextUtf8Lazy :: ByteString -> Either Error Text
bytesToTextUtf8Lazy = forall (p :: Type -> Type -> Type) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first forall exc. Exception exc => exc -> Error
exceptionToError forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either UnicodeException Text
Data.Text.Lazy.Encoding.decodeUtf8'
bytesToTextUtf8Unsafe :: ByteString -> Text
bytesToTextUtf8Unsafe :: ByteString -> Text
bytesToTextUtf8Unsafe = ByteString -> Text
Data.Text.Encoding.decodeUtf8
bytesToTextUtf8UnsafeLazy :: Data.ByteString.Lazy.ByteString -> Data.Text.Lazy.Text
bytesToTextUtf8UnsafeLazy :: ByteString -> Text
bytesToTextUtf8UnsafeLazy = ByteString -> Text
Data.Text.Lazy.Encoding.decodeUtf8
bytesToTextUtf8Lenient :: Data.ByteString.ByteString -> Data.Text.Text
bytesToTextUtf8Lenient :: ByteString -> Text
bytesToTextUtf8Lenient =
OnDecodeError -> ByteString -> Text
Data.Text.Encoding.decodeUtf8With OnDecodeError
Data.Text.Encoding.Error.lenientDecode
bytesToTextUtf8LenientLazy :: Data.ByteString.Lazy.ByteString -> Data.Text.Lazy.Text
bytesToTextUtf8LenientLazy :: ByteString -> Text
bytesToTextUtf8LenientLazy =
OnDecodeError -> ByteString -> Text
Data.Text.Lazy.Encoding.decodeUtf8With OnDecodeError
Data.Text.Encoding.Error.lenientDecode
toStrict :: Data.Text.Lazy.Text -> Text
toStrict :: Text -> Text
toStrict = Text -> Text
Data.Text.Lazy.toStrict
toLazy :: Text -> Data.Text.Lazy.Text
toLazy :: Text -> Text
toLazy = Text -> Text
Data.Text.Lazy.fromStrict
toStrictBytes :: Data.ByteString.Lazy.ByteString -> ByteString
toStrictBytes :: ByteString -> ByteString
toStrictBytes = ByteString -> ByteString
Data.ByteString.Lazy.toStrict
toLazyBytes :: ByteString -> Data.ByteString.Lazy.ByteString
toLazyBytes :: ByteString -> ByteString
toLazyBytes = ByteString -> ByteString
Data.ByteString.Lazy.fromStrict
textToString :: Text -> String
textToString :: Text -> String
textToString = Text -> String
Data.Text.unpack
stringToText :: String -> Text
stringToText :: String -> Text
stringToText = String -> Text
Data.Text.pack
showToText :: (Show a) => a -> Text
showToText :: forall a. Show a => a -> Text
showToText = String -> Text
stringToText forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
charToWordUnsafe :: Char -> Word8
charToWordUnsafe :: Char -> Word8
charToWordUnsafe = forall a b. (Integral a, Num b) => a -> b
fromIntegral forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Int
Data.Char.ord
{-# INLINE charToWordUnsafe #-}
singleton :: a -> NonEmpty a
singleton :: forall a. a -> NonEmpty a
singleton a
a = a
a forall a. a -> [a] -> NonEmpty a
:| []
nonEmptyDef :: a -> [a] -> NonEmpty a
nonEmptyDef :: forall a. a -> [a] -> NonEmpty a
nonEmptyDef a
def [a]
xs =
[a]
xs forall a b. a -> (a -> b) -> b
& forall a. [a] -> Maybe (NonEmpty a)
nonEmpty forall a b. a -> (a -> b) -> b
& \case
Maybe (NonEmpty a)
Nothing -> a
def forall a. a -> [a] -> NonEmpty a
:| []
Just NonEmpty a
ne -> NonEmpty a
ne
toNonEmptyDefault :: a -> [a] -> NonEmpty a
toNonEmptyDefault :: forall a. a -> [a] -> NonEmpty a
toNonEmptyDefault a
def [a]
xs = case [a]
xs of
[] -> a
def forall a. a -> [a] -> NonEmpty a
:| []
(a
x : [a]
xs') -> a
x forall a. a -> [a] -> NonEmpty a
:| [a]
xs'
maximum1 :: (Foldable1 f, Ord a) => f a -> a
maximum1 :: forall (f :: Type -> Type) a. (Foldable1 f, Ord a) => f a -> a
maximum1 f a
xs = f a
xs forall a b. a -> (a -> b) -> b
& forall (t :: Type -> Type) m a.
(Foldable1 t, Semigroup m) =>
(a -> m) -> t a -> m
foldMap1 forall a. a -> Max a
Max forall a b. a -> (a -> b) -> b
& forall a. Max a -> a
getMax
minimum1 :: (Foldable1 f, Ord a) => f a -> a
minimum1 :: forall (f :: Type -> Type) a. (Foldable1 f, Ord a) => f a -> a
minimum1 f a
xs = f a
xs forall a b. a -> (a -> b) -> b
& forall (t :: Type -> Type) m a.
(Foldable1 t, Semigroup m) =>
(a -> m) -> t a -> m
foldMap1 forall a. a -> Min a
Min forall a b. a -> (a -> b) -> b
& forall a. Min a -> a
getMin
annotate :: err -> Maybe a -> Either err a
annotate :: forall err a. err -> Maybe a -> Either err a
annotate err
err = \case
Maybe a
Nothing -> forall a b. a -> Either a b
Left err
err
Just a
a -> forall a b. b -> Either a b
Right a
a
both :: Bifunctor bi => (a -> b) -> bi a a -> bi b b
both :: forall (bi :: Type -> Type -> Type) a b.
Bifunctor bi =>
(a -> b) -> bi a a -> bi b b
both a -> b
f = forall (p :: Type -> Type -> Type) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap a -> b
f a -> b
f
findMaybe :: Foldable t => (a -> Maybe b) -> t a -> Maybe b
findMaybe :: forall (t :: Type -> Type) a b.
Foldable t =>
(a -> Maybe b) -> t a -> Maybe b
findMaybe a -> Maybe b
mPred t a
list =
let pred' :: a -> Bool
pred' a
x = forall a. Maybe a -> Bool
Maybe.isJust forall a b. (a -> b) -> a -> b
$ a -> Maybe b
mPred a
x
in case forall (t :: Type -> Type) a.
Foldable t =>
(a -> Bool) -> t a -> Maybe a
Foldable.find a -> Bool
pred' t a
list of
Just a
a -> a -> Maybe b
mPred a
a
Maybe a
Nothing -> forall a. Maybe a
Nothing
traverseValidate :: forall t a err b. Traversable t => (a -> Either err b) -> t a -> Either (NonEmpty err) (t b)
traverseValidate :: forall (t :: Type -> Type) a err b.
Traversable t =>
(a -> Either err b) -> t a -> Either (NonEmpty err) (t b)
traverseValidate a -> Either err b
f t a
as =
t a
as
forall a b. a -> (a -> b) -> b
& forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse @t @(Validation _) (forall a c. Either a c -> Validation (NonEmpty a) c
eitherToListValidation forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Either err b
f)
forall a b. a -> (a -> b) -> b
& forall e a. Validation e a -> Either e a
validationToEither
traverseValidateM :: forall t m a err b. (Traversable t, Applicative m) => (a -> m (Either err b)) -> t a -> m (Either (NonEmpty err) (t b))
traverseValidateM :: forall (t :: Type -> Type) (m :: Type -> Type) a err b.
(Traversable t, Applicative m) =>
(a -> m (Either err b)) -> t a -> m (Either (NonEmpty err) (t b))
traverseValidateM a -> m (Either err b)
f t a
as =
t a
as
forall a b. a -> (a -> b) -> b
& forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse @t @m (\a
a -> a
a forall a b. a -> (a -> b) -> b
& a -> m (Either err b)
f forall (f :: Type -> Type) a b. Functor f => f a -> (a -> b) -> f b
<&> forall a c. Either a c -> Validation (NonEmpty a) c
eitherToListValidation)
forall (f :: Type -> Type) a b. Functor f => f a -> (a -> b) -> f b
<&> forall (t :: Type -> Type) (f :: Type -> Type) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA @t @(Validation _)
forall (f :: Type -> Type) a b. Functor f => f a -> (a -> b) -> f b
<&> forall e a. Validation e a -> Either e a
validationToEither
traverseValidateM_ :: forall t m a err. (Traversable t, Applicative m) => (a -> m (Either err ())) -> t a -> m (Either (NonEmpty err) ())
traverseValidateM_ :: forall (t :: Type -> Type) (m :: Type -> Type) a err.
(Traversable t, Applicative m) =>
(a -> m (Either err ())) -> t a -> m (Either (NonEmpty err) ())
traverseValidateM_ a -> m (Either err ())
f t a
as =
t a
as
forall a b. a -> (a -> b) -> b
& forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse @t @m (\a
a -> a
a forall a b. a -> (a -> b) -> b
& a -> m (Either err ())
f forall (f :: Type -> Type) a b. Functor f => f a -> (a -> b) -> f b
<&> forall a c. Either a c -> Validation (NonEmpty a) c
eitherToListValidation)
forall (f :: Type -> Type) a b. Functor f => f a -> (a -> b) -> f b
<&> forall (t :: Type -> Type) (f :: Type -> Type) a.
(Foldable t, Applicative f) =>
t (f a) -> f ()
sequenceA_ @t @(Validation _)
forall (f :: Type -> Type) a b. Functor f => f a -> (a -> b) -> f b
<&> forall e a. Validation e a -> Either e a
validationToEither
eitherToListValidation :: Either a c -> Validation (NonEmpty a) c
eitherToListValidation :: forall a c. Either a c -> Validation (NonEmpty a) c
eitherToListValidation = forall (p :: Type -> Type -> Type) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first forall a. a -> NonEmpty a
singleton forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e a. Either e a -> Validation e a
eitherToValidation
eitherToThese :: Either err a -> These err a
eitherToThese :: forall err a. Either err a -> These err a
eitherToThese (Left err
err) = forall a b. a -> These a b
This err
err
eitherToThese (Right a
a) = forall a b. b -> These a b
That a
a
eitherToListThese :: Either err a -> These (NonEmpty err) a
eitherToListThese :: forall err a. Either err a -> These (NonEmpty err) a
eitherToListThese (Left err
e) = forall a b. a -> These a b
This (forall a. a -> NonEmpty a
singleton err
e)
eitherToListThese (Right a
a) = forall a b. b -> These a b
That a
a
validationToThese :: Validation err a -> These err a
validationToThese :: forall err a. Validation err a -> These err a
validationToThese (Failure err
err) = forall a b. a -> These a b
This err
err
validationToThese (Success a
a) = forall a b. b -> These a b
That a
a
thenThese ::
(Monad m, Semigroup err) =>
(a -> m (These err b)) ->
m (These err a) ->
m (These err b)
thenThese :: forall (m :: Type -> Type) err a b.
(Monad m, Semigroup err) =>
(a -> m (These err b)) -> m (These err a) -> m (These err b)
thenThese a -> m (These err b)
f m (These err a)
x = do
These err a
th <- m (These err a)
x
forall (m :: Type -> Type) a. Monad m => m (m a) -> m a
join forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse a -> m (These err b)
f These err a
th
thenValidate ::
(Monad m) =>
(a -> m (Validation err b)) ->
m (Validation err a) ->
m (Validation err b)
thenValidate :: forall (m :: Type -> Type) a err b.
Monad m =>
(a -> m (Validation err b))
-> m (Validation err a) -> m (Validation err b)
thenValidate a -> m (Validation err b)
f m (Validation err a)
x =
forall e a. Either e a -> Validation e a
eitherToValidation forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> do
Either err a
x' <- forall e a. Validation e a -> Either e a
validationToEither forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> m (Validation err a)
x
case Either err a
x' of
Left err
err -> forall (f :: Type -> Type) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a b. a -> Either a b
Left err
err
Right a
a -> forall e a. Validation e a -> Either e a
validationToEither forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> m (Validation err b)
f a
a
putStderrLn :: Text -> IO ()
putStderrLn :: Text -> IO ()
putStderrLn Text
msg =
Handle -> String -> IO ()
System.IO.hPutStrLn Handle
System.IO.stderr forall a b. (a -> b) -> a -> b
$ Text -> String
textToString Text
msg
exitWithMessage :: Text -> IO a
exitWithMessage :: forall a. Text -> IO a
exitWithMessage Text
msg = do
Text -> IO ()
putStderrLn Text
msg
forall a. ExitCode -> IO a
System.Exit.exitWith forall a b. (a -> b) -> a -> b
$ Int -> ExitCode
System.Exit.ExitFailure (-Int
1)
traverseFold :: (Applicative ap, Traversable t, Monoid m) => (a -> ap m) -> t a -> ap m
traverseFold :: forall (ap :: Type -> Type) (t :: Type -> Type) m a.
(Applicative ap, Traversable t, Monoid m) =>
(a -> ap m) -> t a -> ap m
traverseFold a -> ap m
f t a
xs =
forall (t :: Type -> Type) m. (Foldable t, Monoid m) => t m -> m
fold forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse a -> ap m
f t a
xs
{-# INLINE traverseFold #-}
traverseFoldDefault :: (Applicative ap, Traversable t, Semigroup m) => m -> (a -> ap m) -> t a -> ap m
traverseFoldDefault :: forall (ap :: Type -> Type) (t :: Type -> Type) m a.
(Applicative ap, Traversable t, Semigroup m) =>
m -> (a -> ap m) -> t a -> ap m
traverseFoldDefault m
def a -> ap m
f t a
xs = m -> t m -> m
foldDef m
def forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse a -> ap m
f t a
xs
where
foldDef :: m -> t m -> m
foldDef = forall (t :: Type -> Type) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall a. Semigroup a => a -> a -> a
(<>)
{-# INLINE traverseFoldDefault #-}
traverseFold1 :: (Applicative ap, Traversable1 t, Semigroup s) => (a -> ap s) -> t a -> ap s
traverseFold1 :: forall (ap :: Type -> Type) (t :: Type -> Type) s a.
(Applicative ap, Traversable1 t, Semigroup s) =>
(a -> ap s) -> t a -> ap s
traverseFold1 a -> ap s
f t a
xs = forall (t :: Type -> Type) m.
(Foldable1 t, Semigroup m) =>
t m -> m
fold1 forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse a -> ap s
f t a
xs
{-# INLINE traverseFold1 #-}
{-# WARNING todo "'todo' (undefined code) remains in code" #-}
todo :: forall (r :: RuntimeRep). forall (a :: TYPE r). HasCallStack => a
todo :: forall a. HasCallStack => a
todo = forall b a. b -> a
raise# (String -> CallStack -> SomeException
errorCallWithCallStackException String
"This code was not yet implemented: TODO" HasCallStack
?callStack)
intToNatural :: Integral a => a -> Maybe Natural
intToNatural :: forall a. Integral a => a -> Maybe Natural
intToNatural a
i =
if a
i forall a. Ord a => a -> a -> Bool
< a
0
then forall a. Maybe a
Nothing
else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a b. (Integral a, Num b) => a -> b
fromIntegral a
i
inverseFunction ::
forall a k.
(Bounded a, Enum a, Ord k) =>
(a -> k) ->
(k -> Maybe a)
inverseFunction :: forall a k. (Bounded a, Enum a, Ord k) => (a -> k) -> k -> Maybe a
inverseFunction a -> k
f k
k = forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup k
k forall a b. (a -> b) -> a -> b
$ forall a k. (Bounded a, Enum a, Ord k) => (a -> k) -> Map k a
inverseMap a -> k
f
inverseMap :: forall a k. (Bounded a, Enum a, Ord k) => (a -> k) -> Map k a
inverseMap :: forall a k. (Bounded a, Enum a, Ord k) => (a -> k) -> Map k a
inverseMap a -> k
f = forall a. (Enum a, Bounded a) => [a]
enumerateAll forall (f :: Type -> Type) a b. Functor f => f a -> (a -> b) -> f b
<&> (\a
a -> (a -> k
f a
a, a
a)) forall a b. a -> (a -> b) -> b
& forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
enumerateAll :: (Enum a, Bounded a) => [a]
enumerateAll :: forall a. (Enum a, Bounded a) => [a]
enumerateAll = [forall a. Bounded a => a
minBound .. forall a. Bounded a => a
maxBound]
mapFromListOn :: Ord key => (a -> key) -> [a] -> Map key a
mapFromListOn :: forall key a. Ord key => (a -> key) -> [a] -> Map key a
mapFromListOn a -> key
f [a]
xs = [a]
xs forall (f :: Type -> Type) a b. Functor f => f a -> (a -> b) -> f b
<&> (\a
x -> (a -> key
f a
x, a
x)) forall a b. a -> (a -> b) -> b
& forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
mapFromListOnMerge :: (Ord key, Semigroup s) => (a -> (key, s)) -> [a] -> Map key s
mapFromListOnMerge :: forall key s a.
(Ord key, Semigroup s) =>
(a -> (key, s)) -> [a] -> Map key s
mapFromListOnMerge a -> (key, s)
f [a]
xs =
[a]
xs
forall (f :: Type -> Type) a b. Functor f => f a -> (a -> b) -> f b
<&> (\a
x -> a -> (key, s)
f a
x)
forall a b. a -> (a -> b) -> b
& forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
Map.fromListWith
(forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Semigroup a => a -> a -> a
(<>))
ifTrue :: Monoid m => Bool -> m -> m
ifTrue :: forall m. Monoid m => Bool -> m -> m
ifTrue Bool
pred' m
m = if Bool
pred' then m
m else forall a. Monoid a => a
mempty
ifExists :: Monoid m => Maybe m -> m
ifExists :: forall m. Monoid m => Maybe m -> m
ifExists = forall (t :: Type -> Type) m. (Foldable t, Monoid m) => t m -> m
fold