Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin Language Adaptor #292

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions language-adaptors/rxjava-kotlin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Kotlin Adaptor for RxJava

This adaptor allows Kotlin Functions to be used and RxJava will know how to invoke them

This enable code such as:

```kotlin
Observable.toObservable("one", "two", "three")
.take(2)
.subscribe{ (arg:String) ->
println(arg)
}
```

In the future this module will expose a more idiomatic way to use RxJava inside Kotlin

# 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%7Ca%3A%22rxjava-kotlin%22).

Example for Maven:

```xml
<dependency>
<groupId>com.netflix.rxjava</groupId>
<artifactId>rxjava-kotlin</artifactId>
<version>x.y.z</version>
</dependency>
```

and for Ivy:

```xml
<dependency org="com.netflix.rxjava" name="rxjava-kotlin" rev="x.y.z" />
```

59 changes: 59 additions & 0 deletions language-adaptors/rxjava-kotlin/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
buildscript {
repositories {
mavenCentral()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is redundant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed by Kotlin Gradle plugin

maven {
url 'http://repository.jetbrains.com/all'
}
}
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.5.748'
}
}

apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'osgi'


repositories {
maven {
url 'http://repository.jetbrains.com/all'
}
}

dependencies {
compile project(':rxjava-core')
compile 'org.jetbrains.kotlin:kotlin-stdlib:0.5.748'
provided 'junit:junit-dep:4.10'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at your source, I don't see use of junit outside tests, mark this testCompile

provided 'org.mockito:mockito-core:1.8.5'
provided 'com.google.guava:guava:14.0.1'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at your source I don't see use of either mockito or guava. take these out unless they are used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mockito is used but I'll move to testCompile, I'll delete the guava dependency

}

eclipse {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird.. I thought the gradle template already does this..

classpath {
// include 'provided' dependencies on the classpath
plusConfigurations += configurations.provided

downloadSources = true
downloadJavadoc = true
}
}

idea {
module {
// include 'provided' dependencies on the classpath
scopes.PROVIDED.plus += configurations.provided
}
}

jar {
manifest {
name = 'rxjava-kotlin'
instruction 'Bundle-Vendor', 'Netflix'
instruction 'Bundle-DocURL', 'https://github.com/Netflix/RxJava'
instruction 'Import-Package', '!org.junit,!junit.framework,!org.mockito.*,*'
instruction 'Fragment-Host', 'com.netflix.rxjava.core'
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this sets off checkstyle unnecessarily.. sed -i -e '$a\' build.gradle

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* Copyright 2013 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package rx.lang.kotlin

import rx.util.functions.FunctionLanguageAdaptor

public class KotlinAdaptor: FunctionLanguageAdaptor {

public override fun call(function: Any?, args: Array<out Any>?): Any? {
return when(args!!.size){
0 -> (function!! as Function0<Any>)()
1 -> (function!! as Function1<Any, Any>)(args[0])
2 -> (function!! as Function2<Any, Any, Any>)(args[0], args[1])
3 -> (function!! as Function3<Any, Any, Any, Any>)(args[0], args[1], args[2])
4 -> (function!! as Function4<Any, Any, Any, Any, Any>)(args[0], args[1], args[2], args[3])
5 -> (function!! as Function5<Any, Any, Any, Any, Any, Any>)(args[0], args[1], args[2], args[3], args[4])
6 -> (function!! as Function6<Any, Any, Any, Any, Any, Any, Any>)(args[0], args[1], args[2], args[3], args[4], args[5])
7 -> (function!! as Function7<Any, Any, Any, Any, Any, Any, Any, Any>)(args[0], args[1], args[2], args[3], args[4], args[5], args[6])
8 -> (function!! as Function8<Any, Any, Any, Any, Any, Any, Any, Any, Any>)(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7])
9 -> (function!! as Function9<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>)(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8])
10 -> (function!! as Function10<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>)(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9])
11 -> (function!! as Function11<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>)(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10])
12 -> (function!! as Function12<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>)(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11])
13 -> (function!! as Function13<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>)(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12])
14 -> (function!! as Function14<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>)(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13])
15 -> (function!! as Function15<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>)(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13], args[14])
16 -> (function!! as Function16<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>)(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13], args[14], args[15])
17 -> (function!! as Function17<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>)(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13], args[14], args[15], args[16])
18 -> (function!! as Function18<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>)(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13], args[14], args[15], args[16], args[17])
19 -> (function!! as Function19<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>)(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13], args[14], args[15], args[16], args[17], args[18])
20 -> (function!! as Function20<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>)(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13], args[14], args[15], args[16], args[17], args[18], args[19])
21 -> (function!! as Function21<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>)(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13], args[14], args[15], args[16], args[17], args[18], args[19], args[20])
22 -> (function!! as Function22<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>)(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13], args[14], args[15], args[16], args[17], args[18], args[19], args[20], args[21])
else -> throw UnsupportedOperationException("")
}
}

public override fun getFunctionClass(): Array<Class<out Any?>>? {
return array(
javaClass<Function0<Any>>(),
javaClass<Function1<Any, Any>>(),
javaClass<Function2<Any, Any, Any>>(),
javaClass<Function3<Any, Any, Any, Any>>(),
javaClass<Function4<Any, Any, Any, Any, Any>>(),
javaClass<Function5<Any, Any, Any, Any, Any, Any>>(),
javaClass<Function6<Any, Any, Any, Any, Any, Any, Any>>(),
javaClass<Function7<Any, Any, Any, Any, Any, Any, Any, Any>>(),
javaClass<Function8<Any, Any, Any, Any, Any, Any, Any, Any, Any>>(),
javaClass<Function9<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>>(),
javaClass<Function10<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>>(),
javaClass<Function11<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>>(),
javaClass<Function12<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>>(),
javaClass<Function13<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>>(),
javaClass<Function14<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>>(),
javaClass<Function15<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>>(),
javaClass<Function16<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>>(),
javaClass<Function17<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>>(),
javaClass<Function18<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>>(),
javaClass<Function19<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>>(),
javaClass<Function20<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>>(),
javaClass<Function21<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>>(),
javaClass<Function22<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any>>())
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eol then eof

Loading