Safe Haskell | None |
---|---|
Language | Haskell2010 |
Miscellaneous functions/recipes
Synopsis
- pairs :: [a] -> [(a, a)]
- fArray :: (IArray a e, Ix i) => (i, i) -> (i -> e) -> a i e
- chunksOf :: Int -> [a] -> [[a]]
- replicateL :: Int -> [a] -> [a]
- unique :: Eq a => [a] -> [a]
- foldExclusive :: (b -> a -> b) -> b -> [a] -> [b]
- modifyArray :: (MArray a e m, Ix i) => a i e -> i -> (e -> e) -> m ()
- modifyArray' :: (MArray a e m, Ix i) => a i e -> i -> (e -> e) -> m ()
- ifoldr :: Foldable f => (Int -> a -> b -> b) -> b -> f a -> b
- ifoldl' :: Foldable f => (b -> Int -> a -> b) -> b -> f a -> b
- foldMComp :: Monad m => (b -> a -> b) -> (c -> m a) -> b -> c -> m b
- farthest :: (a -> Maybe a) -> a -> a
- foldTree' :: (a -> b -> c) -> (c -> b -> b) -> b -> Tree a -> c
- class Semigroup a => Commutative a
- class Monoid a => Group a where
- invert :: a -> a
- class Semigroup a => Idempotent a
- class (Monoid u, Monoid a) => Action u a where
- act :: a -> u -> a
- bitLength :: FiniteBits b => b -> Int
- unsafeBit :: (Bits a, Num a) => Int -> a
- odds :: [a] -> [a]
- evens :: [a] -> [a]
- orM :: Monad m => m Bool -> m Bool -> m Bool
- andM :: Monad m => m Bool -> m Bool -> m Bool
- anyM :: (Monad m, Foldable f) => (a -> m Bool) -> f a -> m Bool
- allM :: (Monad m, Foldable f) => (a -> m Bool) -> f a -> m Bool
- minimumByMaybe :: Foldable f => (a -> a -> Ordering) -> f a -> Maybe a
- maximumByMaybe :: Foldable f => (a -> a -> Ordering) -> f a -> Maybe a
Documentation
fArray :: (IArray a e, Ix i) => (i, i) -> (i -> e) -> a i e Source #
Generates an Array from bounds and a function. O(n) assuming f takes O(1).
replicateL :: Int -> [a] -> [a] Source #
Replicates a list n times. O(nm) where m is the length of the list.
foldExclusive :: (b -> a -> b) -> b -> [a] -> [b] Source #
Folds strictly such that the ith element of the output list contains the fold of all elements in the
input list except for the ith element. The fold function f must be commutative, in the sense that
(b f
a1) f
a2 = (b f
a2) f
a1
f is called O(n log n) times.
modifyArray :: (MArray a e m, Ix i) => a i e -> i -> (e -> e) -> m () Source #
Modifies an element in a mutable array.
modifyArray' :: (MArray a e m, Ix i) => a i e -> i -> (e -> e) -> m () Source #
Modifies an element in a mutable array. Strict version.
ifoldr :: Foldable f => (Int -> a -> b -> b) -> b -> f a -> b Source #
foldr with an index, starting at 0.
ifoldl' :: Foldable f => (b -> Int -> a -> b) -> b -> f a -> b Source #
foldl' with an index, starting at 0.
foldMComp :: Monad m => (b -> a -> b) -> (c -> m a) -> b -> c -> m b Source #
Compose a strict left fold function with a mapM function. Useful for foldMs.
foldM (f foldMComp
g) z = fmap (foldl' f z) . mapM g
farthest :: (a -> Maybe a) -> a -> a Source #
Repeatedly applies a function to a value and returns the value which gives back Nothing.
foldTree' :: (a -> b -> c) -> (c -> b -> b) -> b -> Tree a -> c Source #
Folds a tree. This does the same job as Data.Tree.foldTree but with different fold functions, which may be preferable in cases such as CPS folds.
class Semigroup a => Commutative a Source #
A semigroup where the operation (<>) is commutative. a <> b = b <> a
class Monoid a => Group a where Source #
A monoid where elements have inverses. a <> invert a = mempty invert a <> a = mempty
class Semigroup a => Idempotent a Source #
A semigroup where the elements are idempotent. a <> a = a
bitLength :: FiniteBits b => b -> Int Source #
The number of bits required to represent the value.