module Polysemy.Plugin.Fundep.Utils where
import Control.Applicative
import Data.Bifunctor
import Data.List
singleListToJust :: [a] -> Maybe a
singleListToJust :: forall a. [a] -> Maybe a
singleListToJust [a
a] = forall a. a -> Maybe a
Just a
a
singleListToJust [a]
_ = forall a. Maybe a
Nothing
whenA
:: (Monad m, Alternative z)
=> Bool
-> m a
-> m (z a)
whenA :: forall (m :: * -> *) (z :: * -> *) a.
(Monad m, Alternative z) =>
Bool -> m a -> m (z a)
whenA Bool
False m a
_ = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall (f :: * -> *) a. Alternative f => f a
empty
whenA Bool
True m a
ma = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a
ma
countLength :: Eq a => [a] -> [(a, Int)]
countLength :: forall a. Eq a => [a] -> [(a, Int)]
countLength [a]
as =
let grouped :: [[a]]
grouped = forall a. Eq a => [a] -> [[a]]
group [a]
as
in forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (forall a b c. ((a, b) -> c) -> a -> b -> c
curry forall a b. (a -> b) -> a -> b
$ forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap forall a. [a] -> a
head forall (t :: * -> *) a. Foldable t => t a -> Int
length) [[a]]
grouped [[a]]
grouped