2323 */
2424package io .github .dgroup .enumerable4j ;
2525
26- import java .util .ArrayList ;
2726import java .util .Collection ;
2827import java .util .HashSet ;
29- import java .util .List ;
3028import java .util .Set ;
3129import java .util .function .BinaryOperator ;
3230import java .util .function .Consumer ;
@@ -96,7 +94,7 @@ default boolean none(Predicate<X> first, Predicate<X>... other) {
9694 */
9795 default Enumerable <X > select (Predicate <X > first , Predicate <X >... other ) {
9896 return new Linked <>(
99- this .stream ().filter (new Joined <>(first , other ))
97+ this .stream ().filter (new Joined <>(first , other )). iterator ()
10098 );
10199 }
102100
@@ -121,7 +119,7 @@ default Enumerable<X> reject(Predicate<X> first, Predicate<X>... other) {
121119 }
122120 }
123121 }
124- return new Linked <>(this .stream ().filter (prd ));
122+ return new Linked <>(this .stream ().filter (prd ). iterator () );
125123 }
126124
127125 /**
@@ -158,12 +156,12 @@ default X find(X alt, Predicate<X> first, Predicate<X>... other) {
158156 * @param <Y> The type of target entity.
159157 * @return The enumerable.
160158 */
161- default <Y > Enumerable <Y > map (Function <? super X , ? extends Y > fnc ) {
159+ default <Y > Enumerable <Y > map (Function <? super X , Y > fnc ) {
162160 final Enumerable <Y > out ;
163161 if (fnc == null ) {
164162 out = new Empty <>();
165163 } else {
166- out = new Linked <>(this .stream ().map (fnc ));
164+ out = new Linked <>(this .stream ().map (fnc ). iterator () );
167165 }
168166 return out ;
169167 }
@@ -313,7 +311,7 @@ default Enumerable<X> take(long num) {
313311 } else if (num == 0 ) {
314312 out = new Empty <>();
315313 } else {
316- out = new Linked <>(this .stream ().limit (num ));
314+ out = new Linked <>(this .stream ().limit (num ). iterator () );
317315 }
318316 return out ;
319317 }
@@ -332,7 +330,7 @@ default Enumerable<X> drop(long num) {
332330 } else if (num == 0 ) {
333331 out = this ;
334332 } else {
335- out = new Linked <>(this .stream ().skip (num ));
333+ out = new Linked <>(this .stream ().skip (num ). iterator () );
336334 }
337335 return out ;
338336 }
@@ -372,15 +370,9 @@ default <Y> Enumerable<X> uniq(Function<? super X, ? extends Y> fnc) {
372370 out = new Empty <>();
373371 } else {
374372 final Set <Y > keys = new HashSet <>(0 );
375- final List <X > values = new ArrayList <>(0 );
376- for (final X val : this ) {
377- final Y key = fnc .apply (val );
378- if (!keys .contains (key )) {
379- keys .add (key );
380- values .add (val );
381- }
382- }
383- out = new Linked <>(values );
373+ out = new Linked <>(
374+ this .stream ().filter (val -> keys .add (fnc .apply (val ))).iterator ()
375+ );
384376 }
385377 return out ;
386378 }
0 commit comments