module Utils.Drasil.Lists where
import Data.List
atLeast2 :: [a] -> Bool
atLeast2 :: forall a. [a] -> Bool
atLeast2 (a
_:a
_:[a]
_) = Bool
True
atLeast2 [a]
_ = Bool
False
replaceAll :: Eq a => [a] -> a -> [a] -> [a]
replaceAll :: forall a. Eq a => [a] -> a -> [a] -> [a]
replaceAll [a]
bad a
repl (a
c:[a]
cs) | a
c forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [a]
bad = a
repl forall a. a -> [a] -> [a]
: forall a. Eq a => [a] -> a -> [a] -> [a]
replaceAll [a]
bad a
repl [a]
cs
| Bool
otherwise = a
c forall a. a -> [a] -> [a]
: forall a. Eq a => [a] -> a -> [a] -> [a]
replaceAll [a]
bad a
repl [a]
cs
replaceAll [a]
_ a
_ [a]
it = [a]
it
subsetOf :: Eq a => [a] -> [a] -> Bool
[a]
xs subsetOf :: forall a. Eq a => [a] -> [a] -> Bool
`subsetOf` [a]
ys = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [a]
ys) [a]
xs
nubSort :: Ord a => [a] -> [a]
nubSort :: forall a. Ord a => [a] -> [a]
nubSort = forall a. Eq a => [a] -> [a]
nub forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Ord a => [a] -> [a]
sort
weave :: [[a]] -> [a]
weave :: forall a. [[a]] -> [a]
weave = forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [[a]] -> [[a]]
transpose
foldle :: (a -> a -> a) -> (a -> a -> a) -> a -> [a] -> a
foldle :: forall a. (a -> a -> a) -> (a -> a -> a) -> a -> [a] -> a
foldle a -> a -> a
_ a -> a -> a
_ a
z [] = a
z
foldle a -> a -> a
_ a -> a -> a
g a
z [a
x] = a -> a -> a
g a
z a
x
foldle a -> a -> a
f a -> a -> a
g a
z [a
x,a
y] = a -> a -> a
g (a -> a -> a
f a
z a
x) a
y
foldle a -> a -> a
f a -> a -> a
g a
z (a
x:[a]
xs) = forall a. (a -> a -> a) -> (a -> a -> a) -> a -> [a] -> a
foldle a -> a -> a
f a -> a -> a
g (a -> a -> a
f a
z a
x) [a]
xs
foldle1 :: (a -> a -> a) -> (a -> a -> a) -> [a] -> a
foldle1 :: forall a. (a -> a -> a) -> (a -> a -> a) -> [a] -> a
foldle1 a -> a -> a
_ a -> a -> a
_ [] = forall a. HasCallStack => [Char] -> a
error [Char]
"foldle1 cannot be used with empty list"
foldle1 a -> a -> a
_ a -> a -> a
_ [a
x] = a
x
foldle1 a -> a -> a
_ a -> a -> a
g [a
x,a
y] = a -> a -> a
g a
x a
y
foldle1 a -> a -> a
f a -> a -> a
g (a
x:a
y:[a]
xs) = forall a. (a -> a -> a) -> (a -> a -> a) -> a -> [a] -> a
foldle a -> a -> a
f a -> a -> a
g (a -> a -> a
f a
x a
y) [a]
xs
toColumn :: [a] -> [[a]]
toColumn :: forall a. [a] -> [[a]]
toColumn = forall a b. (a -> b) -> [a] -> [b]
map (forall a. a -> [a] -> [a]
: [])