Methods
(static) mappend(a, b) → {Object}
Perform an associative operation (similar to appending to a list) on two monoids.
Haskell> mappend :: a -> a -> a
Parameters:
Name | Type | Description |
---|---|---|
a |
Object | Any monoid |
b |
Object | Any monoid |
Returns:
A new monoid of the same type, the result of the associative operation
- Type
- Object
Example
const l1 = list(1,2,3); // => [1:2:3:[]]
const l2 = list(4,5,6); // => [4:5:6:[]]
const l3 = list(7,8,9); // => [7:8:9:[]]
mappend(mempty(l1), l1); // => [1:2:3:[]]
mappend(l1, mappend(l2, l3)); // => [1:2:3:4:5:6:7:8:9:[]]
mappend(mappend(l1, l2), l3); // => [1:2:3:4:5:6:7:8:9:[]]
(static) mconcat(a) → {Object}
Fold a list using the monoid. Concatenates a list of monoids into a single list. Since lists
themselves are monoids, for example, mconcat
will flatten a list of lists into a single list.
Haskell> mconcat :: [a] -> a
Parameters:
Name | Type | Description |
---|---|---|
a |
Object | Any monoid |
Returns:
A new monoid of the same type, the result of the concatenation
- Type
- Object
Example
const l1 = list(1,2,3); // => [1:2:3:[]]
const l2 = list(4,5,6); // => [4:5:6:[]]
const l3 = list(7,8,9); // => [7:8:9:[]]
const ls = list(l1,l2,l3); // => [[1:2:3:[]]:[4:5:6:[]]:[7:8:9:[]]:[]]
mconcat(ls); // => [1:2:3:4:5:6:7:8:9:[]]
(static) mempty(a) → {Object}
Return the identity (or "empty") value for the monoid.
Haskell> mempty :: a
Parameters:
Name | Type | Description |
---|---|---|
a |
Object | Any monoid |
Returns:
Identity value for the monoid
- Type
- Object
Example
const mb = just(1);
const tup = tuple(1,2);
const lst = list(1,2,3);
mempty(mb); // => Nothing
mempty(tup); // => ()
mempty(lst); // => [[]]
(static) Monoid() → {boolean}
A Monoid
is a type with an associative binary operation that has an identity. In plainer
language, a monoid is any type that has an "empty" value that, when "appended" to any other value
of that type, equals that same value. For example, an integer is a monoid, because any integer
added to 0, the "empty" value, equals that integer. Likewise, a list is a monoid, because any
list appended to the empty list equals the original list. Monoids must define mempty
and
mappend
methods.
Parameters:
Type | Description |
---|---|
* | Any object |
Returns:
true
if an object is an instance of Monoid
and false
otherwise
- Type
- boolean