Skip to content

Commit 5a813d6

Browse files
add distinct and distinctUntilChanged, but
those with custom equality are not yet there because of issue #395
1 parent fe1c127 commit 5a813d6

File tree

1 file changed

+117
-2
lines changed

1 file changed

+117
-2
lines changed

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

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,11 +1485,126 @@ class Observable[+T](val asJava: rx.Observable[_ <: T])
14851485
def first: Observable[T] = {
14861486
take(1)
14871487
}
1488-
1488+
1489+
/**
1490+
* Returns an Observable that forwards all sequentially distinct items emitted from the source Observable.
1491+
* <p>
1492+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/distinctUntilChanged.png">
1493+
*
1494+
* @return an Observable of sequentially distinct items
1495+
*/
1496+
def distinctUntilChanged: Observable[T] = {
1497+
Observable[T](asJava.distinctUntilChanged)
1498+
}
1499+
1500+
/**
1501+
* Returns an Observable that forwards all items emitted from the source Observable that are sequentially
1502+
* distinct according to a key selector function.
1503+
* <p>
1504+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/distinctUntilChanged.key.png">
1505+
*
1506+
* @param keySelector
1507+
* a function that projects an emitted item to a key value which is used for deciding whether an item is sequentially
1508+
* distinct from another one or not
1509+
* @return an Observable of sequentially distinct items
1510+
*/
1511+
def distinctUntilChanged[U](keySelector: T => U): Observable[T] = {
1512+
Observable[T](asJava.distinctUntilChanged[U](keySelector))
1513+
}
1514+
1515+
/**
1516+
* Returns an Observable that forwards all items emitted from the source Observable that are sequentially
1517+
* distinct according to an equality function.
1518+
* <p>
1519+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/distinctUntilChanged.png">
1520+
*
1521+
* @param equality
1522+
* an equality function for deciding whether two emitted items are equal or not
1523+
* @return an Observable of sequentially distinct items
1524+
*/
1525+
// def distinctUntilChanged[U](equality: (T, T) => Boolean): Observable[T] = {
1526+
// TODO once https://github.com/Netflix/RxJava/issues/395 is fixed
1527+
// }
1528+
1529+
/**
1530+
* Returns an Observable that forwards all items emitted from the source Observable that are sequentially
1531+
* distinct according to a key selector function and a comparator.
1532+
* <p>
1533+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/distinctUntilChanged.key.png">
1534+
*
1535+
* @param keySelector
1536+
* a function that projects an emitted item to a key value which is used for deciding whether an item is sequentially
1537+
* distinct from another one or not
1538+
* @param equality
1539+
* an equality function for deciding whether two emitted item keys are equal or not
1540+
* @return an Observable of sequentially distinct items
1541+
*/
1542+
// def distinctUntilChanged[U](keySelector: T => U, equality: (T, T) => Boolean): Observable[T] = {
1543+
// TODO once https://github.com/Netflix/RxJava/issues/395 is fixed
1544+
// }
1545+
1546+
/**
1547+
* Returns an Observable that forwards all distinct items emitted from the source Observable.
1548+
* <p>
1549+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/distinct.png">
1550+
*
1551+
* @return an Observable of distinct items
1552+
*/
1553+
def distinct: Observable[T] = {
1554+
Observable[T](asJava.distinct())
1555+
}
1556+
1557+
/**
1558+
* Returns an Observable that forwards all items emitted from the source Observable that are distinct according
1559+
* to a comparator.
1560+
* <p>
1561+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/distinct.png">
1562+
*
1563+
* @param equality
1564+
* an equality function for deciding whether two emitted items are equal or not
1565+
* @return an Observable of distinct items
1566+
*/
1567+
// def distinct(equality: (T, T) => Boolean): Observable[T] = {
1568+
// TODO once https://github.com/Netflix/RxJava/issues/395 is fixed
1569+
// }
1570+
1571+
/**
1572+
* Returns an Observable that forwards all items emitted from the source Observable that are distinct according
1573+
* to a key selector function.
1574+
* <p>
1575+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/distinct.key.png">
1576+
*
1577+
* @param keySelector
1578+
* a function that projects an emitted item to a key value which is used for deciding whether an item is
1579+
* distinct from another one or not
1580+
* @return an Observable of distinct items
1581+
*/
1582+
def distinct[U](keySelector: T => U): Observable[T] = {
1583+
Observable[T](asJava.distinct[U](keySelector))
1584+
}
1585+
1586+
/**
1587+
* Returns an Observable that forwards all items emitted from the source Observable that are distinct according
1588+
* to a key selector function and a comparator.
1589+
* <p>
1590+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/distinct.key.png">
1591+
*
1592+
* @param keySelector
1593+
* a function that projects an emitted item to a key value which is used for deciding whether an item is
1594+
* distinct from another one or not
1595+
* @param equality
1596+
* an equality function for deciding whether two emitted item keys are equal or not
1597+
* @return an Observable of distinct items
1598+
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229050(v=vs.103).aspx">MSDN: Observable.distinct</a>
1599+
*/
1600+
// def distinct[U](keySelector: T => U, equality: (T, T) => Boolean): Observable[T] = {
1601+
// TODO once https://github.com/Netflix/RxJava/issues/395 is fixed
1602+
//}
1603+
14891604
/**
14901605
* Converts an Observable into a {@link BlockingObservable} (an Observable with blocking
14911606
* operators).
1492-
*
1607+
*
14931608
* @see <a href="https://github.com/Netflix/RxJava/wiki/Blocking-Observable-Operators">Blocking Observable Operators</a>
14941609
*/
14951610
def toBlockingObservable: BlockingObservable[T] = {

0 commit comments

Comments
 (0)