Skip to content

Commit 1179bfd

Browse files
all move explanations why methods are not present in Observable to CompletenessTest
1 parent b051f09 commit 1179bfd

File tree

2 files changed

+2
-105
lines changed

2 files changed

+2
-105
lines changed

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/Observable.scala

Lines changed: 1 addition & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,6 @@ class Observable[+T](val asJava: rx.Observable[_ <: T])
200200
Observable[(T, U)](JObservable.zip[T, U, (T, U)](this.asJava, that.asJava, (t: T, u: U) => (t, u)))
201201
}
202202

203-
// There is no method corresponding to
204-
// public static <T> Observable<Boolean> sequenceEqual(Observable<? extends T> first, Observable<? extends T> second)
205-
// because the Scala-idiomatic way of doing this is
206-
// (first zip second) map (p => p._1 == p._2)
207-
208-
// There is no method corresponding to
209-
// public static <T> Observable<Boolean> sequenceEqual(Observable<? extends T> first, Observable<? extends T> second, Func2<? super T, ? super T, Boolean> equality)
210-
// because the Scala-idiomatic way of doing this is
211-
// (first zip second) map (p => equality(p._1, p._2))
212-
213203
/**
214204
* Creates an Observable which produces buffers of collected values.
215205
*
@@ -673,10 +663,6 @@ class Observable[+T](val asJava: rx.Observable[_ <: T])
673663
Observable[R](asJava.flatMap[R]((t: T) => f(t).asJava))
674664
}
675665

676-
// There is no method like
677-
// public Observable<T> where(Func1<? super T, Boolean> predicate)
678-
// because that's called filter in Scala.
679-
680666
/**
681667
* Returns an Observable that applies the given function to each item emitted by an
682668
* Observable and emits the result.
@@ -692,10 +678,6 @@ class Observable[+T](val asJava: rx.Observable[_ <: T])
692678
Observable[R](asJava.map[R](func))
693679
}
694680

695-
// There's no method like
696-
// public <R> Observable<R> mapMany(Func1<? super T, ? extends Observable<? extends R>> func)
697-
// because that's called flatMap in Scala.
698-
699681
/**
700682
* Turns all of the notifications from a source Observable into {@link Observer#onNext onNext} emissions, and marks them with their original notification types within {@link Notification} objects.
701683
* <p>
@@ -948,10 +930,6 @@ class Observable[+T](val asJava: rx.Observable[_ <: T])
948930
(() => javaCO.connect(), Observable[T](javaCO))
949931
}
950932

951-
// There is no aggregate function with signature
952-
// public Observable<T> aggregate(Func2<? super T, ? super T, ? extends T> accumulator)
953-
// because that's called reduce in Scala.
954-
955933
// TODO add Scala-like aggregate function
956934

957935
/**
@@ -980,13 +958,6 @@ class Observable[+T](val asJava: rx.Observable[_ <: T])
980958
def fold[R](initialValue: R)(accumulator: (R, T) => R): Observable[R] = {
981959
Observable[R](asJava.reduce(initialValue, accumulator))
982960
}
983-
// corresponds to Java's
984-
// public <R> Observable<R> reduce(R initialValue, Func2<? super R, ? super T, ? extends R> accumulator)
985-
// public <R> Observable<R> aggregate(R initialValue, Func2<? super R, ? super T, ? extends R> accumulator)
986-
987-
// There is no method like
988-
// public Observable<T> scan(Func2<? super T, ? super T, ? extends T> accumulator)
989-
// because scan has a seed in Scala
990961

991962
/**
992963
* Returns an Observable that emits the results of sampling the items emitted by the source
@@ -1024,7 +995,7 @@ class Observable[+T](val asJava: rx.Observable[_ <: T])
1024995
Observable[T](asJava.sample(duration.length, duration.unit, scheduler))
1025996
}
1026997

1027-
/**
998+
/**
1028999
* Returns an Observable that applies a function of your choosing to the first item emitted by a
10291000
* source Observable, then feeds the result of that function along with the second item emitted
10301001
* by an Observable into the same function, and so on until all items have been emitted by the
@@ -1048,8 +1019,6 @@ class Observable[+T](val asJava: rx.Observable[_ <: T])
10481019
def scan[R](initialValue: R)(accumulator: (R, T) => R): Observable[R] = {
10491020
Observable[R](asJava.scan(initialValue, accumulator))
10501021
}
1051-
// corresponds to Scala's
1052-
// public <R> Observable<R> scan(R initialValue, Func2<? super R, ? super T, ? extends R> accumulator)
10531022

10541023
/**
10551024
* Returns an Observable that emits a Boolean that indicates whether all of the items emitted by
@@ -1068,8 +1037,6 @@ class Observable[+T](val asJava: rx.Observable[_ <: T])
10681037
// it's more fun in Scala:
10691038
this.map(predicate).fold(true)(_ && _)
10701039
}
1071-
// corresponds to Java's
1072-
// public Observable<Boolean> all(Func1<? super T, Boolean> predicate)
10731040

10741041
/**
10751042
* Returns an Observable that skips the first <code>num</code> items emitted by the source
@@ -1088,8 +1055,6 @@ class Observable[+T](val asJava: rx.Observable[_ <: T])
10881055
def drop(n: Int): Observable[T] = {
10891056
Observable[T](asJava.skip(n))
10901057
}
1091-
// corresponds to Java's
1092-
// public Observable<T> skip(int num)
10931058

10941059
/**
10951060
* Returns an Observable that emits only the first <code>num</code> items emitted by the source
@@ -1165,8 +1130,6 @@ class Observable[+T](val asJava: rx.Observable[_ <: T])
11651130
def takeRight(n: Int): Observable[T] = {
11661131
Observable[T](asJava.takeLast(n))
11671132
}
1168-
// corresponds to Java's
1169-
// public Observable<T> takeLast(final int count)
11701133

11711134
/**
11721135
* Returns an Observable that emits the items from the source Observable only until the
@@ -1207,16 +1170,6 @@ class Observable[+T](val asJava: rx.Observable[_ <: T])
12071170
Observable.jObsOfListToScObsOfSeq(asJava.toList())
12081171
: Observable[Seq[T]] // SI-7818
12091172
}
1210-
// corresponds to Java's method
1211-
// public Observable<List<T>> toList() {
1212-
1213-
// There are no toSortedList methods because Scala can sort itself
1214-
// public Observable<List<T>> toSortedList()
1215-
// public Observable<List<T>> toSortedList(Func2<? super T, ? super T, Integer> sortFunction)
1216-
1217-
// There is no method
1218-
// def startWith[U >: T](values: U*): Observable[U]
1219-
// because we can just use ++ instead
12201173

12211174
/**
12221175
* Groups the items emitted by this Observable according to a specified discriminator function.
@@ -1233,10 +1186,6 @@ class Observable[+T](val asJava: rx.Observable[_ <: T])
12331186
val func = (o: rx.observables.GroupedObservable[K, _ <: T]) => (o.getKey(), Observable[T](o))
12341187
Observable[(K, Observable[T])](o1.map[(K, Observable[T])](func))
12351188
}
1236-
1237-
// There's no method corresponding to
1238-
// public <K, R> Observable<GroupedObservable<K, R>> groupBy(final Func1<? super T, ? extends K> keySelector, final Func1<? super T, ? extends R> elementSelector)
1239-
// because this can be obtained by combining groupBy and map (as in Scala)
12401189

12411190
/**
12421191
* Given an Observable that emits Observables, creates a single Observable that
@@ -1505,12 +1454,6 @@ object Observable {
15051454
def apply[T](func: Observer[T] => Subscription): Observable[T] = {
15061455
Observable[T](JObservable.create(func))
15071456
}
1508-
// corresponds to Java's
1509-
// public static <T> Observable<T> create(OnSubscribeFunc<T> func)
1510-
1511-
// Java's
1512-
// public static <T> Observable<T> empty()
1513-
// is not needed in Scala because it's a special case of varargs apply
15141457

15151458
/**
15161459
* Returns an Observable that invokes an {@link Observer}'s {@link Observer#onError onError} method when the Observer subscribes to it
@@ -1526,12 +1469,6 @@ object Observable {
15261469
def apply(exception: Throwable): Observable[Nothing] = {
15271470
Observable[Nothing](JObservable.error(exception))
15281471
}
1529-
// corresponds to Java's
1530-
// public static <T> Observable<T> error(Throwable exception)
1531-
1532-
// There is no method corresponding to
1533-
// public static <T> Observable<T> from(Iterable<? extends T> iterable)
1534-
// because Scala automatically uses the varargs apply for this
15351472

15361473
/**
15371474
* Converts a sequence of values into an Observable.
@@ -1551,18 +1488,11 @@ object Observable {
15511488
def apply[T](args: T*): Observable[T] = {
15521489
Observable[T](JObservable.from(args.toIterable.asJava))
15531490
}
1554-
// corresponds to Java's
1555-
// public static <T> Observable<T> from(T... items)
15561491

15571492
def apply(range: Range): Observable[Int] = {
15581493
Observable[Int](JObservable.from(range.toIterable.asJava))
15591494
}
15601495

1561-
// There is no method corresponding to
1562-
// public static Observable<Integer> range(int start, int count)
1563-
// because the Scala collection library provides enough methods to create Iterables.
1564-
// Examples: Observable(1 to 5), Observable(1 until 10)
1565-
15661496
/**
15671497
* Returns an Observable that calls an Observable factory to create its Observable for each
15681498
* new Observer that subscribes. That is, for each subscriber, the actuall Observable is determined
@@ -1586,8 +1516,6 @@ object Observable {
15861516
def defer[T](observable: => Observable[T]): Observable[T] = {
15871517
Observable[T](JObservable.defer(observable.asJava))
15881518
}
1589-
// corresponds to Java's
1590-
// public static <T> Observable<T> defer(Func0<? extends Observable<? extends T>> observableFactory)
15911519

15921520
/**
15931521
* Returns an Observable that emits a single item and then completes.
@@ -1611,16 +1539,10 @@ object Observable {
16111539
def just[T](value: T): Observable[T] = {
16121540
Observable[T](JObservable.just(value))
16131541
}
1614-
// corresponds to Java's
1615-
// public static <T> Observable<T> just(T value)
16161542

16171543
// TODO we have merge and concat (++) as binary instance methods, but do we also need them as
16181544
// static methods with arity > 2?
16191545

1620-
// There is no method corresponding to
1621-
// public static <T> Observable<T> concat(Observable<? extends T>... source)
1622-
// because we have the instance method ++ instead
1623-
16241546
/**
16251547
* This behaves like {@link #merge(java.util.List)} except that if any of the merged Observables
16261548
* notify of an error via {@link Observer#onError onError}, {@code mergeDelayError} will
@@ -1703,49 +1625,23 @@ object Observable {
17031625
Observable[Nothing](JObservable.never())
17041626
}
17051627

1706-
// There is no method corresponding to
1707-
// public static <T> Observable<T> switchDo(Observable<? extends Observable<? extends T>> sequenceOfSequences)
1708-
// because it's deprecated.
1709-
1710-
// There's no
1711-
// public static <T> Observable<T> switchOnNext(Observable<? extends Observable<? extends T>> sequenceOfSequences)
1712-
// here because that's an instance method.
1713-
1714-
// There is no method here corresponding to
1715-
// public static <T> Observable<T> synchronize(Observable<? extends T> observable)
1716-
// because that's an instance method.
1717-
17181628
/*
17191629
def apply[T](f: Future[T]): Observable[T] = {
17201630
??? // TODO convert Scala Future to Java Future
17211631
}
17221632
*/
1723-
// corresponds to
1724-
// public static <T> Observable<T> from(Future<? extends T> future)
17251633

