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

Add SplitByType observables #116

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

HollandDM
Copy link

@HollandDM HollandDM commented Jan 27, 2024

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.

@HollandDM HollandDM requested a review from raquo as a code owner January 27, 2024 05:10

val allCaseDefLists = caseExprList.reverse.zipWithIndex.flatMap { case (caseExpr, idx) =>
caseExpr.asTerm match {
case Block(List(DefDef(_, _, _, Some(Match(_, caseDefList)))), _) => {

Choose a reason for hiding this comment

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

Suggested change
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!

Copy link
Author

@HollandDM HollandDM Feb 22, 2024

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")
}
Copy link
Author

@HollandDM HollandDM Mar 12, 2024

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.

Copy link
Author

@HollandDM HollandDM Mar 13, 2024

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.

@ngbinh
Copy link
Sponsor Contributor

ngbinh commented May 29, 2024

@kitlangton @raquo is there anything left to do with this PR? I think it is quite useful

@raquo
Copy link
Owner

raquo commented May 29, 2024

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
Copy link
Owner

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

@ngbinh
Copy link
Sponsor Contributor

ngbinh commented May 30, 2024

Awesome! Thanks @raquo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants