jonathanfishbein1/elm-monoid/1.0.3

Monoid

A module to define generic functions for monoid. For instance, we defined generic concat in this module using Monoid type as follows.

concat : Monoid a -> List a -> a
concat m =
    List.foldr (append m) (empty m)


concat string ["foo", "bar", "baz"]
--> "foobarbaz"


concat list [[1, 2, 3], [4, 5], [6]]
--> [1, 2, 3, 4, 5, 6]


concat sum [Sum 1, Sum 2, Sum 3, Sum 4] -- 1 + 2 + 3 + 4
--> Sum 10


concat sum <| List.map Sum [1, 2, 3, 4] -- 1 + 2 + 3 + 4
--> Sum 10


concat product <| List.map Product [1, 2, 3, 4] -- 1 * 2 * 3 * 4
--> Product 24

Types

type Monoid a

Main type.

type Sum a
= Sum a

Monoid under addition

type Product a
= Product a

Monoid under multiplication.

Constructors

monoid : a -> (a -> a -> a) -> Monoid a

Constructor for Monoid.

Functions for unwraping Monoid

empty : Monoid a -> a

Take the identity element of a monoid.

append : Monoid a -> a -> a -> a

Take the way to append a monoids.

Convenient functions for monoid

concat : Monoid a -> List a -> a

Concatenate list of monoid.

Monoid types for popular types

string : Monoid String

Monoid type for String.

sum : Monoid (Sum number)

Monoid type for Sum.

Monoid type for Product.

list : Monoid (List a)

Monoid type for List.

array : Monoid (Array a)

Monoid type for Array.

dict : Monoid (Dict comparable a)

Monoid type for Dict.

set : Monoid (Set comparable)

Monoid type for Set.

cmd : Monoid (Cmd comparable)

Monoid type for Cmd.

sub : Monoid (Sub comparable)

Monoid type for Sub.