Skip to content

Commit

Permalink
Add SingleStream::mapToTriplet
Browse files Browse the repository at this point in the history
  • Loading branch information
Pr3roxDLC committed Dec 10, 2022
1 parent 10df9e1 commit f7389bb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/main/java/me/pr3/Main.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package me.pr3;

import me.pr3.streams.api.streams.ISingleStream;
import me.pr3.streams.impl.TripletStream;

import java.util.Arrays;
import java.util.List;

public class Main {
public static void main(String[] args) {
System.out.println(new TripletStream<>(List.of(1, 2, 3), List.of("a", "b", "c"), List.of("", "", "")).toList());
System.out.println(new TripletStream<>(List.of(1, 2, 3), List.of("a", "b", "c"), List.of("", "", "")).mapSeparate(
a -> a,
b -> b.toUpperCase(),
c -> "test")
.peek((a,b,c) -> System.out.println(a)).toList()
);


System.out.println(Arrays.toString(ISingleStream.of("aaaaaaa", "bbbb", "ccccc")
.map(String::toUpperCase)
.toArray()));
}

}
2 changes: 2 additions & 0 deletions src/main/java/me/pr3/streams/api/streams/ISingleStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public interface ISingleStream<T>{

<A, B> IPairStream<A,B> mapToPair(Function<? super T, A> aFunction, Function<? super T, B> bFunction);

<A, B, C> ITripletStream<A,B, C> mapToTriplet(Function<? super T, A> aFunction, Function<? super T, B> bFunction, Function<? super T, C> cFunction);

IntStream mapToInt(ToIntFunction<? super T> mapper);

LongStream mapToLong(ToLongFunction<? super T> mapper);
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/me/pr3/streams/impl/SingleStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import me.pr3.streams.api.streams.IPairStream;
import me.pr3.streams.api.streams.ISingleStream;
import me.pr3.streams.api.streams.ITripletStream;
import org.apache.commons.collections4.ListUtils;

import java.util.*;
Expand Down Expand Up @@ -31,6 +32,19 @@ public <A, B> IPairStream<A, B> mapToPair(Function<? super T, A> aFunction, Func
return new PairStream<>(aList, bList);
}

@Override
public <A, B, C> ITripletStream<A, B, C> mapToTriplet(Function<? super T, A> aFunction, Function<? super T, B> bFunction, Function<? super T, C> cFunction) {
List<A> aList = new ArrayList<>();
List<B> bList = new ArrayList<>();
List<C> cList = new ArrayList<>();
stream.forEach(t ->{
aList.add(aFunction.apply(t));
bList.add(bFunction.apply(t));
cList.add(cFunction.apply(t));
});
return new TripletStream<>(aList, bList, cList);
}

@Override
public IntStream mapToInt(ToIntFunction<? super T> mapper) {
return stream.mapToInt(mapper);
Expand Down

0 comments on commit f7389bb

Please sign in to comment.