Skip to content

Commit ba16fd5

Browse files
Merge pull request ReactiveX#529 from benjchristensen/scala-tweaks
Scala Tweaks
2 parents 2192f20 + 46db816 commit ba16fd5

22 files changed

+335
-13
lines changed

language-adaptors/rxjava-scala/src/examples/scala/rx/lang/scala/examples/TestSchedulerExample.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ class TestSchedulerExample extends JUnitSuite {
3535
verify(observer, never).onCompleted()
3636
verify(observer, never).onError(any(classOf[Throwable]))
3737

38+
verify(observer, never).onNext(2L)
39+
3840
sub.unsubscribe();
41+
3942
scheduler.advanceTimeTo(4 seconds)
40-
verify(observer, never).onNext(2L)
41-
verify(observer, times(1)).onCompleted()
42-
verify(observer, never).onError(any(classOf[Throwable]))
43+
44+
// after unsubscription we expect no further events
45+
verifyNoMoreInteractions(observer)
4346
}
4447

4548
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,21 @@ object ImplicitFunctionConversions {
3939
}
4040
}
4141

42+
implicit def toJavaNotification[T](s: Notification[T]): rx.Notification[_ <: T] = s.asJava
43+
implicit def toScalaNotification[T](s: rx.Notification[_ <: T]): Notification[T] = Notification(s)
44+
4245
implicit def toJavaSubscription(s: Subscription): rx.Subscription = s.asJavaSubscription
4346
implicit def toScalaSubscription(s: rx.Subscription): Subscription = Subscription(s)
4447

4548
implicit def scalaSchedulerToJavaScheduler(s: Scheduler): rx.Scheduler = s.asJavaScheduler
4649
implicit def javaSchedulerToScalaScheduler(s: rx.Scheduler): Scheduler = Scheduler(s)
4750

4851
implicit def toJavaObserver[T](s: Observer[T]): rx.Observer[_ >: T] = s.asJavaObserver
49-
implicit def toScalaObserver[T](s: rx.Observer[T]): Observer[T] = Observer(s)
52+
implicit def toScalaObserver[T](s: rx.Observer[_ >: T]): Observer[T] = Observer(s)
5053

