Skip to content

Commit 5e9d170

Browse files
author
nedzad
committed
Refactor: migrate internal function handling from Function3 to FunctionRecord (record-based)
1 parent 2655c28 commit 5e9d170

20 files changed

Lines changed: 256 additions & 171 deletions

src/main/java/io/reactivex/rxjava4/core/Flowable.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ public static int bufferSize() {
750750
public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull R> Flowable<R> combineLatest(
751751
@NonNull Publisher<? extends T1> source1, @NonNull Publisher<? extends T2> source2,
752752
@NonNull Publisher<? extends T3> source3,
753-
@NonNull Function3<? super T1, ? super T2, ? super T3, ? extends R> combiner) {
753+
@NonNull FunctionRecord< Args3<T1, T2, T3>, ? extends R> combiner) {
754754
Objects.requireNonNull(source1, "source1 is null");
755755
Objects.requireNonNull(source2, "source2 is null");
756756
Objects.requireNonNull(source3, "source3 is null");
@@ -5342,7 +5342,7 @@ public static Flowable<Long> timer(long delay, @NonNull TimeUnit unit, @NonNull
53425342
@SchedulerSupport(SchedulerSupport.NONE)
53435343
public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull R> Flowable<R> zip(
53445344
@NonNull Publisher<? extends T1> source1, @NonNull Publisher<? extends T2> source2, @NonNull Publisher<? extends T3> source3,
5345-
@NonNull Function3<? super T1, ? super T2, ? super T3, ? extends R> zipper) {
5345+
@NonNull FunctionRecord< Args3<T1, T2, T3>, ? extends R> zipper) {
53465346
Objects.requireNonNull(source1, "source1 is null");
53475347
Objects.requireNonNull(source2, "source2 is null");
53485348
Objects.requireNonNull(source3, "source3 is null");
@@ -19644,7 +19644,7 @@ public final Flowable<Flowable<T>> window(
1964419644
@BackpressureSupport(BackpressureKind.PASS_THROUGH)
1964519645
@SchedulerSupport(SchedulerSupport.NONE)
1964619646
public final <@NonNull T1, @NonNull T2, @NonNull R> Flowable<R> withLatestFrom(@NonNull Publisher<T1> source1, @NonNull Publisher<T2> source2,
19647-
@NonNull Function3<? super T, ? super T1, ? super T2, R> combiner) {
19647+
@NonNull FunctionRecord< Args3<T, T1, T2>, R> combiner) {
1964819648
Objects.requireNonNull(source1, "source1 is null");
1964919649
Objects.requireNonNull(source2, "source2 is null");
1965019650
Objects.requireNonNull(combiner, "combiner is null");

src/main/java/io/reactivex/rxjava4/core/Maybe.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2402,7 +2402,7 @@ public static Maybe<Long> timer(long delay, @NonNull TimeUnit unit, @NonNull Sch
24022402
@SchedulerSupport(SchedulerSupport.NONE)
24032403
public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull R> Maybe<R> zip(
24042404
@NonNull MaybeSource<? extends T1> source1, @NonNull MaybeSource<? extends T2> source2, @NonNull MaybeSource<? extends T3> source3,
2405-
@NonNull Function3<? super T1, ? super T2, ? super T3, ? extends R> zipper) {
2405+
@NonNull FunctionRecord< Args3<T1, T2, T3>, ? extends R> zipper) {
24062406
Objects.requireNonNull(source1, "source1 is null");
24072407
Objects.requireNonNull(source2, "source2 is null");
24082408
Objects.requireNonNull(source3, "source3 is null");

src/main/java/io/reactivex/rxjava4/core/Observable.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ public static int bufferSize() {
466466
public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull R> Observable<R> combineLatest(
467467
@NonNull ObservableSource<? extends T1> source1, @NonNull ObservableSource<? extends T2> source2,
468468
@NonNull ObservableSource<? extends T3> source3,
469-
@NonNull Function3<? super T1, ? super T2, ? super T3, ? extends R> combiner) {
469+
@NonNull FunctionRecord< Args3<T1, T2, T3>, ? extends R> combiner) {
470470
Objects.requireNonNull(source1, "source1 is null");
471471
Objects.requireNonNull(source2, "source2 is null");
472472
Objects.requireNonNull(source3, "source3 is null");
@@ -4803,7 +4803,7 @@ public static Observable<Long> timer(long delay, @NonNull TimeUnit unit, @NonNul
48034803
public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull R> Observable<R> zip(
48044804
@NonNull ObservableSource<? extends T1> source1, @NonNull ObservableSource<? extends T2> source2,
48054805
@NonNull ObservableSource<? extends T3> source3,
4806-
@NonNull Function3<? super T1, ? super T2, ? super T3, ? extends R> zipper) {
4806+
@NonNull FunctionRecord< Args3<T1, T2, T3>, ? extends R> zipper) {
48074807
Objects.requireNonNull(source1, "source1 is null");
48084808
Objects.requireNonNull(source2, "source2 is null");
48094809
Objects.requireNonNull(source3, "source3 is null");
@@ -16467,7 +16467,7 @@ public final Observable<Observable<T>> window(
1646716467
@NonNull
1646816468
public final <@NonNull T1, @NonNull T2, @NonNull R> Observable<R> withLatestFrom(
1646916469
@NonNull ObservableSource<T1> source1, @NonNull ObservableSource<T2> source2,
16470-
@NonNull Function3<? super T, ? super T1, ? super T2, R> combiner) {
16470+
@NonNull FunctionRecord< Args3<T, T1, T2>, R> combiner) {
1647116471
Objects.requireNonNull(source1, "source1 is null");
1647216472
Objects.requireNonNull(source2, "source2 is null");
1647316473
Objects.requireNonNull(combiner, "combiner is null");

src/main/java/io/reactivex/rxjava4/core/Single.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2165,7 +2165,7 @@ public static Single<Long> timer(long delay, @NonNull TimeUnit unit, @NonNull Sc
21652165
public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull R> Single<R> zip(
21662166
@NonNull SingleSource<? extends T1> source1, @NonNull SingleSource<? extends T2> source2,
21672167
@NonNull SingleSource<? extends T3> source3,
2168-
@NonNull Function3<? super T1, ? super T2, ? super T3, ? extends R> zipper
2168+
@NonNull FunctionRecord< Args3<T1, T2, T3>, ? extends R> zipper
21692169
) {
21702170
Objects.requireNonNull(source1, "source1 is null");
21712171
Objects.requireNonNull(source2, "source2 is null");
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.reactivex.rxjava4.functions;
2+
3+
import io.reactivex.rxjava4.annotations.NonNull;
4+
5+
public record Args3<T1, T2, T3>(
6+
@NonNull T1 t1,
7+
@NonNull T2 t2,
8+
@NonNull T3 t3
9+
) {}

src/main/java/io/reactivex/rxjava4/functions/Function3.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
package io.reactivex.rxjava4.functions;
1515

1616
import io.reactivex.rxjava4.annotations.NonNull;
17-
1817
/**
1918
* A functional interface (callback) that computes a value based on multiple input values.
2019
* @param <T1> the first value type
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2016-present, RxJava Contributors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5+
* compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is
10+
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11+
* the License for the specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package io.reactivex.rxjava4.functions;
15+
16+
import io.reactivex.rxjava4.annotations.NonNull;
17+
18+
/**
19+
* A functional interface (callback) that computes a value based on multiple input values.
20+
* @param <T1> the first value type
21+
22+
* @param <R> the result type
23+
*/
24+
@FunctionalInterface
25+
public interface FunctionRecord<@NonNull T1 extends Record, @NonNull R> {
26+
/**
27+
* Calculate a value based on the input values.
28+
* @param t1 the first value
29+
30+
* @return the result value
31+
* @throws Throwable if the implementation wishes to throw any type of exception
32+
*/
33+
R apply(T1 t1) throws Throwable;
34+
}

src/main/java/io/reactivex/rxjava4/internal/functions/Functions.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static <T1, T2, R> Function<Object[], R> toFunction(@NonNull BiFunction<?
4141
}
4242

4343
@NonNull
44-
public static <T1, T2, T3, R> Function<Object[], R> toFunction(@NonNull Function3<T1, T2, T3, R> f) {
44+
public static <T1, T2, T3, R> Function<Object[], R> toFunction(@NonNull FunctionRecord<Args3<T1, T2,T3>,R> f) {
4545
return new Array3Func<>(f);
4646
}
4747

@@ -546,19 +546,25 @@ public R apply(Object[] a) throws Throwable {
546546
}
547547

548548
static final class Array3Func<T1, T2, T3, R> implements Function<Object[], R> {
549-
final Function3<T1, T2, T3, R> f;
550-
551-
Array3Func(Function3<T1, T2, T3, R> f) {
552-
this.f = f;
549+
// final Function3<T1, T2, T3, R> f;
550+
final FunctionRecord<Args3<T1, T2,T3>,R> Fr;
551+
//
552+
// Array3Func(Function3<T1, T2, T3, R> f) {
553+
// this.f = f;
554+
// }
555+
Array3Func(FunctionRecord<Args3<T1, T2,T3>,R> fr)
556+
{
557+
this.Fr = fr;
553558
}
554559

560+
555561
@SuppressWarnings("unchecked")
556562
@Override
557563
public R apply(Object[] a) throws Throwable {
558564
if (a.length != 3) {
559565
throw new IllegalArgumentException("Array of size 3 expected but got " + a.length);
560566
}
561-
return f.apply((T1)a[0], (T2)a[1], (T3)a[2]);
567+
return Fr.apply(new Args3<>((T1)a[0], (T2)a[1], (T3)a[2]));
562568
}
563569
}
564570

src/main/java/io/reactivex/rxjava4/internal/operators/flowable/FlowableOnErrorNext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
public final class FlowableOnErrorNext<T> extends AbstractFlowableWithUpstream<T, T> {
2727
final Function<? super Throwable, ? extends Publisher<? extends T>> nextSupplier;
2828

29+
30+
2931
public FlowableOnErrorNext(Flowable<T> source,
3032
Function<? super Throwable, ? extends Publisher<? extends T>> nextSupplier) {
3133
super(source);

src/test/java/io/reactivex/rxjava4/internal/functions/FunctionsTest.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,30 @@ public Integer apply(Integer t1, Integer t2) throws Exception {
103103
}).apply(new Object[20]);
104104
}
105105

106+
// @Test(expected = IllegalArgumentException.class)
107+
// public void toFunction3() throws Throwable {
108+
// Functions.toFunction(new Function3<Integer, Integer, Integer, Integer>() {
109+
// @Override
110+
// public Integer apply(Integer t1, Integer t2, Integer t3) throws Exception {
111+
// return null;
112+
// }
113+
// }).apply(new Object[20]);
114+
// }
115+
106116
@Test(expected = IllegalArgumentException.class)
107117
public void toFunction3() throws Throwable {
108-
Functions.toFunction(new Function3<Integer, Integer, Integer, Integer>() {
109-
@Override
110-
public Integer apply(Integer t1, Integer t2, Integer t3) throws Exception {
111-
return null;
112-
}
113-
}).apply(new Object[20]);
118+
// Functions.toFunction((Args3<Integer, Integer, Integer> Integer) {
119+
// @Override
120+
// public Integer apply(Integer t1, Integer t2, Integer t3) throws Exception {
121+
// return null;
122+
// }
123+
// }).apply(new Object[20]);
124+
Functions.toFunction( new FunctionRecord<Args3<Integer, Integer, Integer>, Integer>() {
125+
@Override
126+
public Integer apply(Args3<Integer, Integer, Integer> integerIntegerIntegerArgs3) throws Throwable {
127+
return null;
128+
}
129+
}).apply(new Object[20]);
114130
}
115131

116132
@Test(expected = IllegalArgumentException.class)

0 commit comments

Comments
 (0)