Skip to content

Commit d66ffc9

Browse files
committed
Add Linked constructor with stream parameter
1 parent 5cf2540 commit d66ffc9

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/main/java/io/github/dgroup/enumerable4j/Enumerable.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.util.function.Consumer;
3333
import java.util.function.Function;
3434
import java.util.function.Predicate;
35-
import java.util.stream.Collectors;
3635

3736
/**
3837
* The iterable with primitive operations witch simplify typical actions like count, map, etc.
@@ -93,7 +92,7 @@ default boolean none(Predicate<X> first, Predicate<X>... other) {
9392
*/
9493
default Enumerable<X> select(Predicate<X> first, Predicate<X>... other) {
9594
return new Linked<>(
96-
this.stream().filter(new Joined<>(first, other)).collect(Collectors.toList())
95+
this.stream().filter(new Joined<>(first, other))
9796
);
9897
}
9998

@@ -117,7 +116,7 @@ default Enumerable<X> reject(Predicate<X> first, Predicate<X>... other) {
117116
}
118117
}
119118
}
120-
return new Linked<>(this.stream().filter(prd).collect(Collectors.toList()));
119+
return new Linked<>(this.stream().filter(prd));
121120
}
122121

123122
/**
@@ -157,9 +156,7 @@ default <Y> Enumerable<Y> map(Function<? super X, ? extends Y> fnc) {
157156
if (fnc == null) {
158157
out = new Empty<>();
159158
} else {
160-
out = new Linked<>(
161-
this.stream().map(fnc).collect(Collectors.toList())
162-
);
159+
out = new Linked<>(this.stream().map(fnc));
163160
}
164161
return out;
165162
}
@@ -308,9 +305,7 @@ default Enumerable<X> take(long num) {
308305
} else if (num == 0) {
309306
out = new Empty<>();
310307
} else {
311-
out = new Linked<>(
312-
this.stream().limit(num).collect(Collectors.toList())
313-
);
308+
out = new Linked<>(this.stream().limit(num));
314309
}
315310
return out;
316311
}
@@ -329,9 +324,7 @@ default Enumerable<X> drop(long num) {
329324
} else if (num == 0) {
330325
out = this;
331326
} else {
332-
out = new Linked<>(
333-
this.stream().skip(num).collect(Collectors.toList())
334-
);
327+
out = new Linked<>(this.stream().skip(num));
335328
}
336329
return out;
337330
}

src/main/java/io/github/dgroup/enumerable4j/Linked.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424
package io.github.dgroup.enumerable4j;
2525

26+
import java.util.stream.Collectors;
27+
import java.util.stream.Stream;
2628
import org.cactoos.list.ListEnvelope;
2729
import org.cactoos.list.ListOf;
2830

@@ -50,4 +52,12 @@ public Linked(final X... src) {
5052
public Linked(final Iterable<X> src) {
5153
super(new ListOf<>(src));
5254
}
55+
56+
/**
57+
* Ctor.
58+
* @param stream The stream of source items.
59+
*/
60+
public Linked(final Stream<X> stream) {
61+
super(stream.collect(Collectors.toList()));
62+
}
5363
}

0 commit comments

Comments
 (0)