Interface Monoid<A>
-
- Type Parameters:
A
- the element type this Monoid is formed over
- All Superinterfaces:
Applicative<Fn1<A,A>,Fn1<A,?>>
,Cartesian<A,Fn1<A,A>,Fn1<?,?>>
,Cocartesian<A,Fn1<A,A>,Fn1<?,?>>
,Contravariant<A,Profunctor<?,Fn1<A,A>,Fn1<?,?>>>
,Fn1<A,Fn1<A,A>>
,Fn2<A,A,A>
,Functor<Fn1<A,A>,Fn1<A,?>>
,Monad<Fn1<A,A>,Fn1<A,?>>
,MonadReader<A,Fn1<A,A>,Fn1<A,?>>
,MonadRec<Fn1<A,A>,Fn1<A,?>>
,MonadWriter<A,Fn1<A,A>,Fn1<A,?>>
,Profunctor<A,Fn1<A,A>,Fn1<?,?>>
,Semigroup<A>
- All Known Implementing Classes:
And
,Concat
,Endo
,First
,Join
,Last
,MergeHMaps
,Or
,PutAll
,Trivial
,Union
,Xor
public interface Monoid<A> extends Semigroup<A>
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Monoid<A>
flip()
Flip the order of the arguments.default A
foldLeft(A a, java.lang.Iterable<A> as)
Catamorphism under this semigroup usingFoldLeft
, where the binary operator is this semigroup, and the starting accumulator is provided.default <B> A
foldMap(Fn1<? super B,? extends A> fn, java.lang.Iterable<B> bs)
Homomorphism combined with catamorphism.default Lazy<A>
foldRight(A a, java.lang.Iterable<A> as)
Catamorphism under this semigroup usingFoldRight
, where the binary operator is this semigroup, and the starting accumulator is provided.A
identity()
The identity element of this monoid.static <A> Monoid<A>
monoid(Semigroup<A> semigroup, A identity)
static <A> Monoid<A>
monoid(Semigroup<A> semigroup, Fn0<A> identityFn0)
default A
reduceLeft(java.lang.Iterable<A> as)
Catamorphism under this monoid usingReduceLeft
, where the result is the reduction, or, if empty, the identity of this monoid.default A
reduceRight(java.lang.Iterable<A> as)
Catamorphism under this monoid usingReduceRight
, where the result is the reduction, or, if empty, the identity of this monoid.-
Methods inherited from interface com.jnape.palatable.lambda.functions.Fn1
andThen, carry, cartesian, censor, choose, cocartesian, diMap, diMapR, discardL, flatMap, fmap, lazyZip, listens, local, pure, self, thunk, toFunction, trampolineM, zip, zip
-
Methods inherited from interface com.jnape.palatable.lambda.functions.Fn2
apply, apply, checkedApply, checkedApply, compose, contraMap, diMapL, discardR, toBiFunction, uncurry, widen
-
-
-
-
Method Detail
-
identity
A identity()
The identity element of this monoid.- Returns:
- the identity
-
reduceLeft
default A reduceLeft(java.lang.Iterable<A> as)
Catamorphism under this monoid usingReduceLeft
, where the result is the reduction, or, if empty, the identity of this monoid.- Parameters:
as
- the elements to reduce- Returns:
- the reduction, or
identity()
if empty - See Also:
ReduceLeft
-
reduceRight
default A reduceRight(java.lang.Iterable<A> as)
Catamorphism under this monoid usingReduceRight
, where the result is the reduction, or, if empty, the identity of this monoid.- Parameters:
as
- an Iterable of elements in this monoid- Returns:
- the reduction, or
identity()
if empty - See Also:
ReduceRight
-
foldMap
default <B> A foldMap(Fn1<? super B,? extends A> fn, java.lang.Iterable<B> bs)
Homomorphism combined with catamorphism. Convert anIterable<B>
to anIterable<A>
(that is, anIterable
of elements this monoid is formed over), then reduce the result from left to right. Under algebraic data types, this is isomorphic to a flatMap.- Type Parameters:
B
- the input Iterable element type- Parameters:
fn
- the mapping function from A to Bbs
- the Iterable of Bs- Returns:
- the folded result under this Monoid
- See Also:
Map
,reduceLeft(Iterable)
-
foldLeft
default A foldLeft(A a, java.lang.Iterable<A> as)
Catamorphism under this semigroup usingFoldLeft
, where the binary operator is this semigroup, and the starting accumulator is provided.
-
foldRight
default Lazy<A> foldRight(A a, java.lang.Iterable<A> as)
Catamorphism under this semigroup usingFoldRight
, where the binary operator is this semigroup, and the starting accumulator is provided.
-
monoid
static <A> Monoid<A> monoid(Semigroup<A> semigroup, A identity)
- Type Parameters:
A
- the element type of this monoid- Parameters:
semigroup
- the semigroupidentity
- the identity element- Returns:
- the monoid
-
-