# RxKotlin
[](https://maven-badges.herokuapp.com/maven-central/io.reactivex.rxjava3/rxkotlin)
## Kotlin Extensions for RxJava
RxKotlin is a lightweight library that adds convenient extension functions to [RxJava](https://github.com/ReactiveX/RxJava). You can use RxJava with Kotlin out-of-the-box, but Kotlin has language features (such as [extension functions](https://kotlinlang.org/docs/reference/extensions.html)) that can streamline usage of RxJava even more. RxKotlin aims to conservatively collect these conveniences in one centralized library, and standardize conventions for using RxJava with Kotlin.
```kotlin
import io.reactivex.rxjava3.kotlin.subscribeBy
import io.reactivex.rxjava3.kotlin.toObservable
fun main() {
val list = listOf("Alpha", "Beta", "Gamma", "Delta", "Epsilon")
list.toObservable() // extension function for Iterables
.filter { it.length >= 5 }
.subscribeBy( // named arguments for lambda Subscribers
onNext = { println(it) },
onError = { it.printStackTrace() },
onComplete = { println("Done!") }
)
}
```
## Contributing
:warning: (16/10/2023) We are currently not accepting contributions due to lack of developers capable of handling them in a reasonable manner.
Since Kotlin makes it easy to implement extensions for anything and everything, this project has to be conservative in what features are in scope. Intentions to create syntactic sugar can quickly regress into [syntactic saccharin](https://en.wikipedia.org/wiki/Syntactic_sugar#Syntactic_saccharin), and such personal preferences belong in one's internal domain rather than an OSS library.
Here are some basic guidelines to determine whether your contribution might be in scope for RxKotlin:
* Is this intended feature already in RxJava?
- If no, propose the operator in RxJava.
- If yes, can Kotlin streamline the operator further?
* Does this substantially reduce the amount of boilerplate code?
* Does this make an existing operator easier to use?
* Does RxJava not contain this feature due to Java language limitations, or because of a deliberate decision to not include it?
### Kotlin Slack Channel
Join us on the #rx channel in Kotlin Slack!
https://kotlinlang.slack.com/messages/rx
## Support for RxJava 3.x, RxJava 2.x and RxJava 1.x
**Use RxKotlin 3.x versions to target RxJava 3.x.**
- The 3.x version is active.
Use RxKotlin 2.x versions to target RxJava 2.x.
- The 2.x version of RxJava and RxKotlin is in maintenance mode and will be supported only through bugfixes. No new features or behavior changes will be accepted or applied.
Use RxKotlin 1.x versions to target RxJava 1.x.
- The 1.x version of RxJava and RxKotlin reached end-of-life. No further development, support, maintenance, PRs or updates will happen.
The maintainers do not update the RxJava dependency version for every minor or patch RxJava release, so you should explicitly add the desired RxJava dependency version to your `pom.xml` or `build.gradle(.kts)`.
## Binaries
Binaries and dependency information for Maven, Ivy, Gradle and others can be found at [http://search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Crxkotlin).
### RxKotlin 3.x [](https://travis-ci.org/ReactiveX/RxKotlin)
Example for Maven:
```xml
io.reactivex.rxjava3
rxkotlin
3.x.y
```
Example for Gradle:
```kotlin
implementation("io.reactivex.rxjava3:rxkotlin:3.x.y")
```
### RxKotlin 2.x [](https://travis-ci.org/ReactiveX/RxKotlin)
Example for Maven:
```xml
io.reactivex.rxjava2
rxkotlin
2.x.y
```
Example for Gradle:
```kotlin
implementation("io.reactivex.rxjava2:rxkotlin:2.x.y")
```
### RxKotlin 1.x
Example for Maven:
```xml
io.reactivex
rxkotlin
1.x.y
```
Example for Gradle:
```kotlin
implementation("io.reactivex:rxkotlin:1.x.y")
```
### Building with JitPack
You can also use Gradle or Maven with [JitPack](https://jitpack.io/) to build directly off a snapshot, branch, or commit of this repository.
For example, to build off the 3.x branch, use this setup for Gradle:
```groovy
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.ReactiveX:RxKotlin:3.x-SNAPSHOT'
}
```
Use this setup for Maven:
```xml
jitpack.io
https://jitpack.io
com.github.ReactiveX
RxKotlin
3.x-SNAPSHOT
```
Learn more about building this project with JitPack [here](https://jitpack.io/#ReactiveX/RxKotlin).
## Extensions
|Target Type|Method|Return Type|Description|
|---|---|---|---|
|BooleanArray|toObservable()|Observable|Turns a Boolean array into an Observable|
|ByteArray|toObservable()|Observable|Turns a Byte array into an Observable|
|ShortArray|toObservable()|Observable|Turns a Short array into an Observable|
|IntArray|toObservable()|Observable|Turns an Int array into an Observable|
|LongArray|toObservable()|Observable|Turns a Long array into an Observable|
|FloatArray|toObservable()|Observable|Turns a Float array into an Observable|
|DoubleArray|toObservable()|Observable|Turns a Double array into an Observable|
|Array|toObservable()|Observable|Turns a `T` array into an Observable|
|IntProgression|toObservable()|Observable|Turns an `IntProgression` into an Observable|
|Iterable|toObservable()|Observable|Turns an `Iterable` into an Observable|
|Iterator|toObservable()|Observable|Turns an `Iterator` into an Observable|
|Observable|flatMapSequence()|Observable|Flat maps each `T` emission to a `Sequence`|
|Observable>|toMap()|Single