5154
implicit def toJavaObservable[T](s: Observable[T]): rx.Observable[_ <: T] = s.asJavaObservable
52-
implicit def toScalaObservable[T](s: rx.Observable[T]): Observable[T] = Observable(s)
53-
55+
implicit def toScalaObservable[T](s: rx.Observable[_ <: T]): Observable[T] = Observable(s)
56+
5457
implicit def scalaFunction1ToOnSubscribeFunc[T](f: rx.lang.scala.Observer[T] => Subscription) =
5558
new rx.Observable.OnSubscribeFunc[T] {
5659
def onSubscribe(obs: rx.Observer[_ >: T]): rx.Subscription = {

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* Copyright 2013 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package rx.lang.scala
217

318
/**
@@ -36,6 +51,11 @@ object Notification {
3651
}
3752

3853
object OnNext {
54+
55+
def apply[T](value: T): Notification[T] = {
56+
Notification(new rx.Notification[T](value))
57+
}
58+
3959
def unapply[U](n: Notification[U]): Option[U] = n match {
4060
case n2: OnNext[U] => Some(n.asJava.getValue)
4161
case _ => None
@@ -47,6 +67,11 @@ object Notification {
4767
}
4868

4969
object OnError {
70+
71+
def apply[T](error: Throwable): Notification[T] = {
72+
Notification(new rx.Notification[T](error))
73+
}
74+
5075
def unapply[U](n: Notification[U]): Option[Throwable] = n match {
5176
case n2: OnError[U] => Some(n2.asJava.getThrowable)
5277
case _ => None
@@ -56,6 +81,11 @@ object Notification {
5681
class OnCompleted[T](val asJava: rx.Notification[_ <: T]) extends Notification[T] {}
5782

5883
object OnCompleted {
84+
85+
def apply[T](): Notification[T] = {
86+
Notification(new rx.Notification())
87+
}
88+
5989
def unapply[U](n: Notification[U]): Option[Unit] = n match {
6090
case n2: OnCompleted[U] => Some()
6191
case _ => None

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* Copyright 2013 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package rx.lang.scala
217

318
/**

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* Copyright 2013 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package rx.lang.scala
217

318
import java.util.Date

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* Copyright 2013 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package rx.lang.scala
217

318
import ImplicitFunctionConversions.scalaBooleanFunction1ToRxBooleanFunc1

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/concurrency/Schedulers.scala

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* Copyright 2013 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package rx.lang.scala.concurrency
217

318
import java.util.concurrent.Executor
@@ -13,29 +28,29 @@ object Schedulers {
1328
/**
1429
* Returns a [[rx.lang.scala.Scheduler]] that executes work immediately on the current thread.
1530
*/
16-
def immediate: Scheduler = rx.concurrency.Schedulers.immediate()
31+
def immediate: Scheduler = Scheduler(rx.concurrency.Schedulers.immediate())
1732

1833
/**
1934
* Returns a [[rx.lang.scala.Scheduler]] that queues work on the current thread to be executed after the current work completes.
2035
*/
21-
def currentThread: Scheduler = rx.concurrency.Schedulers.currentThread()
36+
def currentThread: Scheduler = Scheduler(rx.concurrency.Schedulers.currentThread())
2237

2338
/**
2439
* Returns a [[rx.lang.scala.Scheduler]] that creates a new {@link Thread} for each unit of work.
2540
*/
26-
def newThread: Scheduler = rx.concurrency.Schedulers.newThread
41+
def newThread: Scheduler = Scheduler(rx.concurrency.Schedulers.newThread)
2742

2843
/**
2944
* Returns a [[rx.lang.scala.Scheduler]] that queues work on an `java.util.concurrent.Executor`.
3045
*
3146
* Note that this does not support scheduled actions with a delay.
3247
*/
33-
def executor(executor: Executor): Scheduler = rx.concurrency.Schedulers.executor(executor)
48+
def executor(executor: Executor): Scheduler = Scheduler(rx.concurrency.Schedulers.executor(executor))
3449

3550
/**
3651
* Returns a [[rx.lang.scala.Scheduler]] that queues work on an `java.util.concurrent.ScheduledExecutorService`.
3752
*/
38-
def executor(executor: ScheduledExecutorService): Scheduler = rx.concurrency.Schedulers.executor(executor)
53+
def executor(executor: ScheduledExecutorService): Scheduler = Scheduler(rx.concurrency.Schedulers.executor(executor))
3954

4055
/**
4156
* Returns a [[rx.lang.scala.Scheduler]] intended for computational work.
@@ -46,7 +61,7 @@ object Schedulers {
4661
*
4762
* Do not perform IO-bound work on this scheduler. Use [[rx.lang.scala.concurrency.Schedulers.threadPoolForIO]] instead.
4863
*/
49-
def threadPoolForComputation: Scheduler = rx.concurrency.Schedulers.threadPoolForComputation()
64+
def threadPoolForComputation: Scheduler = Scheduler(rx.concurrency.Schedulers.threadPoolForComputation())
5065

5166
/**
5267
* [[rx.lang.scala.Scheduler]] intended for IO-bound work.
@@ -57,6 +72,6 @@ object Schedulers {
5772
*
5873
* Do not perform computational work on this scheduler. Use [[rx.lang.scala.concurrency.Schedulers.threadPoolForComputation]] instead.
5974
*/
60-
def threadPoolForIO: Scheduler = rx.concurrency.Schedulers.threadPoolForIO()
75+
def threadPoolForIO: Scheduler = Scheduler(rx.concurrency.Schedulers.threadPoolForIO())
6176

6277
}

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/concurrency/TestScheduler.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* Copyright 2013 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package rx.lang.scala.concurrency
217

318
import scala.concurrent.duration.Duration

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/observables/package.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* Copyright 2013 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package rx.lang.scala
217

318
/**

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/subjects/AsyncSubject.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* Copyright 2013 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package rx.lang.scala.subjects
217

318
import rx.lang.scala.Subject

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/subjects/BehaviorSubject.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* Copyright 2013 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package rx.lang.scala.subjects
217

318
import rx.lang.scala.Subject

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/subjects/PublishSubject.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* Copyright 2013 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package rx.lang.scala.subjects
217

318
import rx.lang.scala.Subject

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/subjects/ReplaySubject.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* Copyright 2013 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package rx.lang.scala.subjects
217

318
import rx.lang.scala.Subject

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/subjects/Subject.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* Copyright 2013 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package rx.lang.scala
217

318
/**

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/subjects/package.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* Copyright 2013 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package rx.lang.scala
217

318
/**

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/subscriptions/BooleanSubscription.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* Copyright 2013 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package rx.lang.scala.subscriptions
217

318
import rx.lang.scala._

0 commit comments

Comments
 (0)