File tree Expand file tree Collapse file tree
src/main/java/com/jnape/palatable/lambda/functions/builtin/fn2 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66import static com .jnape .palatable .lambda .functions .builtin .fn1 .Tail .tail ;
77import static com .jnape .palatable .lambda .functions .builtin .fn2 .PrependAll .prependAll ;
88
9+ /**
10+ * Lazily inject the provided separator value between each value in the supplied <code>Iterable</code>. An empty
11+ * <code>Iterable</code> is left untouched.
12+ *
13+ * @param <A> the Iterable parameter type
14+ * @see PrependAll
15+ */
916public final class Intersperse <A > implements Fn2 <A , Iterable <A >, Iterable <A >> {
1017
1118 private static final Intersperse INSTANCE = new Intersperse ();
Original file line number Diff line number Diff line change 88import static com .jnape .palatable .lambda .functions .builtin .fn2 .Cons .cons ;
99import static java .util .Collections .emptyList ;
1010
11+ /**
12+ * Lazily prepend each value with of the <code>Iterable</code> with the supplied separator value. An empty
13+ * <code>Iterable</code> is left untouched.
14+ *
15+ * @param <A> the Iterable parameter type
16+ * @see Intersperse
17+ */
1118public final class PrependAll <A > implements Fn2 <A , Iterable <A >, Iterable <A >> {
1219
1320 private static final PrependAll INSTANCE = new PrependAll ();
Original file line number Diff line number Diff line change 66import java .util .Map ;
77import java .util .function .Supplier ;
88
9+ import static com .jnape .palatable .lambda .functions .builtin .fn3 .FoldLeft .foldLeft ;
10+
911/**
1012 * Given a {@link Supplier} of some {@link Map} <code>M</code>, create an instance of <code>M</code> and put
1113 * all of the entries in the provided <code>Iterable</code> into the instance. Note that instances of <code>M</code>
@@ -24,9 +26,10 @@ private ToMap() {
2426
2527 @ Override
2628 public M apply (Supplier <M > mSupplier , Iterable <Map .Entry <K , V >> entries ) {
27- M m = mSupplier .get ();
28- entries .forEach (kv -> m .put (kv .getKey (), kv .getValue ()));
29- return m ;
29+ return foldLeft ((m , kv ) -> {
30+ m .put (kv .getKey (), kv .getValue ());
31+ return m ;
32+ }, mSupplier .get (), entries );
3033 }
3134
3235 @ SuppressWarnings ("unchecked" )
You can’t perform that action at this time.
0 commit comments