17261634
/*
17271635
def apply[T](f: Future[T], scheduler: Scheduler): Observable[T] = {
17281636
??? // TODO convert Scala Future to Java Future
17291637
}
17301638
*/
1731-
// public static <T> Observable<T> from(Future<? extends T> future, Scheduler scheduler)
17321639

17331640
/*
17341641
def apply[T](f: Future[T], duration: Duration): Observable[T] = {
17351642
??? // TODO convert Scala Future to Java Future
17361643
}
17371644
*/
1738-
// corresponds to
1739-
// public static <T> Observable<T> from(Future<? extends T> future, long timeout, TimeUnit unit)
1740-
1741-
// There is no method here corresponding to
1742-
// public static <T1, T2, R> Observable<R> zip(Observable<? extends T1> o1, Observable<? extends T2> o2, Func2<? super T1, ? super T2, ? extends R> zipFunction)
1743-
// because it's an instance method
1744-
1745-
// There is no method corresponding to
1746-
// public static <T1, T2, T3, R> Observable<R> zip(Observable<? extends T1> o1, Observable<? extends T2> o2, Observable<? extends T3> o3, Func3<? super T1, ? super T2, ? super T3, ? extends R> zipFunction)
1747-
// because zip3 is not known in the Scala world
1748-
// Also applies to all zipN with N > 3 ;-)
17491645

17501646
/**
17511647
* Combines the given observables, emitting an event containing an aggregation of the latest values of each of the source observables

language-adaptors/rxjava-scala/src/test/scala/rx/lang/scala/CompletenessTest.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class CompletenessTest extends JUnitSuite {
3535
"skipWhile(Func1[_ >: T, Boolean])" -> "dropWhile(T => Boolean)",
3636
"skipWhileWithIndex(Func2[_ >: T, Integer, Boolean])" -> unnecessary,
3737
"startWith(Iterable[T])" -> "[unnecessary because we can just use ++ instead]",
38+
"takeLast(Int)" -> "takeRight(Int)",
3839
"toList()" -> "toSeq",
3940
"toSortedList()" -> unnecessary,
4041
"toSortedList(Func2[_ >: T, _ >: T, Integer])" -> unnecessary,

0 commit comments

Comments
 (0)