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

Idiomatic Scala Adaptor #376

Merged
merged 38 commits into from
Sep 13, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c159625
set up stubs for Scala Observable and its testing
samuelgruetter Sep 6, 2013
aa3ae12
add methods to Scala Wrapper (1)
samuelgruetter Sep 6, 2013
cce3ac1
add methods to Scala Wrapper (2) and find scalac bug
samuelgruetter Sep 6, 2013
25c4642
work around scalac bug by removing `extends AnyVal`
samuelgruetter Sep 6, 2013
0df8170
work around scalac bug by giving explicit type parameter to Observabl…
samuelgruetter Sep 6, 2013
61abf29
add methods to Scala Wrapper (3) and find interesting questions
samuelgruetter Sep 6, 2013
7872df8
add methods to Scala Wrapper (4)
samuelgruetter Sep 6, 2013
81584d0
Merge branch 'master' of github.com:Netflix/RxJava into idiomaticscala
samuelgruetter Sep 6, 2013
955fbfc
add methods to Scala Wrapper (5) (window)
samuelgruetter Sep 6, 2013
6f58752
add Observer wrapper to make subscribe(Observer[T]) work
samuelgruetter Sep 9, 2013
1c9ddef
Merge branch 'master' of github.com:Netflix/RxJava into idiomaticscala
samuelgruetter Sep 10, 2013
e3f3ba7
get rid of wrapper around Observer
samuelgruetter Sep 10, 2013
72c0e8a
add methods to Scala Wrapper (6)
samuelgruetter Sep 10, 2013
dd591b8
make dematerialize infer everything
samuelgruetter Sep 10, 2013
1caee60
add methods to Scala Wrapper (7)
samuelgruetter Sep 10, 2013
d12eb25
(does not compile!) refactoring of package structure
samuelgruetter Sep 10, 2013
dbf0375
refactoring package structure
samuelgruetter Sep 10, 2013
0603e39
Java example using Scala Observable code
samuelgruetter Sep 11, 2013
0566f9c
IntervalDemo
samuelgruetter Sep 11, 2013
61c2218
add usability tests
samuelgruetter Sep 11, 2013
2901c06
add operation merge (as instance method)
samuelgruetter Sep 11, 2013
171131c
add a int-version of buffer and window...
samuelgruetter Sep 11, 2013
2bf40bc
Merge branch 'master' of github.com:Netflix/RxJava into idiomaticscala
samuelgruetter Sep 11, 2013
c9f60ee
replace cast in window() by ascription
samuelgruetter Sep 11, 2013
f8787aa
Merge branch 'master' of github.com:Netflix/RxJava into idiomaticscala
samuelgruetter Sep 12, 2013
0a9c485
fix reduce to work with new no-wildcards Java reduce
samuelgruetter Sep 12, 2013
05a79a8
add debounce/throttle methods
samuelgruetter Sep 12, 2013
d0a48b2
refactor package structure
samuelgruetter Sep 12, 2013
f0feb97
remove sleep() from RxScalaDemo
samuelgruetter Sep 12, 2013
54fc958
BlockingObservable: add foreach and make it extend AnyVal
samuelgruetter Sep 12, 2013
4788a22
add apply() which takes Java Observable
samuelgruetter Sep 12, 2013
1bec926
restore old RxImplicits and RxImplicitsTests
samuelgruetter Sep 12, 2013
1d52491
mark RxImplicits and RxImplicitsTests as old
samuelgruetter Sep 12, 2013
2bd12ab
complete WithFilter
samuelgruetter Sep 12, 2013
4915348
TODO list for Scala adaptor
samuelgruetter Sep 12, 2013
6633ac9
update README
samuelgruetter Sep 12, 2013
0ad4282
add more methods and type aliases
samuelgruetter Sep 12, 2013
6072d65
add license headers
samuelgruetter Sep 12, 2013
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
5 changes: 5 additions & 0 deletions language-adaptors/rxjava-scala-java/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

rxjava-scala-java
Copy link
Member

Choose a reason for hiding this comment

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

