Skip to content

Conversation

@hamzaremmal
Copy link
Member

No description provided.

@nowarn("msg=ChainingSyntax will be removed in the future")
object chaining extends ChainingSyntax:
extension[A](x: A)
inline def tap(inline f: A => Unit): x.type = { f(x); x }
Copy link
Member Author

Choose a reason for hiding this comment

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

The signature here differs from the one we used to have in scala.util.ChainingOps. First, we return a more precise type: x.type. Second, we do not need to have a second type variable and specify that f: A => B since we adapt the body of the lambda after the eta-expansion. This code will compile because of the adaptation for example:

def foo(x: String): String = "()"
val x: String => Unit = foo

def bar(f: String => Unit) = ()
bar(foo)
bar(x)

f(self)
self
}
def tap[U](f: A => U): A = scala.util.chaining.tap(self)(x => f(x))
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
def tap[U](f: A => U): A = scala.util.chaining.tap(self)(x => f(x))
def tap[U](f: A => U): A = scala.util.chaining.tap(self)(f)

But it is blocked by #24726

@hamzaremmal hamzaremmal added this to the 3.10.0 milestone Dec 11, 2025
@hamzaremmal hamzaremmal added area:library Standard library needs-minor-release This PR cannot be merged until the next minor release labels Dec 11, 2025
*/
object chaining extends ChainingSyntax
@nowarn("msg=ChainingSyntax will be removed in the future")
object chaining extends ChainingSyntax:
Copy link
Member Author

Choose a reason for hiding this comment

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

Question for me: Can we move this object to be outside the package object util?

@sjrd
Copy link
Member

sjrd commented Dec 11, 2025

This PR's communication is off.

The value added by the first commit is that tap and pipe become more inline, guaranteeing that they have no overhead. That's what the commit message should say. The deprecation is secondary and should appear in the body of the commit message. Also that's definitely not a "chore" since it provides value to end users.

Even more so, the second commit adds a public method to the API. There is no world in which this should be categorized as "chore". This is the archetypical "feat" according to any such categorization.

@nowarn("msg=ChainingSyntax will be removed in the future")
object chaining extends ChainingSyntax:
extension[A](x: A)
inline def tap(inline f: A => Unit): x.type = { f(x); x }
Copy link
Member

Choose a reason for hiding this comment

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

if you don't want to break imports like import scala.util.chaining.given then you can put these in a given AnyRef:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:library Standard library needs-minor-release This PR cannot be merged until the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants