File tree Expand file tree Collapse file tree
src/main/java/fi/solita/utils/functional Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22 <modelVersion >4.0.0</modelVersion >
33 <groupId >fi.solita.utils</groupId >
44 <artifactId >functional-utils</artifactId >
5- <version >0.12.64 </version >
5+ <version >0.12.66 </version >
66 <build >
77 <resources >
88 <resource >
Original file line number Diff line number Diff line change 55import static fi .solita .utils .functional .Collections .newList ;
66import static fi .solita .utils .functional .Functional .concat ;
77
8+ import java .util .Collection ;
89import java .util .Comparator ;
910import java .util .List ;
1011import java .util .Map ;
@@ -81,6 +82,23 @@ public Iterable<T> zero() {
8182 };
8283 }
8384
85+ public static final <T > Monoid <Collection <T >> collectionConcat () {
86+ return new Monoid <Collection <T >>() {
87+ public Collection <T > apply (Map .Entry <? extends Collection <T >, ? extends Collection <T >> t ) {
88+ if (t .getKey () == null || t .getKey ().isEmpty ()) {
89+ return t .getValue ();
90+ } else if (t .getValue () == null || t .getValue ().isEmpty ()) {
91+ return t .getKey ();
92+ }
93+ return newList (concat (t .getKey (), t .getValue ()));
94+ }
95+
96+ public Collection <T > zero () {
97+ return emptyList ();
98+ }
99+ };
100+ }
101+
84102 public static final <T > Monoid <List <T >> listConcat () {
85103 return new Monoid <List <T >>() {
86104 public List <T > apply (Map .Entry <? extends List <T >, ? extends List <T >> t ) {
Original file line number Diff line number Diff line change @@ -111,6 +111,10 @@ public static final <T> SemiGroup<List<T>> listConcat() {
111111 return Monoids .listConcat ();
112112 }
113113
114+ public static final <T > SemiGroup <Collection <T >> collectionConcat () {
115+ return Monoids .collectionConcat ();
116+ }
117+
114118 public static final <T > SemiGroup <Iterable <T >> iterableConcat () {
115119 return Monoids .iterableConcat ();
116120 }
You can’t perform that action at this time.
0 commit comments