nikita-volkov / typeclasses / Typeclasses.Classes.Semigroup

Semigroup typeclass definition and its instances for basic types.

Definition


type alias Semigroup a =
{ prepend : a -> a -> a }

Explicit typeclass which implements semigroup operations for type a.

Notice that the binary operation function is named "prepend" instead of "append", because it follows the convention of having the context value come as the last value.

Construction utilities

prepend : (a -> a -> a) -> Semigroup a

Construct from a prepend function.

concat : (List a -> a) -> Semigroup a

Construct from a concatenation function.

appendable : Semigroup appendable

Construct an instance for any type which satisfies Elm's appendable magic constraint.

numberProduct : Semigroup number

Construct an instance for any type which satisfies Elm's number magic constraint. Implements multiplication.

numberSum : Semigroup number

Construct an instance for any type which satisfies Elm's number magic constraint. Implements sum.

Instance transformation utilities

map : (a -> b) -> (b -> a) -> Semigroup a -> Semigroup b

Map over the owner type of an instance to produce a new instance.

You need to provide both a covariant and a contravariant mapping (i.e., (a -> b) and (b -> a)).

Instances

intProduct : Semigroup Basics.Int

Instance for integers under the multiplication operation.

intSum : Semigroup Basics.Int

Instance for integers under the sum operation.

string : Semigroup String

Instance for strings under the appending operation.

maybeFirst : Semigroup (Maybe a)

Instance for maybe, which chooses the first Just value.

list : Semigroup (List a)

Instance for list under concatenation.

setUnion : Semigroup (Set comparable)

Instance for set under the union operation.

setIntersection : Semigroup (Set comparable)

Instance for set under the intersection operation.

setDifference : Semigroup (Set comparable)

Instance for set under the difference operation.

cmd : Semigroup (Platform.Cmd.Cmd msg)

Instance for commands under the batch operation.

sub : Semigroup (Platform.Sub.Sub msg)

Instance for subscriptions under the batch operation.

task : Semigroup a -> Semigroup (Task x a)

Instance for tasks, which sequentially executes them and groups the results.