Package at.jku.ssw.fp.sect06_2
Class Monoids
- java.lang.Object
-
- at.jku.ssw.fp.sect06_2.Monoids
-
public class Monoids extends Object
Class with fields and methods providing monoid objects.- Author:
- Herbert Praehofer
-
-
Field Summary
Fields Modifier and Type Field Description static Monoid<Boolean>
booleanAndMonoid
The monoid for Boolean values, the and operator andtrue
as identity value.static Monoid<Boolean>
booleanOrMonoid
The monoid for Boolean values, the or operator andfalse
as identity value.static Monoid<Double>
doubleMultMonoid
The monoid for double values, the times operator and1.0
as identity value.static Monoid<Double>
doublePlusMonoid
The monoid for double values, the plus operator and0.0
as identity value.static Monoid<Integer>
intPlusMonoid
The monoid for integer values, the plus operator and0
as identity value.static Monoid<Integer>
intTimesMonoid
The monoid for integer values, the times operator and1
as identity value.static Monoid<String>
stringMonoid
The monoid for string values, the concatenation operator and""
as identity value.
-
Constructor Summary
Constructors Constructor Description Monoids()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <M> Monoid<M>
implicitMonoid(M m)
Returns a default monoid based on the type of a value.static <A> Monoid<List<A>>
listMonoid()
Creates a monoid object for list for a generic value setA
, the list concatenation operator and the empty list as identity value.static <K,V>
Monoid<Map<K,V>>mapMonoid(Monoid<V> vMonoid)
Creates a monoid for maps from a key to value where values are combined by the given monoid.static <E> Monoid<Optional<E>>
optionalMonoid(Monoid<E> eMonoid)
Creates a monoid for optional values where two values of non-empty optionals are combined by the given monoid.static <A> Monoid<Set<A>>
setMonoid()
Creates a monoid object for power sets for a generic value setA
, the union operator and the empty set as identity value.
-
-
-
Field Detail
-
doublePlusMonoid
public static Monoid<Double> doublePlusMonoid
The monoid for double values, the plus operator and0.0
as identity value.
-
doubleMultMonoid
public static Monoid<Double> doubleMultMonoid
The monoid for double values, the times operator and1.0
as identity value.
-
intPlusMonoid
public static Monoid<Integer> intPlusMonoid
The monoid for integer values, the plus operator and0
as identity value.
-
intTimesMonoid
public static Monoid<Integer> intTimesMonoid
The monoid for integer values, the times operator and1
as identity value.
-
stringMonoid
public static Monoid<String> stringMonoid
The monoid for string values, the concatenation operator and""
as identity value.
-
booleanAndMonoid
public static Monoid<Boolean> booleanAndMonoid
The monoid for Boolean values, the and operator andtrue
as identity value.
-
-
Method Detail
-
setMonoid
public static <A> Monoid<Set<A>> setMonoid()
Creates a monoid object for power sets for a generic value setA
, the union operator and the empty set as identity value.- Type Parameters:
A
- the type of values for the sets- Returns:
- the monoid object
-
listMonoid
public static <A> Monoid<List<A>> listMonoid()
Creates a monoid object for list for a generic value setA
, the list concatenation operator and the empty list as identity value.- Type Parameters:
A
- the type of values for the list elements- Returns:
- the monoid object
-
optionalMonoid
public static <E> Monoid<Optional<E>> optionalMonoid(Monoid<E> eMonoid)
Creates a monoid for optional values where two values of non-empty optionals are combined by the given monoid.- Type Parameters:
E
- the values contained in the optional- Parameters:
eMonoid
- the monoid for the contained values- Returns:
- the monoid for the optional values
-
mapMonoid
public static <K,V> Monoid<Map<K,V>> mapMonoid(Monoid<V> vMonoid)
Creates a monoid for maps from a key to value where values are combined by the given monoid. The monoid for the values is used to combine values when in both maps entries for the same key exist.- Type Parameters:
K
- the type of the keys in the mapV
- the type of the values in the map- Parameters:
vMonoid
- the monoid for combining values- Returns:
- the monoid for combining maps
-
implicitMonoid
public static <M> Monoid<M> implicitMonoid(M m)
Returns a default monoid based on the type of a value.- Type Parameters:
M
- the type of values- Parameters:
m
- a single value- Returns:
- a monoid for the value
-
-