-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
Add SplitByType
s observables
#116
Merged
Merged
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e74cf3b
add macro & test
HollandDM cebb134
feat: add illegal usage check
HollandDM 9705542
fix: use Lamda instead of DefDef
HollandDM 57b3ea3
some small update
HollandDM d3680f3
fix: use opaque type
HollandDM ebe5718
ref: test to scala 3 only
HollandDM 9a41579
feat: add handle type
HollandDM 36926bb
feat: remove debug info and sanitize test cases
HollandDM 27dadd2
feat: add handleValue
HollandDM d7f1ef9
ref: change handleCase signature
HollandDM 649f769
ref: opaque to anyval
HollandDM 786b181
ref: rename splitMatch to splitMatchOne
HollandDM 6817520
feat: add splitMatchSeq
HollandDM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/main/scala-3/com/raquo/airstream/split/MatchSplitObservable.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.raquo.airstream.split | ||
|
||
import com.raquo.airstream.core.{Observable, BaseObservable} | ||
import scala.annotation.compileTimeOnly | ||
|
||
/** | ||
* `MatchSplitObservable` served as macro's data holder for macro expansion. | ||
* | ||
* For example: | ||
* | ||
* ```scala | ||
* fooSignal.splitMatch | ||
* .handleCase { case Bar(Some(str)) => str } { (str, strSignal) => renderStrNode(str, strSignal) } | ||
* .handleCase { case baz: Baz => baz } { (baz, bazSignal) => renderBazNode(baz, bazSignal) } | ||
* ``` | ||
* | ||
* will be expanded sematically into: | ||
* | ||
* ```scala | ||
* MatchSplitObservable.build(fooSignal, ({ case baz: Baz => baz }) :: ({ case Bar(Some(str)) => str }) :: Nil, handlerMap) | ||
* ``` | ||
*/ | ||
|
||
opaque type MatchSplitObservable[Self[+_] <: Observable[_] , I, O] = Unit | ||
|
||
object MatchSplitObservable { | ||
|
||
@compileTimeOnly("splitMatch without toSignal/toStream is illegal") | ||
def build[Self[+_] <: Observable[_] , I, O]( | ||
observable: BaseObservable[Self, I], | ||
caseList: List[PartialFunction[Any, Any]], | ||
handlerMap: Map[Int, Function2[Any, Any, O]] | ||
): MatchSplitObservable[Self, I, O] = throw new UnsupportedOperationException("splitMatch without toSignal/toStream is illegal") | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
src/main/scala-3/com/raquo/airstream/split/MatchTypeObservable.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.raquo.airstream.split | ||
|
||
import com.raquo.airstream.core.{Observable, BaseObservable} | ||
import scala.annotation.compileTimeOnly | ||
|
||
/** `MatchTypeObservable` served as macro's data holder for macro expansion. | ||
* | ||
* For example: | ||
* | ||
* ```scala | ||
* fooSignal.splitMatch | ||
* .splitType[Baz] { (baz, bazSignal) => renderBazNode(baz, bazSignal) } | ||
* ``` | ||
* | ||
* will be expanded sematically into: | ||
* | ||
* ```scala | ||
* MatchTypeObservable.build[*, *, *, Baz]( | ||
* fooSignal, | ||
* Nil, | ||
* handlerMap, | ||
* ({ case t: Baz => t }) | ||
* ) | ||
* ``` | ||
* | ||
* and then into: | ||
* | ||
* ```scala | ||
* MatchSplitObservable.build( | ||
* fooSignal, | ||
* ({ case baz: Baz => baz }) :: Nil, | ||
* handlerMap | ||
* ) | ||
* ``` | ||
*/ | ||
|
||
opaque type MatchTypeObservable[Self[+_] <: Observable[_], I, O, T] = Unit | ||
|
||
object MatchTypeObservable { | ||
|
||
@compileTimeOnly("splitMatch without toSignal/toStream is illegal") | ||
def build[Self[+_] <: Observable[_], I, O, T]( | ||
observable: BaseObservable[Self, I], | ||
caseList: List[PartialFunction[Any, Any]], | ||
handlerMap: Map[Int, Function2[Any, Any, O]], | ||
tCast: PartialFunction[T, T] | ||
): MatchTypeObservable[Self, I, O, T] = | ||
throw new UnsupportedOperationException( | ||
"splitMatch without toSignal/toStream is illegal" | ||
) | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
src/main/scala-3/com/raquo/airstream/split/MatchValueObservable.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.raquo.airstream.split | ||
|
||
import com.raquo.airstream.core.{Observable, BaseObservable} | ||
import scala.annotation.compileTimeOnly | ||
|
||
/** `MatchSingletonObservable` served as macro's data holder for macro expansion. | ||
* | ||
* For example: | ||
* | ||
* ```scala | ||
* fooSignal.splitMatch | ||
* .splitValue(Tar)(tarSignal => renderTarNode(tarSignal)) | ||
* ``` | ||
* | ||
* will be expanded sematically into: | ||
* | ||
* ```scala | ||
* MatchTypeObservable.build[*, *, *, Baz]( | ||
* fooSignal, | ||
* Nil, | ||
* handlerMap, | ||
* ({ case Tar => Tar }) | ||
* ) | ||
* ``` | ||
* | ||
* and then into: | ||
* | ||
* ```scala | ||
* MatchSplitObservable.build( | ||
* fooSignal, | ||
* ({ case Tar => Tar }) :: Nil, | ||
* handlerMap | ||
* ) | ||
* ``` | ||
*/ | ||
|
||
opaque type MatchValueObservable[Self[+_] <: Observable[_], I, O, V0, V1] = Unit | ||
|
||
object MatchValueObservable { | ||
|
||
@compileTimeOnly("splitMatch without toSignal/toStream is illegal") | ||
def build[Self[+_] <: Observable[_], I, O, V0, V1]( | ||
observable: BaseObservable[Self, I], | ||
caseList: List[PartialFunction[Any, Any]], | ||
handlerMap: Map[Int, Function2[Any, Any, O]], | ||
vCast: PartialFunction[V0, V1] | ||
): MatchValueObservable[Self, I, O, V0, V1] = | ||
throw new UnsupportedOperationException( | ||
"splitMatch without toSignal/toStream is illegal" | ||
) | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
V0
andV1
should never be different, but we cannot just doMatchValueObservable[Self[+_] <: Observable[_], I, O, V]
because after type erasure, compiler cannot differentiatesMatchValueObservable[Self[+_] <: Observable[_], I, O, V]
fromMatchTypeObservable[Self[+_] <: Observable[_], I, O, T]
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH the implications of this are over my head, but it sounds like it's just an unfortunate implementation detail that we have to deal with. In that case, fine by me, I certainly don't have better ideas on this.
I think we're all good now, thanks for all the updates!
I am super pumped for these new operators, this will be one of the first things that I will merge for 18.x, proooobably in a few weeks (but apologies in advance if my 18.x gets delayed a bit, honestly, it's possible, but I'll do my best to carve out some time for it asap).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ambiguity happens because of the opaque types. I changed them back to value classes to remove this implementation hack. It should be easier to read and understand now.