basement-0.0.16: Foundation scrap box of array & string

Safe Haskell | Safe-Inferred
Language | Haskell2010

Basement.Compat.Semigroup

Synopsis

- class Semigroup a where
  - (<>) :: a -> a -> a
  - sconcat :: NonEmpty a -> a
  - stimes :: Integral b => b -> a -> a
- type ListNonEmpty = NonEmpty

# Documentation

class Semigroup a where Source #

The class of semigroups (types with an associative binary operation).

Instances should satisfy the following:

Associativity
  `x `<>` (y `<>` z) = (x `<>` y) `<>` z`

Since: base-4.9.0.0

Minimal complete definition

(<>)

Methods

(<>) :: a -> a -> a infixr 6 Source #

An associative operation.

    >>> [1,2,3] <> [4,5,6]
    [1,2,3,4,5,6]

sconcat :: NonEmpty a -> a Source #

Reduce a non-empty list with `<>`

The default definition should be sufficient, but this can be overridden for efficiency.

    >>> import Data.List.NonEmpty (NonEmpty (..))
    >>> sconcat $ "Hello" :| [" ", "Haskell", "!"]
    "Hello Haskell!"

stimes :: Integral b => b -> a -> a Source #

Repeat a value `n` times.

Given that this works on a `Semigroup` it is allowed to fail if you request 0 or fewer repetitions, and the default definition will do so.

By making this a member of the class, idempotent semigroups and monoids can upgrade this to execute in \(\mathcal{O}(1)\) by picking `stimes = `stimesIdempotent`` or `stimes = `stimesIdempotentMonoid`` respectively.

    >>> stimes 4 [1]
    [1,1,1,1]

#### Instances

Instances details

Semigroup All | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup.Internal Methods (<>) :: All -> All -> All Source # sconcat :: NonEmpty All -> All Source # stimes :: Integral b => b -> All -> All Source #
Semigroup Any | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup.Internal Methods (<>) :: Any -> Any -> Any Source # sconcat :: NonEmpty Any -> Any Source # stimes :: Integral b => b -> Any -> Any Source #
Semigroup Builder Source # |
Instance details Defined in Basement.Block.Builder Methods (<>) :: Builder -> Builder -> Builder Source # sconcat :: NonEmpty Builder -> Builder Source # stimes :: Integral b => b -> Builder -> Builder Source #
Semigroup Builder Source # |
Instance details Defined in Basement.String.Builder Methods (<>) :: Builder -> Builder -> Builder Source # sconcat :: NonEmpty Builder -> Builder Source # stimes :: Integral b => b -> Builder -> Builder Source #
Semigroup AsciiString Source # |
Instance details Defined in Basement.Types.AsciiString Methods (<>) :: AsciiString -> AsciiString -> AsciiString Source # sconcat :: NonEmpty AsciiString -> AsciiString Source # stimes :: Integral b => b -> AsciiString -> AsciiString Source #
Semigroup String Source # |
Instance details Defined in Basement.UTF8.Base Methods (<>) :: String -> String -> String Source # sconcat :: NonEmpty String -> String Source # stimes :: Integral b => b -> String -> String Source #
Semigroup Ordering | Since: base-4.9.0.0
Instance details Defined in GHC.Base Methods (<>) :: Ordering -> Ordering -> Ordering Source # sconcat :: NonEmpty Ordering -> Ordering Source # stimes :: Integral b => b -> Ordering -> Ordering Source #
Semigroup () | Since: base-4.9.0.0
Instance details Defined in GHC.Base Methods (<>) :: () -> () -> () Source # sconcat :: NonEmpty () -> () Source # stimes :: Integral b => b -> () -> () Source #
Bits a => Semigroup (And a) | Since: base-4.16
Instance details Defined in Data.Bits Methods (<>) :: And a -> And a -> And a Source # sconcat :: NonEmpty (And a) -> And a Source # stimes :: Integral b => b -> And a -> And a Source #
FiniteBits a => Semigroup (Iff a) | This constraint is arguably too strong. However, as some types (such as `Natural`) have undefined `complement`, this is the only safe choice. Since: base-4.16
Instance details Defined in Data.Bits Methods (<>) :: Iff a -> Iff a -> Iff a Source # sconcat :: NonEmpty (Iff a) -> Iff a Source # stimes :: Integral b => b -> Iff a -> Iff a Source #
Bits a => Semigroup (Ior a) | Since: base-4.16
Instance details Defined in Data.Bits Methods (<>) :: Ior a -> Ior a -> Ior a Source # sconcat :: NonEmpty (Ior a) -> Ior a Source # stimes :: Integral b => b -> Ior a -> Ior a Source #
Bits a => Semigroup (Xor a) | Since: base-4.16
Instance details Defined in Data.Bits Methods (<>) :: Xor a -> Xor a -> Xor a Source # sconcat :: NonEmpty (Xor a) -> Xor a Source # stimes :: Integral b => b -> Xor a -> Xor a Source #
Semigroup a => Semigroup (Identity a) | Since: base-4.9.0.0
Instance details Defined in Data.Functor.Identity Methods (<>) :: Identity a -> Identity a -> Identity a Source # sconcat :: NonEmpty (Identity a) -> Identity a Source # stimes :: Integral b => b -> Identity a -> Identity a Source #
Semigroup (First a) | Since: base-4.9.0.0
Instance details Defined in Data.Monoid Methods (<>) :: First a -> First a -> First a Source # sconcat :: NonEmpty (First a) -> First a Source # stimes :: Integral b => b -> First a -> First a Source #
Semigroup (Last a) | Since: base-4.9.0.0
Instance details Defined in Data.Monoid Methods (<>) :: Last a -> Last a -> Last a Source # sconcat :: NonEmpty (Last a) -> Last a Source # stimes :: Integral b => b -> Last a -> Last a Source #
Semigroup a => Semigroup (Down a) | Since: base-4.11.0.0
Instance details Defined in Data.Ord Methods (<>) :: Down a -> Down a -> Down a Source # sconcat :: NonEmpty (Down a) -> Down a Source # stimes :: Integral b => b -> Down a -> Down a Source #
Semigroup (First a) | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup Methods (<>) :: First a -> First a -> First a Source # sconcat :: NonEmpty (First a) -> First a Source # stimes :: Integral b => b -> First a -> First a Source #
Semigroup (Last a) | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup Methods (<>) :: Last a -> Last a -> Last a Source # sconcat :: NonEmpty (Last a) -> Last a Source # stimes :: Integral b => b -> Last a -> Last a Source #
Ord a => Semigroup (Max a) | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup Methods (<>) :: Max a -> Max a -> Max a Source # sconcat :: NonEmpty (Max a) -> Max a Source # stimes :: Integral b => b -> Max a -> Max a Source #
Ord a => Semigroup (Min a) | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup Methods (<>) :: Min a -> Min a -> Min a Source # sconcat :: NonEmpty (Min a) -> Min a Source # stimes :: Integral b => b -> Min a -> Min a Source #
Monoid m => Semigroup (WrappedMonoid m) | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup Methods (<>) :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m Source # sconcat :: NonEmpty (WrappedMonoid m) -> WrappedMonoid m Source # stimes :: Integral b => b -> WrappedMonoid m -> WrappedMonoid m Source #
Semigroup a => Semigroup (Dual a) | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup.Internal Methods (<>) :: Dual a -> Dual a -> Dual a Source # sconcat :: NonEmpty (Dual a) -> Dual a Source # stimes :: Integral b => b -> Dual a -> Dual a Source #
Semigroup (Endo a) | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup.Internal Methods (<>) :: Endo a -> Endo a -> Endo a Source # sconcat :: NonEmpty (Endo a) -> Endo a Source # stimes :: Integral b => b -> Endo a -> Endo a Source #
Num a => Semigroup (Product a) | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup.Internal Methods (<>) :: Product a -> Product a -> Product a Source # sconcat :: NonEmpty (Product a) -> Product a Source # stimes :: Integral b => b -> Product a -> Product a Source #
Num a => Semigroup (Sum a) | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup.Internal Methods (<>) :: Sum a -> Sum a -> Sum a Source # sconcat :: NonEmpty (Sum a) -> Sum a Source # stimes :: Integral b => b -> Sum a -> Sum a Source #
(Generic a, Semigroup (Rep a ())) => Semigroup (Generically a) | Since: base-4.17.0.0
Instance details Defined in GHC.Generics Methods (<>) :: Generically a -> Generically a -> Generically a Source # sconcat :: NonEmpty (Generically a) -> Generically a Source # stimes :: Integral b => b -> Generically a -> Generically a Source #
Semigroup p => Semigroup (Par1 p) | Since: base-4.12.0.0
Instance details Defined in GHC.Generics Methods (<>) :: Par1 p -> Par1 p -> Par1 p Source # sconcat :: NonEmpty (Par1 p) -> Par1 p Source # stimes :: Integral b => b -> Par1 p -> Par1 p Source #
PrimType ty => Semigroup (Block ty) Source # |
Instance details Defined in Basement.Block.Base Methods (<>) :: Block ty -> Block ty -> Block ty Source # sconcat :: NonEmpty (Block ty) -> Block ty Source # stimes :: Integral b => b -> Block ty -> Block ty Source #
Semigroup (Array a) Source # |
Instance details Defined in Basement.BoxedArray Methods (<>) :: Array a -> Array a -> Array a Source # sconcat :: NonEmpty (Array a) -> Array a Source # stimes :: Integral b => b -> Array a -> Array a Source #
Semigroup (CountOf ty) Source # |
Instance details Defined in Basement.Types.OffsetSize Methods (<>) :: CountOf ty -> CountOf ty -> CountOf ty Source # sconcat :: NonEmpty (CountOf ty) -> CountOf ty Source # stimes :: Integral b => b -> CountOf ty -> CountOf ty Source #
PrimType ty => Semigroup (UArray ty) Source # |
Instance details Defined in Basement.UArray.Base Methods (<>) :: UArray ty -> UArray ty -> UArray ty Source # sconcat :: NonEmpty (UArray ty) -> UArray ty Source # stimes :: Integral b => b -> UArray ty -> UArray ty Source #
Semigroup a => Semigroup (IO a) | Since: base-4.10.0.0
Instance details Defined in GHC.Base Methods (<>) :: IO a -> IO a -> IO a Source # sconcat :: NonEmpty (IO a) -> IO a Source # stimes :: Integral b => b -> IO a -> IO a Source #
Semigroup (NonEmpty a) | Since: base-4.9.0.0
Instance details Defined in GHC.Base Methods (<>) :: NonEmpty a -> NonEmpty a -> NonEmpty a Source # sconcat :: NonEmpty (NonEmpty a) -> NonEmpty a Source # stimes :: Integral b => b -> NonEmpty a -> NonEmpty a Source #
Semigroup a => Semigroup (Maybe a) | Since: base-4.9.0.0
Instance details Defined in GHC.Base Methods (<>) :: Maybe a -> Maybe a -> Maybe a Source # sconcat :: NonEmpty (Maybe a) -> Maybe a Source # stimes :: Integral b => b -> Maybe a -> Maybe a Source #
Semigroup a => Semigroup (a) | Since: base-4.15
Instance details Defined in GHC.Base Methods (<>) :: (a) -> (a) -> (a) Source # sconcat :: NonEmpty (a) -> (a) Source # stimes :: Integral b => b -> (a) -> (a) Source #
Semigroup [a] | Since: base-4.9.0.0
Instance details Defined in GHC.Base Methods (<>) :: [a] -> [a] -> [a] Source # sconcat :: NonEmpty [a] -> [a] Source # stimes :: Integral b => b -> [a] -> [a] Source #
Semigroup (Either a b) | Since: base-4.9.0.0
Instance details Defined in Data.Either Methods (<>) :: Either a b -> Either a b -> Either a b Source # sconcat :: NonEmpty (Either a b) -> Either a b Source # stimes :: Integral b0 => b0 -> Either a b -> Either a b Source #
Semigroup (Proxy s) | Since: base-4.9.0.0
Instance details Defined in Data.Proxy Methods (<>) :: Proxy s -> Proxy s -> Proxy s Source # sconcat :: NonEmpty (Proxy s) -> Proxy s Source # stimes :: Integral b => b -> Proxy s -> Proxy s Source #
Semigroup (U1 p) | Since: base-4.12.0.0
Instance details Defined in GHC.Generics Methods (<>) :: U1 p -> U1 p -> U1 p Source # sconcat :: NonEmpty (U1 p) -> U1 p Source # stimes :: Integral b => b -> U1 p -> U1 p Source #
Semigroup (V1 p) | Since: base-4.12.0.0
Instance details Defined in GHC.Generics Methods (<>) :: V1 p -> V1 p -> V1 p Source # sconcat :: NonEmpty (V1 p) -> V1 p Source # stimes :: Integral b => b -> V1 p -> V1 p Source #
Semigroup a => Semigroup (ST s a) | Since: base-4.11.0.0
Instance details Defined in GHC.ST Methods (<>) :: ST s a -> ST s a -> ST s a Source # sconcat :: NonEmpty (ST s a) -> ST s a Source # stimes :: Integral b => b -> ST s a -> ST s a Source #
Semigroup b => Semigroup (a -> b) | Since: base-4.9.0.0
Instance details Defined in GHC.Base Methods (<>) :: (a -> b) -> (a -> b) -> a -> b Source # sconcat :: NonEmpty (a -> b) -> a -> b Source # stimes :: Integral b0 => b0 -> (a -> b) -> a -> b Source #
(Semigroup a, Semigroup b) => Semigroup (a, b) | Since: base-4.9.0.0
Instance details Defined in GHC.Base Methods (<>) :: (a, b) -> (a, b) -> (a, b) Source # sconcat :: NonEmpty (a, b) -> (a, b) Source # stimes :: Integral b0 => b0 -> (a, b) -> (a, b) Source #
Semigroup a => Semigroup (Const a b) | Since: base-4.9.0.0
Instance details Defined in Data.Functor.Const Methods (<>) :: Const a b -> Const a b -> Const a b Source # sconcat :: NonEmpty (Const a b) -> Const a b Source # stimes :: Integral b0 => b0 -> Const a b -> Const a b Source #
(Applicative f, Semigroup a) => Semigroup (Ap f a) | Since: base-4.12.0.0
Instance details Defined in Data.Monoid Methods (<>) :: Ap f a -> Ap f a -> Ap f a Source # sconcat :: NonEmpty (Ap f a) -> Ap f a Source # stimes :: Integral b => b -> Ap f a -> Ap f a Source #
Alternative f => Semigroup (Alt f a) | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup.Internal Methods (<>) :: Alt f a -> Alt f a -> Alt f a Source # sconcat :: NonEmpty (Alt f a) -> Alt f a Source # stimes :: Integral b => b -> Alt f a -> Alt f a Source #
Semigroup (f p) => Semigroup (Rec1 f p) | Since: base-4.12.0.0
Instance details Defined in GHC.Generics Methods (<>) :: Rec1 f p -> Rec1 f p -> Rec1 f p Source # sconcat :: NonEmpty (Rec1 f p) -> Rec1 f p Source # stimes :: Integral b => b -> Rec1 f p -> Rec1 f p Source #
(Semigroup a, Semigroup b, Semigroup c) => Semigroup (a, b, c) | Since: base-4.9.0.0
Instance details Defined in GHC.Base Methods (<>) :: (a, b, c) -> (a, b, c) -> (a, b, c) Source # sconcat :: NonEmpty (a, b, c) -> (a, b, c) Source # stimes :: Integral b0 => b0 -> (a, b, c) -> (a, b, c) Source #
(Semigroup (f p), Semigroup (g p)) => Semigroup ((f :*: g) p) | Since: base-4.12.0.0
Instance details Defined in GHC.Generics Methods (<>) :: (f :*: g) p -> (f :*: g) p -> (f :*: g) p Source # sconcat :: NonEmpty ((f :*: g) p) -> (f :*: g) p Source # stimes :: Integral b => b -> (f :*: g) p -> (f :*: g) p Source #
Semigroup c => Semigroup (K1 i c p) | Since: base-4.12.0.0
Instance details Defined in GHC.Generics Methods (<>) :: K1 i c p -> K1 i c p -> K1 i c p Source # sconcat :: NonEmpty (K1 i c p) -> K1 i c p Source # stimes :: Integral b => b -> K1 i c p -> K1 i c p Source #
(Semigroup a, Semigroup b, Semigroup c, Semigroup d) => Semigroup (a, b, c, d) | Since: base-4.9.0.0
Instance details Defined in GHC.Base Methods (<>) :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d) Source # sconcat :: NonEmpty (a, b, c, d) -> (a, b, c, d) Source # stimes :: Integral b0 => b0 -> (a, b, c, d) -> (a, b, c, d) Source #
Semigroup (f (g p)) => Semigroup ((f :.: g) p) | Since: base-4.12.0.0
Instance details Defined in GHC.Generics Methods (<>) :: (f :.: g) p -> (f :.: g) p -> (f :.: g) p Source # sconcat :: NonEmpty ((f :.: g) p) -> (f :.: g) p Source # stimes :: Integral b => b -> (f :.: g) p -> (f :.: g) p Source #
Semigroup (f p) => Semigroup (M1 i c f p) | Since: base-4.12.0.0
Instance details Defined in GHC.Generics Methods (<>) :: M1 i c f p -> M1 i c f p -> M1 i c f p Source # sconcat :: NonEmpty (M1 i c f p) -> M1 i c f p Source # stimes :: Integral b => b -> M1 i c f p -> M1 i c f p Source #
(Semigroup a, Semigroup b, Semigroup c, Semigroup d, Semigroup e) => Semigroup (a, b, c, d, e) | Since: base-4.9.0.0
Instance details Defined in GHC.Base Methods (<>) :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) Source # sconcat :: NonEmpty (a, b, c, d, e) -> (a, b, c, d, e) Source # stimes :: Integral b0 => b0 -> (a, b, c, d, e) -> (a, b, c, d, e) Source #

type ListNonEmpty = NonEmpty Source #