An interesting consequence of Scala 3's context functions is that since the parameter's name isn't chosen at the call site (it's implicit), it's often accessed using a helper method, and that method will have a consistent canonical name across codebases. That helps readability.
-
Show this thread
-
For example, imagine an HTTP server's request handler is typed `Request ?=> Response`, so the request object is "given" within its body at the callsite. Defining, def request(using Request) = summon[Request] in the library means the request will always have the name `request`.
3 replies 0 retweets 6 likesShow this thread -
Compare that to a "normal" (non-context) function parameter, where one user will write `{ r => ... }`, another will write `{ req => ... }` and another will write `{ httpRequest => ... }`. Any user reading that code needs to learn the parameter name for each use site.
1 reply 0 retweets 9 likesShow this thread -
Replying to @propensive
Good point. The same principle holds for anonymous using clauses + global helper function. Highly recommended!
1 reply 0 retweets 15 likes
In fact, that's exactly how I've been writing tests for the last couple of weeks!pic.twitter.com/GZhr1DVvav
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.