module DatabaseDesign.Ampersand.Basics.Auxiliaries
where
import Data.List (nub,elemIndex)
import Data.Graph (stronglyConnComp, SCC(CyclicSCC))
import Data.Maybe (fromMaybe)
eqClass :: (a -> a -> Bool) -> [a] -> [[a]]
eqClass _ [] = []
eqClass f (x:xs) = (x:[e |e<-xs, f x e]) : eqClass f [e |e<-xs, not (f x e)]
eqCl :: Eq b => (a -> b) -> [a] -> [[a]]
eqCl _ [] = []
eqCl f (x:xs) = (x:[e |e<-xs, f x==f e]) : eqCl f [e |e<-xs, f x/=f e]
getCycles :: Eq a => [(a, [a])] -> [[a]]
getCycles edges =
let allVertices = nub . concat $ [ from : to | (from, to) <- edges ]
keyFor v = fromMaybe (error "FATAL") $ elemIndex v allVertices
graphEdges = [ (v, keyFor v , map keyFor vs) | (v, vs) <- edges ]
in [ vs | CyclicSCC vs <- stronglyConnComp graphEdges ]
combinations :: [[a]] -> [[a]]
combinations [] = [[]]
combinations (es:ess) = [ x:xs | x<-es, xs<-combinations ess]
commaEng :: String -> [String] -> String
commaEng str [a,b,c] = a++", "++b++", "++str++" "++c
commaEng str [a,b] = a++" "++str++" "++b
commaEng _ [a] = a
commaEng str (a:as) = a++", "++commaEng str as
commaEng _ [] = ""
commaNL :: String -> [String] -> String
commaNL str [a,b] = a++" "++str++" "++b
commaNL _ [a] = a
commaNL str (a:as) = a++", "++commaNL str as
commaNL _ [] = ""
fst3 :: (a,b,c)->a
snd3 :: (a,b,c)->b
thd3 :: (a,b,c)->c
fst3 (a,_,_) = a
snd3 (_,b,_) = b
thd3 (_,_,c) = c
class Flippable a where
flp :: a -> a