Skip to content

Commit 91b0457

Browse files
authored
Refactor: Move / rename CoreOps to MapOps; expand map ops scaladoc (#151)
1 parent edae59f commit 91b0457

16 files changed

+87
-49
lines changed

project/GenerateTupleSignals.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ case class GenerateTupleSignals(
1616
line("package com.raquo.airstream.extensions")
1717
line()
1818
line("import com.raquo.airstream.core.Signal")
19-
line("import com.raquo.airstream.misc.MapSignal")
19+
line("import com.raquo.airstream.map.MapSignal")
2020
line()
2121
line("// #Warning do not edit this file directly, it is generated by GenerateTupleSignals.scala")
2222
line()

project/GenerateTupleStreams.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ case class GenerateTupleStreams(
1616
line("package com.raquo.airstream.extensions")
1717
line()
1818
line("import com.raquo.airstream.core.EventStream")
19-
line("import com.raquo.airstream.misc.{FilterStream, MapStream}")
19+
line("import com.raquo.airstream.map.MapStream")
20+
line("import com.raquo.airstream.misc.FilterStream")
2021
line()
2122
line("// #Warning do not edit this file directly, it is generated by GenerateTupleStreams.scala")
2223
line()

src/main/scala/com/raquo/airstream/core/BaseObservable.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.raquo.airstream.core
33
import com.raquo.airstream.debug.DebugOps
44
import com.raquo.airstream.distinct.DistinctOps
55
import com.raquo.airstream.flatten.{AllowFlatMap, FlattenStrategy, MergingStrategy, SwitchingStrategy}
6+
import com.raquo.airstream.map.MapOps
67
import com.raquo.airstream.ownership.{Owner, Subscription}
78
import com.raquo.airstream.status.{FlatMapStatusObservable, Status}
89
import com.raquo.ew.JsArray
@@ -35,7 +36,7 @@ import scala.util.Try
3536
trait BaseObservable[+Self[+_] <: Observable[_], +A]
3637
extends Source[A]
3738
with Named
38-
with CoreOps[Self, A]
39+
with MapOps[Self, A]
3940
with RecoverOps[Self, A]
4041
with DistinctOps[Self[A], A]
4142
with DebugOps[Self, A] {

src/main/scala/com/raquo/airstream/core/CoreOps.scala

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/main/scala/com/raquo/airstream/core/EventStream.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.raquo.airstream.dynamicImport.{DynamicImportStreamObjectOps, DynamicI
1111
import com.raquo.airstream.eventbus.EventBus
1212
import com.raquo.airstream.extensions._
1313
import com.raquo.airstream.javaflow.FlowPublisherStream
14+
import com.raquo.airstream.map.{MapOps, MapStream}
1415
import com.raquo.airstream.misc._
1516
import com.raquo.airstream.split.SplittableOneStream
1617
import com.raquo.airstream.status.{AsyncStatusObservable, Status}
@@ -31,7 +32,7 @@ with CombineStreamOps[A] // combineWith, combineWithFn, withCurrentValueOf, samp
3132
with DynamicImportStreamOps[A] // dynamicImport (Scala 3 only)
3233
{
3334

34-
/** See more map-like operators in [[CoreOps]]
35+
/** See more map-like operators in [[MapOps]]
3536
*
3637
* @param project Note: guarded against exceptions
3738
*/

src/main/scala/com/raquo/airstream/core/Signal.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import com.raquo.airstream.debug.{Debugger, DebuggerSignal, DebugOps, DebugSigna
99
import com.raquo.airstream.distinct.{DistinctOps, DistinctSignal}
1010
import com.raquo.airstream.dynamicImport.{DynamicImportSignalObjectOps, DynamicImportSignalOps}
1111
import com.raquo.airstream.extensions._
12-
import com.raquo.airstream.misc.{MapSignal, ScanLeftSignal, StreamFromSignal}
12+
import com.raquo.airstream.map.{MapOps, MapSignal}
13+
import com.raquo.airstream.misc.{ScanLeftSignal, StreamFromSignal}
1314
import com.raquo.airstream.ownership.Owner
1415
import com.raquo.airstream.state.{ObservedSignal, OwnedSignal, Val}
1516
import com.raquo.airstream.timing.JsPromiseSignal
@@ -44,7 +45,7 @@ with DynamicImportSignalOps[A] // dynamicImport (Scala 3 only)
4445
*/
4546
protected[airstream] def now(): A = tryNow().get
4647

47-
/** See also various map-like operators methods in [[CoreOps]].
48+
/** See also various map-like operators methods in [[MapOps]].
4849
*
4950
* @param project Note: guarded against exceptions
5051
*/

src/main/scala/com/raquo/airstream/extensions/TupleSignals.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.raquo.airstream.extensions
22

33
import com.raquo.airstream.core.Signal
4-
import com.raquo.airstream.misc.MapSignal
4+
import com.raquo.airstream.map.MapSignal
55

66
// #Warning do not edit this file directly, it is generated by GenerateTupleSignals.scala
77

src/main/scala/com/raquo/airstream/extensions/TupleStreams.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.raquo.airstream.extensions
22

33
import com.raquo.airstream.core.EventStream
4-
import com.raquo.airstream.misc.{FilterStream, MapStream}
4+
import com.raquo.airstream.map.MapStream
5+
import com.raquo.airstream.misc.FilterStream
56

67
// #Warning do not edit this file directly, it is generated by GenerateTupleStreams.scala
78

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.raquo.airstream.map
2+
3+
import com.raquo.airstream.core.{EventStream, Signal}
4+
5+
/**
6+
* A base trait for observables that have mapping operators such as `map` and `mapTo`.
7+
* @tparam Self The kind of observable that this is (e.g. [[Signal]] or [[EventStream]]).
8+
* @tparam A The type of value emitted by this observable (e.g. [[org.scalajs.dom.MouseEvent]] or [[Int]]).
9+
*/
10+
trait MapOps[+Self[+_], +A] {
11+
12+
/**
13+
* Map all events or updates of this observable through a pure transformation `project`.
14+
* The resulting observable emits once each time this parent observable emits.
15+
*
16+
* @param project The transformation to apply, to be called exactly once per event or update.
17+
* Exceptions thrown during evaluation are caught by Airstream (see `recover()`).
18+
*
19+
* @see [[mapTo]], [[mapToStrict]], [[mapToUnit]], [[tapEach]]
20+
*/
21+
def map[B](project: A => B): Self[B]
22+
23+
/**
24+
* Ignore the current value and take a new value instead.
25+
*
26+
* @param value The replacement value, evaluated lazily and repeatedly on every event or update.
27+
* Exceptions thrown during evaluation are caught by Airstream (see `recover()`).
28+
*
29+
* @note Equivalent to `map(_ => value)` if `value` is defined with `def`.
30+
* @see [[map]], [[mapToStrict]], [[mapToUnit]], [[tapEach]]
31+
*/
32+
def mapTo[B](value: => B): Self[B] = map(_ => value)
33+
34+
/**
35+
* Ignore the current value and take a new value instead.
36+
*
37+
* @param value The replacement value, evaluated eagerly and only once.
38+
* Exceptions thrown during evaluation go uncaught in the current call stack.
39+
*
40+
* @note Equivalent to `map(_ => value)` if `value` is defined with `val`.
41+
* @see [[map]], [[mapTo]], [[mapToUnit]], [[tapEach]]
42+
*/
43+
def mapToStrict[B](value: B): Self[B] = map(_ => value)
44+
45+
/**
46+
* Ignore the current value and instead take the value "`()`" (i.e. of type [[Unit]]).
47+
*
48+
* @note Equivalent to `mapTo(())` or `mapToStrict(())`.
49+
* @see [[map]], [[mapTo]], [[mapToStrict]], [[tapEach]]
50+
*/
51+
@inline def mapToUnit: Self[Unit] = map(_ => ())
52+
53+
/**
54+
* Execute a side-effecting callback on every event or update.
55+
*
56+
* @param callback A callback whose return value is ignored, to be called exactly once per event or update.
57+
* Exceptions thrown during evaluation are caught by Airstream (see `recover()`).
58+
*
59+
* @note Will not work if no downstream observable is subscribed to by an observer.
60+
* @see [[map]], [[mapTo]], [[mapToStrict]], [[mapToUnit]]
61+
*/
62+
@inline def tapEach[U](callback: A => U): Self[A] = map { v => callback(v); v }
63+
}

src/main/scala/com/raquo/airstream/misc/MapSignal.scala renamed to src/main/scala/com/raquo/airstream/map/MapSignal.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.raquo.airstream.misc
1+
package com.raquo.airstream.map
22

33
import com.raquo.airstream.common.SingleParentSignal
44
import com.raquo.airstream.core.{Protected, Signal, Transaction}

0 commit comments

Comments
 (0)