Skip to content

Commit f89381d

Browse files
committed
Add "first" and "last" semigroups
1 parent 6892c93 commit f89381d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,20 @@ public static <A> Semigroup<A> semigroup(final F2<A, A, A> sum) {
264264
public static final Semigroup<StringBuilder> stringBuilderSemigroup =
265265
semigroup((s1, s2) -> new StringBuilder(s1).append(s2));
266266

267+
/**
268+
* A semigroup which always uses the "first" (left-hand side) value.
269+
*/
270+
public static <A> Semigroup<A> firstSemigroup() {
271+
return semigroup((a1, a2) -> a1);
272+
}
273+
274+
/**
275+
* A semigroup which always uses the "last" (right-hand side) value.
276+
*/
277+
public static <A> Semigroup<A> lastSemigroup() {
278+
return semigroup((a1, a2) -> a2);
279+
}
280+
267281
/**
268282
* A semigroup for functions.
269283
*

0 commit comments

Comments
 (0)