Skip to content

Use lazy arguments for when and whenNot#169

Open
neunzehnhundert97 wants to merge 1 commit intoraquo:masterfrom
neunzehnhundert97:master
Open

Use lazy arguments for when and whenNot#169
neunzehnhundert97 wants to merge 1 commit intoraquo:masterfrom
neunzehnhundert97:master

Conversation

@neunzehnhundert97
Copy link

Hi, here is a small change/fix.

When using when as a shortcut for an if, it violated my assumption that the conditional code would not be executed at all. Instead, it is executed but its result not used. Not a problem if your code is mostly pure, but if there are lurking some side effects, it can give you a hard time finding the problem. I did set the boolean correctly, did I?

I suggest to use lazy parameters here, which makes usage of when as equivalent to ìf as possible.

@raquo
Copy link
Owner

raquo commented Aug 24, 2024 via email

raquo added a commit that referenced this pull request Jan 16, 2025
- Note: Scala 2 does not support by-name varargs, so in Scala 2 these methods are now limited to at most one argument
- This required an alternative implementation vs #169.
raquo added a commit that referenced this pull request Jan 16, 2025
- Note: Scala 2 does not support by-name varargs, so in Scala 2 these methods are now limited to at most one argument
- This required an alternative implementation vs #169.
@raquo
Copy link
Owner

raquo commented Jan 18, 2025

It turns out that Scala 2 does not support by-name varargs.

To keep Laminar behaviour consistent, I split the implementations of when and whenNot to only accept a single argument in Scala 2, and to accept varargs in Scala 3 (both by-name). In Scala2, users can still provide Seq(mod1, mod2) or modSeq(mod1, mod2) as a single param, the implicit conversion from Seq[Mod] to Mod will take care of that.

So, I will close this PR when I actually merge my alternative implementation. Thanks for bringing up this issue!

raquo added a commit that referenced this pull request Oct 27, 2025
- Note: Scala 2 does not support by-name varargs, so in Scala 2 these methods are now limited to at most one argument
- This required an alternative implementation vs #169.
@raquo raquo added this to the v18.0.0 milestone Oct 30, 2025
raquo added a commit that referenced this pull request Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants