# Add parameter name hint to function parameter

**URL:** <https://contributors.scala-lang.org/t/add-parameter-name-hint-to-function-parameter/6299>\
**Category:** Dotty\
**Created:** [August 31, 2023, 4:51pm UTC](https://contributors.scala-lang.org/t/add-parameter-name-hint-to-function-parameter/6299 "2023-08-31T16:51:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hepin1989](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/hepin1989/32/419_2.png) [@hepin1989](https://contributors.scala-lang.org/u/hepin1989)\
**Post date:** [August 31, 2023, 4:51pm UTC](https://contributors.scala-lang.org/t/add-parameter-name-hint-to-function-parameter/6299/1 "2023-08-31T16:51:05Z")

</div>

```scala

def distinctUtilChanged[T](predicate: (old:T, `new`:T) => Boolean):IterableOnce[T]

```

Which I have to write some like below for now:

```scala

def distinctUtilChanged[T](predicate: (/*old*/ T, /*new*/T) => Boolean):IterableOnce[T]

```

---

<div class="post-metadata">

**Author:** ![matthew.rooney](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/matthew.rooney/32/1179_2.png) [@matthew.rooney](https://contributors.scala-lang.org/u/matthew.rooney)\
**Post date:** [August 31, 2023, 5:46pm UTC](https://contributors.scala-lang.org/t/add-parameter-name-hint-to-function-parameter/6299/2 "2023-08-31T17:46:02Z")

</div>

This would be a really nice feature, and one of the nicer things about typescript. Quite often I find that I want to use named arguments for things. For example when integrating with a map tile system.

```auto
def someUtility(source: (Int, Int, Int) => ImageIO) ....

```

I’ve used type aliases etc to make it clear that the arguments are `x, y and zoom` but it doesn’t feel ideal. I’ve also played with using a SAM type (which is not too bad).

```auto
trait TileSource {
  fetch(x: Int, y: Int, zoom: Int): ImageIO
}

```

---

<div class="post-metadata">

**Author:** ![MateuszKowalewski](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/mateuszkowalewski/32/77_2.png) [@MateuszKowalewski](https://contributors.scala-lang.org/u/MateuszKowalewski)\
**Post date:** [August 31, 2023, 7:47pm UTC](https://contributors.scala-lang.org/t/add-parameter-name-hint-to-function-parameter/6299/3 "2023-08-31T19:47:16Z")

</div>

You’re not the first one who wants anonymous case classes / named tuples (like for example C# and few other languages have). But don’t expect to get then.

> [@Named Tuple Arguments / Anonymous Case Classes](https://contributors.scala-lang.org/t/named-tuple-arguments-anonymous-case-classes/4352):
>
> I often find myself in a dilemma when creating a helper function that returns a tuple. On the one hand, I don’t want to create a case class specially for this single function, while on the other hand it’s more difficult to understand/use the return arguments because they are unnamed (\_1, \_2, ...) private def getNames[T] : (String, Map[T, String]) = ??? I propose that it will be possible to name the arguments for these tuples, effectively making them anonymous case classes. private def getNam…

In my opinion named tuples should be even the basic building block for structures (and of course parameters lists), and additionally “tagging” them with a name should be the special case. But that’s likely not Scala but a different language…

---

<div class="post-metadata">

**Author:** ![rcano](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/rcano/32/3073_2.png) [@rcano](https://contributors.scala-lang.org/u/rcano)\
**Post date:** [September 1, 2023, 12:41am UTC](https://contributors.scala-lang.org/t/add-parameter-name-hint-to-function-parameter/6299/4 "2023-09-01T00:41:44Z")

</div>

Given that scala 3 has path dependent function types, this is already possible. See here: [Dependent Function Types](https://dotty.epfl.ch/docs/reference/new-types/dependent-function-types.html)

---

<div class="post-metadata">

**Author:** ![MateuszKowalewski](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/mateuszkowalewski/32/77_2.png) [@MateuszKowalewski](https://contributors.scala-lang.org/u/MateuszKowalewski)\
**Post date:** [September 3, 2023, 8:54am UTC](https://contributors.scala-lang.org/t/add-parameter-name-hint-to-function-parameter/6299/5 "2023-09-03T08:54:45Z")

</div>

How is this supposed to work?

You could write the signature, but you can’t access the “Tuple fields” in the body of the method, of course, as this is type level and not term level.

This does not compile:

```scala
trait t:
   def distinctUtilChanged[T](predicate: (old: T, `new`: T) => Boolean): IterableOnce[T] =
      println(old) // Not found: old
      List()

```

---

<div class="post-metadata">

**Author:** ![Katrix](https://contributors.scala-lang.org/letter_avatar_proxy/v4/letter/k/c6cbf5/32.png) [@Katrix](https://contributors.scala-lang.org/u/Katrix)\
**Post date:** [September 3, 2023, 1:09pm UTC](https://contributors.scala-lang.org/t/add-parameter-name-hint-to-function-parameter/6299/6 "2023-09-03T13:09:07Z")

</div>

Not sure why that would compile. What you have in scope there is a parameter named `predicate`. Now, it is a valid point that `predicate(old = ???, new = ???)` won’t work, but that is a different problem.

---

<div class="post-metadata">

**Author:** ![MateuszKowalewski](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/mateuszkowalewski/32/77_2.png) [@MateuszKowalewski](https://contributors.scala-lang.org/u/MateuszKowalewski)\
**Post date:** [September 6, 2023, 9:26am UTC](https://contributors.scala-lang.org/t/add-parameter-name-hint-to-function-parameter/6299/7 "2023-09-06T09:26:00Z")

</div>

You’re right! My fault. 😅

Even if this would be a TypeScript object as param for the `predicate` function one wouldn’t be able to destructure it directly.

But you would get at least IDE hints for the object fields in TS.

(I was thinking about something like [https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABAExgZ1pKBVWAbAYQAsBDMAcwFNkAKABwCdqYISpKAuRGgfS4G84eZFzAgAtgCNKDADSIeYSgHdRE6QwC+ASkQBeAHyIAQnCGUy2rgEEGDEgE8APGKkyj-AFCIfiAPR+iBAIGIh0JPbiaFwAChEk4pTsDGhOUA50lHDAYUyorOwGANoADAC6+oj8AHS1jMwFlNUR5BKUYFBomt6+Ab79AHoDiFBE6IgABuGRaBOIpGiIMB0ylBjL5CMZlIBkBD0+fcFgaObVeHDk9HksbJQ0gsJcAIzyPMoMCORcAEw6un22VqJDqIbJbTKIADk-FBj0Qrg0AG4FO9Pmo3AxkZpIft+nj8QTCUSiX0fOMwHAoIgSGg0DByGASJI8JQRnAwvFEslQTl0hDobCRPD1DJkYoVOikYhsdVccT5QrFf5AgB5SQAK0o0EQeBgyRIeEQ4kcoLAeAciDQmQgMGAFoA1hTlEhGHBMgxYGt5GRkFC3h8KDilcGQ-jSSg4Gt4ZTEJQAB7oKnLcGsgVCIUI0UKJSqYUYrFB3wsqmSSr1fK3e7p56vHM-HS4phQEAMJBFF6Ib5lTzdIA](https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABAExgZ1pKBVWAbAYQAsBDMAcwFNkAKABwCdqYISpKAuRGgfS4G84eZFzAgAtgCNKDADSIeYSgHdRE6QwC+ASkQBeAHyIAQnCGUy2rgEEGDEgE8APGKkyj-AFCIfiAPR+iBAIGIh0JPbiaFwAChEk4pTsDGhOUA50lHDAYUyorOwGANoADAC6+oj8AHS1jMwFlNUR5BKUYFBomt6+Ab79AHoDiFBE6IgABuGRaBOIpGiIMB0ylBjL5CMZlIBkBD0+fcFgaObVeHDk9HksbJQ0gsJcAIzyPMoMCORcAEw6un22VqJDqIbJbTKIADk-FBj0Qrg0AG4FO9Pmo3AxkZpIft+nj8QTCUSiX0fOMwHAoIgSGg0DByGASJI8JQRnAwvFEslQTl0hDobCRPD1DJkYoVOikYhsdVccT5QrFf5AgB5SQAK0o0EQeBgyRIeEQ4kcoLAeAciDQmQgMGAFoA1hTlEhGHBMgxYGt5GRkFC3h8KDilcGQ-jSSg4Gt4ZTEJQAB7oKnLcGsgVCIUI0UKJSqYUYrFB3wsqmSSr1fK3e7p56vHM-HS4phQEAMJBFF6Ib5lTzdIA) )

This is unrelated to the point that I think “named tuples” would be nevertheless a really cool addition to Scala.

---

<div class="post-metadata">

**Author:** ![Katrix](https://contributors.scala-lang.org/letter_avatar_proxy/v4/letter/k/c6cbf5/32.png) [@Katrix](https://contributors.scala-lang.org/u/Katrix)\
**Post date:** [September 6, 2023, 5:09pm UTC](https://contributors.scala-lang.org/t/add-parameter-name-hint-to-function-parameter/6299/8 "2023-09-06T17:09:01Z")

</div>

Oh I’d love native named tuples too. So much code that could benefit from such a thing I think
