Skip to content

Commit 9398623

Browse files
Merge pull request ReactiveX#537 from landonf/scala-do-operator
Add scala adapters for doOnEach operator.
2 parents 00c565d + 87bb561 commit 9398623

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,6 +1818,65 @@ trait Observable[+T]
18181818
new WithFilter[T](p, asJavaObservable)
18191819
}
18201820

1821+
/**
1822+
* Returns an Observable that applies the given function to each item emitted by an
1823+
* Observable.
1824+
*
1825+
* @param observer the observer
1826+
*
1827+
* @return an Observable with the side-effecting behavior applied.
1828+
*/
1829+
def doOnEach(observer: Observer[T]): Observable[T] = {
1830+
Observable[T](asJavaObservable.doOnEach(observer.asJavaObserver))
1831+
}
1832+
1833+
/**
1834+
* Returns an Observable that applies the given function to each item emitted by an
1835+
* Observable.
1836+
*
1837+
* @param onNext this function will be called whenever the Observable emits an item
1838+
*
1839+
* @return an Observable with the side-effecting behavior applied.
1840+
*/
1841+
def doOnEach(onNext: T => Unit): Observable[T] = {
1842+
Observable[T](asJavaObservable.doOnEach(
1843+
onNext
1844+
))
1845+
}
1846+
1847+
/**
1848+
* Returns an Observable that applies the given function to each item emitted by an
1849+
* Observable.
1850+
*
1851+
* @param onNext this function will be called whenever the Observable emits an item
1852+
* @param onError this function will be called if an error occurs
1853+
*
1854+
* @return an Observable with the side-effecting behavior applied.
1855+
*/
1856+
def doOnEach(onNext: T => Unit, onError: Throwable => Unit): Observable[T] = {
1857+
Observable[T](asJavaObservable.doOnEach(
1858+
onNext,
1859+
onError
1860+
))
1861+
}
1862+
1863+
/**
1864+
* Returns an Observable that applies the given function to each item emitted by an
1865+
* Observable.
1866+
*
1867+
* @param onNext this function will be called whenever the Observable emits an item
1868+
* @param onError this function will be called if an error occurs
1869+
* @param onCompleted the action to invoke when the source Observable calls
1870+
*
1871+
* @return an Observable with the side-effecting behavior applied.
1872+
*/
1873+
def doOnEach(onNext: T => Unit, onError: Throwable => Unit, onCompleted: () => Unit): Observable[T] = {
1874+
Observable[T](asJavaObservable.doOnEach(
1875+
onNext,
1876+
onError,
1877+
onCompleted
1878+
))
1879+
}
18211880
}
18221881

18231882
/**

0 commit comments

Comments
 (0)