Given a function `f` with a single argument, `x`, I have a need for passing x both strictly and non-strictly.
-- Example: def fStrict(x: Int) = ??? def fNonStrict(x: => Int) = ??? I don't like explicitly putting strict and non-strict in the names. Does anyone have a convention for how to name both functions? You received this message because you are subscribed to the Google Groups "scala-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
Kevin, As you know. The two parameter signatures, albeit visually similar have very different meaning. The first one accepts an integer, and the second one a function that returns an integer. This can have wide ranging implications in both performance and functionality. I am wondering if having two versions of the same function, one by name and one by value is the right way to go. Without knowing your use case it's of course hard to give an educated opinion, but it seems to me that it would bloat your API and confuse users more than providing the "preferred" route and let the caller turn it into a function / defer the entire method call as necessary. Sincerely, Peter Salanki -- You received this message because you are subscribed to the Google Groups "scala-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
>The first one accepts an integer, and the second one a function that returns an integer.
-- For the second, it's technically not a function though, is it? Although I see how a 0-arg call by-name argument behaves like Function0. On Friday, February 17, 2017 at 9:26:00 AM UTC-5, Peter Salanki wrote:
You received this message because you are subscribed to the Google Groups "scala-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
Conceptually it's not a Function0, but technically under the hood it is implemented with a Function0. Depending on your interpretation of the words conceptually and technically, I guess...
-- Kind regards, Jasper Op vrijdag 17 februari 2017 20:02:10 UTC+1 schreef Kevin Meredith:
You received this message because you are subscribed to the Google Groups "scala-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
In reply to this post by Kevin Meredith
In the very very rare cases (actually, I only remember one) where I needed to do this and didn't immediately rip it out as confusing, I called the strict one `f` and the non-strict one `fByName`. If you know what a by name parameter is, it's very clear. If you don't, it doesn't get at the distinction at all, so it's not so great. ("fLazyArg" would be more instructive.) The problem with Strict in my opinion is that it requires the same level of knowledge as ByName to make sense, but isn't as precise leaving one to wonder what isn't strict about it. On Fri, Feb 17, 2017 at 5:57 AM, Kevin Meredith <[hidden email]> wrote:
You received this message because you are subscribed to the Google Groups "scala-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
Free forum by Nabble | Edit this page |