-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Anything that associates -- @package semigroups @version 0.17 -- | A NonEmpty list forms a monad as per list, but always contains at -- least one element. module Data.List.NonEmpty data NonEmpty a (:|) :: a -> [a] -> NonEmpty a -- | Map a function over a NonEmpty stream. map :: (a -> b) -> NonEmpty a -> NonEmpty b -- | 'intersperse x xs' alternates elements of the list with copies of -- x. -- --
--   intersperse 0 (1 :| [2,3]) == 1 :| [0,2,0,3]
--   
intersperse :: a -> NonEmpty a -> NonEmpty a -- | scanl is similar to foldl, but returns a stream of -- successive reduced values from the left: -- --
--   scanl f z [x1, x2, ...] == z :| [z `f` x1, (z `f` x1) `f` x2, ...]
--   
-- -- Note that -- --
--   last (scanl f z xs) == foldl f z xs.
--   
scanl :: Foldable f => (b -> a -> b) -> b -> f a -> NonEmpty b -- | scanr is the right-to-left dual of scanl. Note that -- --
--   head (scanr f z xs) == foldr f z xs.
--   
scanr :: Foldable f => (a -> b -> b) -> b -> f a -> NonEmpty b -- | scanl1 is a variant of scanl that has no starting value -- argument: -- --
--   scanl1 f [x1, x2, ...] == x1 :| [x1 `f` x2, x1 `f` (x2 `f` x3), ...]
--   
scanl1 :: (a -> a -> a) -> NonEmpty a -> NonEmpty a -- | scanr1 is a variant of scanr that has no starting value -- argument. scanr1 :: (a -> a -> a) -> NonEmpty a -> NonEmpty a -- | transpose for NonEmpty, behaves the same as -- transpose The rows/columns need not be the same length, in -- which case > transpose . transpose /= id transpose :: NonEmpty (NonEmpty a) -> NonEmpty (NonEmpty a) -- | sortBy for NonEmpty, behaves the same as sortBy sortBy :: (a -> a -> Ordering) -> NonEmpty a -> NonEmpty a -- | sortWith for NonEmpty, behaves the same as: -- --
--   sortBy . comparing
--   
sortWith :: Ord o => (a -> o) -> NonEmpty a -> NonEmpty a length :: NonEmpty a -> Int -- | Extract the first element of the stream. head :: NonEmpty a -> a -- | Extract the possibly-empty tail of the stream. tail :: NonEmpty a -> [a] -- | Extract the last element of the stream. last :: NonEmpty a -> a -- | Extract everything except the last element of the stream. init :: NonEmpty a -> [a] -- | Prepend an element to the stream. (<|) :: a -> NonEmpty a -> NonEmpty a -- | Synonym for <|. cons :: a -> NonEmpty a -> NonEmpty a -- | uncons produces the first element of the stream, and a stream -- of the remaining elements, if any. uncons :: NonEmpty a -> (a, Maybe (NonEmpty a)) unfoldr :: (a -> (b, Maybe a)) -> a -> NonEmpty b -- | Sort a stream. sort :: Ord a => NonEmpty a -> NonEmpty a -- | reverse a finite NonEmpty stream. reverse :: NonEmpty a -> NonEmpty a -- | The inits function takes a stream xs and returns all -- the finite prefixes of xs. inits :: Foldable f => f a -> NonEmpty [a] -- | The tails function takes a stream xs and returns all -- the suffixes of xs. tails :: Foldable f => f a -> NonEmpty [a] -- | iterate f x produces the infinite sequence of repeated -- applications of f to x. -- --
--   iterate f x = x :| [f x, f (f x), ..]
--   
iterate :: (a -> a) -> a -> NonEmpty a -- | repeat x returns a constant stream, where all elements -- are equal to x. repeat :: a -> NonEmpty a -- | cycle xs returns the infinite repetition of -- xs: -- --
--   cycle [1,2,3] = 1 :| [2,3,1,2,3,...]
--   
cycle :: NonEmpty a -> NonEmpty a -- | unfold produces a new stream by repeatedly applying the -- unfolding function to the seed value to produce an element of type -- b and a new seed value. When the unfolding function returns -- Nothing instead of a new seed value, the stream ends. unfold :: (a -> (b, Maybe a)) -> a -> NonEmpty b -- | insert x xs inserts x into the last position -- in xs where it is still less than or equal to the next -- element. In particular, if the list is sorted beforehand, the result -- will also be sorted. insert :: (Foldable f, Ord a) => a -> f a -> NonEmpty a -- | some1 x sequences x one or more times. some1 :: Alternative f => f a -> f (NonEmpty a) -- | take n xs returns the first n elements of -- xs. take :: Int -> NonEmpty a -> [a] -- | drop n xs drops the first n elements off the -- front of the sequence xs. drop :: Int -> NonEmpty a -> [a] -- | splitAt n xs returns a pair consisting of the prefix -- of xs of length n and the remaining stream -- immediately following this prefix. -- --
--   'splitAt' n xs == ('take' n xs, 'drop' n xs)
--   xs == ys ++ zs where (ys, zs) = 'splitAt' n xs
--   
splitAt :: Int -> NonEmpty a -> ([a], [a]) -- | takeWhile p xs returns the longest prefix of the -- stream xs for which the predicate p holds. takeWhile :: (a -> Bool) -> NonEmpty a -> [a] -- | dropWhile p xs returns the suffix remaining after -- takeWhile p xs. dropWhile :: (a -> Bool) -> NonEmpty a -> [a] -- | span p xs returns the longest prefix of xs -- that satisfies p, together with the remainder of the stream. -- --
--   'span' p xs == ('takeWhile' p xs, 'dropWhile' p xs)
--   xs == ys ++ zs where (ys, zs) = 'span' p xs
--   
span :: (a -> Bool) -> NonEmpty a -> ([a], [a]) -- | The break p function is equivalent to span -- (not . p). break :: (a -> Bool) -> NonEmpty a -> ([a], [a]) -- | filter p xs removes any elements from xs that -- do not satisfy p. filter :: (a -> Bool) -> NonEmpty a -> [a] -- | The partition function takes a predicate p and a -- stream xs, and returns a pair of lists. The first list -- corresponds to the elements of xs for which p holds; -- the second corresponds to the elements of xs for which -- p does not hold. -- --
--   'partition' p xs = ('filter' p xs, 'filter' (not . p) xs)
--   
partition :: (a -> Bool) -> NonEmpty a -> ([a], [a]) -- | The group function takes a stream and returns a list of streams -- such that flattening the resulting list is equal to the argument. -- Moreover, each stream in the resulting list contains only equal -- elements. For example, in list notation: -- --
--   'group' $ 'cycle' "Mississippi" = "M" : "i" : "ss" : "i" : "ss" : "i" : "pp" : "i" : "M" : "i" : ...
--   
group :: (Foldable f, Eq a) => f a -> [NonEmpty a] -- | groupBy operates like group, but uses the provided -- equality predicate instead of ==. groupBy :: Foldable f => (a -> a -> Bool) -> f a -> [NonEmpty a] -- | groupWith operates like group, but uses the provided -- projection when comparing for equality groupWith :: (Foldable f, Eq b) => (a -> b) -> f a -> [NonEmpty a] -- | groupAllWith operates like groupWith, but sorts the list -- first so that each equivalence class has, at most, one list in the -- output groupAllWith :: Ord b => (a -> b) -> [a] -> [NonEmpty a] -- | group1 operates like group, but uses the knowledge that -- its input is non-empty to produce guaranteed non-empty output. group1 :: Eq a => NonEmpty a -> NonEmpty (NonEmpty a) -- | groupBy1 is to group1 as groupBy is to -- group. groupBy1 :: (a -> a -> Bool) -> NonEmpty a -> NonEmpty (NonEmpty a) -- | groupWith1 is to group1 as groupWith is to -- group groupWith1 :: Eq b => (a -> b) -> NonEmpty a -> NonEmpty (NonEmpty a) -- | groupAllWith1 is to groupWith1 as groupAllWith is -- to groupWith groupAllWith1 :: Ord b => (a -> b) -> NonEmpty a -> NonEmpty (NonEmpty a) -- | The isPrefix function returns True if the first -- argument is a prefix of the second. isPrefixOf :: Eq a => [a] -> NonEmpty a -> Bool -- | The nub function removes duplicate elements from a list. In -- particular, it keeps only the first occurence of each element. (The -- name nub means 'essence'.) It is a special case of -- nubBy, which allows the programmer to supply their own -- inequality test. nub :: Eq a => NonEmpty a -> NonEmpty a -- | The nubBy function behaves just like nub, except it uses -- a user-supplied equality predicate instead of the overloaded == -- function. nubBy :: (a -> a -> Bool) -> NonEmpty a -> NonEmpty a -- | xs !! n returns the element of the stream xs at -- index n. Note that the head of the stream has index 0. -- -- Beware: a negative or out-of-bounds index will cause an error. (!!) :: NonEmpty a -> Int -> a -- | The zip function takes two streams and returns a stream of -- corresponding pairs. zip :: NonEmpty a -> NonEmpty b -> NonEmpty (a, b) -- | The zipWith function generalizes zip. Rather than -- tupling the elements, the elements are combined using the function -- passed as the first argument. zipWith :: (a -> b -> c) -> NonEmpty a -> NonEmpty b -> NonEmpty c -- | The unzip function is the inverse of the zip function. unzip :: Functor f => f (a, b) -> (f a, f b) -- | The words function breaks a stream of characters into a stream -- of words, which were delimited by white space. -- -- Beware: if the input contains no words (i.e. is entirely -- whitespace), this will cause an error. words :: NonEmpty Char -> NonEmpty String -- | The unwords function is an inverse operation to words. -- It joins words with separating spaces. -- -- Beware: the input ("" :| []) will cause an error. unwords :: NonEmpty String -> NonEmpty Char -- | The lines function breaks a stream of characters into a stream -- of strings at newline characters. The resulting strings do not contain -- newlines. lines :: NonEmpty Char -> NonEmpty String -- | The unlines function is an inverse operation to lines. -- It joins lines, after appending a terminating newline to each. unlines :: NonEmpty String -> NonEmpty Char -- | Converts a normal list to a NonEmpty stream. -- -- Raises an error if given an empty list. fromList :: [a] -> NonEmpty a -- | Convert a stream to a normal list efficiently. toList :: NonEmpty a -> [a] -- | nonEmpty efficiently turns a normal list into a NonEmpty -- stream, producing Nothing if the input is empty. nonEmpty :: [a] -> Maybe (NonEmpty a) xor :: NonEmpty Bool -> Bool instance Typeable NonEmpty instance Eq a => Eq (NonEmpty a) instance Ord a => Ord (NonEmpty a) instance Show a => Show (NonEmpty a) instance Read a => Read (NonEmpty a) instance Data a => Data (NonEmpty a) instance Generic (NonEmpty a) instance Generic1 NonEmpty instance Datatype D1NonEmpty instance Constructor C1_0NonEmpty instance Foldable NonEmpty instance Traversable NonEmpty instance Monad NonEmpty instance Applicative NonEmpty instance Functor NonEmpty instance MonadZip NonEmpty instance MonadFix NonEmpty instance NFData a => NFData (NonEmpty a) instance IsList (NonEmpty a) instance Hashable a => Hashable (NonEmpty a) -- | In mathematics, a semigroup is an algebraic structure consisting of a -- set together with an associative binary operation. A semigroup -- generalizes a monoid in that there might not exist an identity -- element. It also (originally) generalized a group (a monoid with all -- inverses) to a type where every element did not have to have an -- inverse, thus the name semigroup. -- -- The use of (<>) in this module conflicts with an -- operator with the same name that is being exported by Data.Monoid. -- However, this package re-exports (most of) the contents of -- Data.Monoid, so to use semigroups and monoids in the same package just -- --
--   import Data.Semigroup
--   
module Data.Semigroup class Semigroup a where (<>) = mappend sconcat (a :| as) = go a as where go b (c : cs) = b <> go c cs go b [] = b stimes y0 x0 | y0 <= 0 = error "stimes: positive multiplier expected" | otherwise = f x0 y0 where f x y | even y = f (x <> x) (y `quot` 2) | y == 1 = x | otherwise = g (x <> x) (pred y `quot` 2) x g x y z | even y = g (x <> x) (y `quot` 2) z | y == 1 = x <> z | otherwise = g (x <> x) (pred y `quot` 2) (x <> z) (<>) :: Semigroup a => a -> a -> a sconcat :: Semigroup a => NonEmpty a -> a stimes :: (Semigroup a, Integral b) => b -> a -> a -- | This is a valid definition of stimes for a Monoid. -- -- Unlike the default definition of stimes, it is defined for 0 -- and so it should be preferred where possible. stimesMonoid :: (Integral b, Monoid a) => b -> a -> a -- | This is a valid definition of stimes for an idempotent -- Semigroup. -- -- When x <> x = x, this definition should be preferred, -- because it works in O(1) rather than O(log n). stimesIdempotent :: Integral b => b -> a -> a -- | This is a valid definition of stimes for an idempotent -- Monoid. -- -- When mappend x x = x, this definition should be preferred, -- because it works in O(1) rather than O(log n) stimesIdempotentMonoid :: (Integral b, Monoid a) => b -> a -> a -- | Repeat a value n times. -- --
--   mtimesDefault n a = a <> a <> ... <> a  -- using <> (n-1) times
--   
-- -- Implemented using stimes and mempty. -- -- This is a suitable definition for an mtimes member of -- Monoid. -- -- @since 0.18 mtimesDefault :: (Integral b, Monoid a) => b -> a -> a newtype Min a Min :: a -> Min a getMin :: Min a -> a newtype Max a Max :: a -> Max a getMax :: Max a -> a -- | Use Option (First a) to get the behavior of -- First from Data.Monoid. newtype First a First :: a -> First a getFirst :: First a -> a -- | Use Option (Last a) to get the behavior of -- Last from Data.Monoid newtype Last a Last :: a -> Last a getLast :: Last a -> a -- | Provide a Semigroup for an arbitrary Monoid. newtype WrappedMonoid m WrapMonoid :: m -> WrappedMonoid m unwrapMonoid :: WrappedMonoid m -> m -- | The class of monoids (types with an associative binary operation that -- has an identity). Instances should satisfy the following laws: -- -- -- -- The method names refer to the monoid of lists under concatenation, but -- there are many other instances. -- -- Minimal complete definition: mempty and mappend. -- -- Some types can be viewed as a monoid in more than one way, e.g. both -- addition and multiplication on numbers. In such cases we often define -- newtypes and make those instances of Monoid, e.g. -- Sum and Product. class Monoid a mempty :: Monoid a => a mappend :: Monoid a => a -> a -> a mconcat :: Monoid a => [a] -> a -- | The dual of a monoid, obtained by swapping the arguments of -- mappend. newtype Dual a :: * -> * Dual :: a -> Dual a getDual :: Dual a -> a -- | The monoid of endomorphisms under composition. newtype Endo a :: * -> * Endo :: (a -> a) -> Endo a appEndo :: Endo a -> a -> a -- | Boolean monoid under conjunction. newtype All :: * All :: Bool -> All getAll :: All -> Bool -- | Boolean monoid under disjunction. newtype Any :: * Any :: Bool -> Any getAny :: Any -> Bool -- | Monoid under addition. newtype Sum a :: * -> * Sum :: a -> Sum a getSum :: Sum a -> a -- | Monoid under multiplication. newtype Product a :: * -> * Product :: a -> Product a getProduct :: Product a -> a -- | Option is effectively Maybe with a better instance of -- Monoid, built off of an underlying Semigroup instead of -- an underlying Monoid. -- -- Ideally, this type would not exist at all and we would just fix the -- Monoid instance of Maybe newtype Option a Option :: Maybe a -> Option a getOption :: Option a -> Maybe a -- | Fold an Option case-wise, just like maybe. option :: b -> (a -> b) -> Option a -> b -- | This lets you use a difference list of a Semigroup as a -- Monoid. diff :: Semigroup m => m -> Endo m -- | A generalization of cycle to an arbitrary Semigroup. May -- fail to terminate for some values in some semigroups. cycle1 :: Semigroup m => m -> m -- | Arg isn't itself a Semigroup in its own right, but it -- can be placed inside Min and Max to compute an arg min -- or arg max. data Arg a b Arg :: a -> b -> Arg a b type ArgMin a b = Min (Arg a b) type ArgMax a b = Max (Arg a b) instance Typeable Min instance Typeable Max instance Typeable Arg instance Typeable First instance Typeable Last instance Typeable WrappedMonoid instance Typeable Option instance Eq a => Eq (Min a) instance Ord a => Ord (Min a) instance Show a => Show (Min a) instance Read a => Read (Min a) instance Data a => Data (Min a) instance Generic (Min a) instance Generic1 Min instance Eq a => Eq (Max a) instance Ord a => Ord (Max a) instance Show a => Show (Max a) instance Read a => Read (Max a) instance Data a => Data (Max a) instance Generic (Max a) instance Generic1 Max instance (Show a, Show b) => Show (Arg a b) instance (Read a, Read b) => Read (Arg a b) instance (Data a, Data b) => Data (Arg a b) instance Generic (Arg a b) instance Generic1 (Arg a) instance Eq a => Eq (First a) instance Ord a => Ord (First a) instance Show a => Show (First a) instance Read a => Read (First a) instance Data a => Data (First a) instance Generic (First a) instance Generic1 First instance Eq a => Eq (Last a) instance Ord a => Ord (Last a) instance Show a => Show (Last a) instance Read a => Read (Last a) instance Data a => Data (Last a) instance Generic (Last a) instance Generic1 Last instance Eq m => Eq (WrappedMonoid m) instance Ord m => Ord (WrappedMonoid m) instance Show m => Show (WrappedMonoid m) instance Read m => Read (WrappedMonoid m) instance Data m => Data (WrappedMonoid m) instance Generic (WrappedMonoid m) instance Generic1 WrappedMonoid instance Eq a => Eq (Option a) instance Ord a => Ord (Option a) instance Show a => Show (Option a) instance Read a => Read (Option a) instance Data a => Data (Option a) instance Generic (Option a) instance Generic1 Option instance Datatype D1Min instance Constructor C1_0Min instance Selector S1_0_0Min instance Datatype D1Max instance Constructor C1_0Max instance Selector S1_0_0Max instance Datatype D1Arg instance Constructor C1_0Arg instance Datatype D1First instance Constructor C1_0First instance Selector S1_0_0First instance Datatype D1Last instance Constructor C1_0Last instance Selector S1_0_0Last instance Datatype D1WrappedMonoid instance Constructor C1_0WrappedMonoid instance Selector S1_0_0WrappedMonoid instance Datatype D1Option instance Constructor C1_0Option instance Selector S1_0_0Option instance Semigroup a => Semigroup (Tagged s a) instance Semigroup (Proxy s) instance Ord k => Semigroup (Map k v) instance Semigroup (IntMap v) instance Ord a => Semigroup (Set a) instance Semigroup IntSet instance Semigroup (Seq a) instance Semigroup a => Monoid (Option a) instance Semigroup a => Semigroup (Option a) instance NFData a => NFData (Option a) instance Traversable Option instance Foldable Option instance MonadFix Option instance MonadPlus Option instance Alternative Option instance Monad Option instance Applicative Option instance Functor Option instance Hashable a => Hashable (Option a) instance NFData m => NFData (WrappedMonoid m) instance Enum a => Enum (WrappedMonoid a) instance Bounded a => Bounded (WrappedMonoid a) instance Monoid m => Monoid (WrappedMonoid m) instance Monoid m => Semigroup (WrappedMonoid m) instance Hashable a => Hashable (WrappedMonoid a) instance (Hashable a, Eq a) => Semigroup (HashSet a) instance (Hashable k, Eq k) => Semigroup (HashMap k a) instance Semigroup Builder instance Semigroup Text instance Semigroup Text instance Semigroup ShortByteString instance Semigroup Builder instance Semigroup ByteString instance Semigroup ByteString instance NFData a => NFData (Last a) instance MonadFix Last instance Monad Last instance Applicative Last instance Traversable Last instance Foldable Last instance Functor Last instance Semigroup (Last a) instance Hashable a => Hashable (Last a) instance Enum a => Enum (Last a) instance Bounded a => Bounded (Last a) instance NFData a => NFData (First a) instance MonadFix First instance Monad First instance Applicative First instance Traversable First instance Foldable First instance Functor First instance Semigroup (First a) instance Hashable a => Hashable (First a) instance Enum a => Enum (First a) instance Bounded a => Bounded (First a) instance (Hashable a, Hashable b) => Hashable (Arg a b) instance (NFData a, NFData b) => NFData (Arg a b) instance Ord a => Ord (Arg a b) instance Eq a => Eq (Arg a b) instance Traversable (Arg a) instance Foldable (Arg a) instance Functor (Arg a) instance Num a => Num (Max a) instance NFData a => NFData (Max a) instance MonadFix Max instance Monad Max instance Applicative Max instance Traversable Max instance Foldable Max instance Functor Max instance (Ord a, Bounded a) => Monoid (Max a) instance Ord a => Semigroup (Max a) instance Hashable a => Hashable (Max a) instance Enum a => Enum (Max a) instance Bounded a => Bounded (Max a) instance Num a => Num (Min a) instance NFData a => NFData (Min a) instance MonadFix Min instance Monad Min instance Applicative Min instance Traversable Min instance Foldable Min instance Functor Min instance (Ord a, Bounded a) => Monoid (Min a) instance Ord a => Semigroup (Min a) instance Hashable a => Hashable (Min a) instance Enum a => Enum (Min a) instance Bounded a => Bounded (Min a) instance Semigroup (NonEmpty a) instance Semigroup (Last a) instance Semigroup (First a) instance Semigroup a => Semigroup (Const a b) instance Num a => Semigroup (Product a) instance Num a => Semigroup (Sum a) instance Semigroup Any instance Semigroup All instance Semigroup (Endo a) instance Semigroup a => Semigroup (Dual a) instance Semigroup Ordering instance (Semigroup a, Semigroup b, Semigroup c, Semigroup d, Semigroup e) => Semigroup (a, b, c, d, e) instance (Semigroup a, Semigroup b, Semigroup c, Semigroup d) => Semigroup (a, b, c, d) instance (Semigroup a, Semigroup b, Semigroup c) => Semigroup (a, b, c) instance (Semigroup a, Semigroup b) => Semigroup (a, b) instance Semigroup (Either a b) instance Semigroup a => Semigroup (Maybe a) instance Semigroup [a] instance Semigroup b => Semigroup (a -> b) instance Semigroup () -- | This module provides generic deriving tools for monoids and semigroups -- for product-like structures. module Data.Semigroup.Generic class GSemigroup f -- | Generically generate a Semigroup (<>) operation -- for any type implementing Generic. This operation will append -- two values by point-wise appending their component fields. It is only -- defined for product types. -- --
--   gmappend a (gmappend b c) = gmappend (gmappend a b) c
--   
gmappend :: (Generic a, GSemigroup (Rep a)) => a -> a -> a class GSemigroup f => GMonoid f -- | Generically generate a Monoid mempty for any -- product-like type implementing Generic. -- -- It is only defined for product types. -- --
--   gmappend gmempty a = a = gmappend a gmempty
--   
gmempty :: (Generic a, GMonoid (Rep a)) => a instance [safe] (GMonoid f, GMonoid g) => GMonoid (f :*: g) instance [safe] GMonoid f => GMonoid (M1 i c f) instance [safe] (Semigroup a, Monoid a) => GMonoid (K1 i a) instance [safe] GMonoid U1 instance [safe] (GSemigroup f, GSemigroup g) => GSemigroup (f :*: g) instance [safe] GSemigroup f => GSemigroup (M1 i c f) instance [safe] Semigroup a => GSemigroup (K1 i a) instance [safe] GSemigroup V1 instance [safe] GSemigroup U1