Skip to content

Commit 87d9b30

Browse files
committed
Stream: Avoid unecessary currying in uncurried version of foldRight.
1 parent bd665e1 commit 87d9b30

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

core/src/main/java/fj/data/Stream.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public final <B> B uncons(final B nil, final F<A, F<P1<Stream<A>>, B>> cons) {
119119
* @return The final result after the right-fold reduction.
120120
*/
121121
public final <B> B foldRight(final F<A, F<P1<B>, B>> f, final B b) {
122-
return isEmpty() ? b : f.f(head()).f(P.lazy(() -> tail()._1().foldRight(f, b)));
122+
return foldRight(uncurryF2(f), b);
123123
}
124124

125125
/**
@@ -130,7 +130,7 @@ public final <B> B foldRight(final F<A, F<P1<B>, B>> f, final B b) {
130130
* @return The final result after the right-fold reduction.
131131
*/
132132
public final <B> B foldRight(final F2<A, P1<B>, B> f, final B b) {
133-
return foldRight(curry(f), b);
133+
return isEmpty() ? b : f.f(head(), P.lazy(() -> tail()._1().foldRight(f, b)));
134134
}
135135

136136
/**
@@ -141,7 +141,7 @@ public final <B> B foldRight(final F2<A, P1<B>, B> f, final B b) {
141141
* @return The final result after the right-fold reduction.
142142
*/
143143
public final <B> B foldRight1(final F<A, F<B, B>> f, final B b) {
144-
return foldRight(compose(Function.<P1<B>, B, B>andThen().f(P1.__1()), f), b);
144+
return foldRight1(uncurryF2(f), b);
145145
}
146146

147147
/**
@@ -152,7 +152,7 @@ public final <B> B foldRight1(final F<A, F<B, B>> f, final B b) {
152152
* @return The final result after the right-fold reduction.
153153
*/
154154
public final <B> B foldRight1(final F2<A, B, B> f, final B b) {
155-
return foldRight1(curry(f), b);
155+
return isEmpty() ? b : f.f(head(), tail()._1().foldRight1(f, b));
156156
}
157157

158158
/**

0 commit comments

Comments
 (0)