@samuelgruetter Do you want this separate project being published to Maven Central? Does this code need to be a separate project or can it go under ./src/examples/ like each of the other language adaptors? As a full module it gets built and published.

Here are how the examples are placed for Clojure and Groovy:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that this not yet the way it should be. This rxjava-scala-java project only contains MovieLibUsage.java, which illustrates that Scala code using Scala Observables can be used from Java with Java Observables.
MovieLibUsage.java should reside somewhere in rxjava-scala/src/examples, and should be compiled by the Java compiler, but only after the Scala compiler has compiled MovieLib.scala. Since I have no experience with gradle, the only way I could solve this was to make a seperate project for MovieLibUsage.java which depends on the project containing MovieLib.scala.
Another solution that I found would be to instruct the Scala compiler to compile MovieLibUsage.java, too, but I don't like this solution, because I'd like to illustrate with this example that Java code depending on Scala libraries using Scala Observables can be built using the Java compiler having Scala-generated class files on the classpath.
I'd be very happy if you could set up the gradle build such that this works.

-----------------

Contains examples illustrating how RxScala code can be used from Java.
32 changes: 32 additions & 0 deletions language-adaptors/rxjava-scala-java/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

apply plugin: 'osgi'


project(':language-adaptors:rxjava-scala-java') {
//sourceSets.test.java.srcDir 'src/examples/java'
sourceSets.main.java.srcDir 'src/main/java'
}

dependencies {
compile 'org.scala-lang:scala-library:2.10.+'

compile project(':rxjava-core')

compile project(':language-adaptors:rxjava-scala')

provided 'junit:junit-dep:4.10'
provided 'org.mockito:mockito-core:1.8.5'
provided 'org.scalatest:scalatest_2.10:1.9.1'
}

jar {
manifest {
name = 'rxjava-scala-java'
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'
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package rx.lang.scala.examples;

import org.junit.Test;

import rx.Observable;
import rx.util.functions.Action1;


public class MovieLibUsage {

Action1<Movie> moviePrinter = new Action1<Movie>() {
public void call(Movie m) {
System.out.println("A movie of length " + m.lengthInSeconds() + "s");
}
};

@Test
public void test() {
MovieLib lib = new MovieLib(Observable.from(new Movie(3000), new Movie(1000), new Movie(2000)));

lib.longMovies().subscribe(moviePrinter);
}

}
13 changes: 1 addition & 12 deletions language-adaptors/rxjava-scala/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
# Scala Adaptor for RxJava


This adaptor allows 'fn' functions to be used and RxJava will know how to invoke them.

This enables code such as:

```scala
Observable.from("1", "2", "3")
.take(2)
.subscribe((callback: String) => {
println(callback)
})
```
There's an old Scala adaptor ( `rx.lang.scala.RxImplicits` with test `rx.lang.scala.RxImplicitsTest` ), which is deprecated. All other classes in `rx.lang.scala` belong to the new adaptor.

# Binaries

Expand Down
20 changes: 20 additions & 0 deletions language-adaptors/rxjava-scala/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

TODOs for Scala Adapter
-----------------------

This is a (probably incomplete) list of what still needs to be done in the Scala adaptor:

- [ ] ConnectableObservable: Implement adaptor. Note that it cannot extend Scala Observable, since value classes are final.
- [ ] more methods of BlockingObservable
- [ ] multicast, publish, replay once we have ConnectableObservable
- [ ] groupBy and GroupedObservable
- [ ] mirror complete Java package structure in Scala
- [ ] convert Java futures to Scala futures
- [ ] Add methods present in Scala collections library, but not in RxJava, e.g. zipWithIndex, aggregate à la Scala
- [ ] mergeDelayError, combineLatest, merge, concat, zip: decide if instance method or static or both, decide about arities > 2
- [ ] naming: switch() or switchOnNext()?
- [ ] decide where the MovieLib/MovieLibUsage (use Scala code from Java code) example should live and make sure gradle builds it in the right order
- [ ] Avoid text duplication in scaladoc using templates, add examples, distinction between use case signature and full signature
- [ ] other small TODOs


Loading