-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
observables
#116
base: master
Are you sure you want to change the base?
Conversation
|
||
val allCaseDefLists = caseExprList.reverse.zipWithIndex.flatMap { case (caseExpr, idx) => | ||
caseExpr.asTerm match { | ||
case Block(List(DefDef(_, _, _, Some(Match(_, caseDefList)))), _) => { |
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.
case Block(List(DefDef(_, _, _, Some(Match(_, caseDefList)))), _) => { | |
case Lambda(_, Match(_, caseDefList)) => { |
There's actually this little helper built into the reflectModule
that matches the (awkwardly verbose) AST for anonymous functions. 👍 Awesome macro, btw!
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.
Thanks, I actually forgot about Lambda
because I rarely use it. It's really useful actually
*/ | ||
final class MatchSplitObservable[Self[+_] <: Observable[_] , I, O] { | ||
throw new UnsupportedOperationException("splitMatch without toSignal/toStream is illegal") | ||
} |
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 class acts as a type only. DuckTape has a trick to create these kind of types (opaque TypeName = Unit
), but I cannot seem to integrate it into this code. Will have to dig more into this.
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.
Split type definition into a dedicated file seems to work.
4c2700c
to
3066f39
Compare
@kitlangton @raquo is there anything left to do with this PR? I think it is quite useful |
It's definitely very useful, thanks for your work on this! I am yet to properly review this, but on the high level it looks good. Sorry for such a delay, this was just too much for me to include in v17. I plan to merge this when I start working on the next Laminar release, likely around September-October. Since all this ties into Airstream with extension methods, I assume that you can use this code privately for now. |
val owner = new TestableOwner | ||
|
||
val signal = myVar.signal | ||
.splitMatch |
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.
Since this test file uses the new Scala 3 only features, the test file itself should be Scala 3 only
Awesome! Thanks @raquo |
As discussed in #103, this is the implementation of
SplitByType
macro for observable.The macro will expand into
match/case
definition, so it can takes advantage of exhaustive and reachable checking of the compiler.