Skip to content

Commit 8ec791f

Browse files
committed
Add "lift" from Semigroup into an Option Monoid
1 parent 4419ee3 commit 8ec791f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

core/src/main/java/fj/Semigroup.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ public Semigroup<A> dual() {
105105
return semigroup(flip(sum));
106106
}
107107

108+
/**
109+
* Lifts the semigroup to obtain a trivial monoid.
110+
*/
111+
public Monoid<Option<A>> lift() {
112+
return Monoid.monoid(a -> b -> Option.liftM2(sum).f(a).f(b).orElse(a).orElse(b), Option.none());
113+
}
114+
115+
/**
108116
* Constructs a semigroup from the given function.
109117
*
110118
* @param sum The function to construct this semigroup with.

0 commit comments

Comments
 (0)