This is potentially super easy, but I can't find any documentation on my problem.
There are two ways to define a functions in Scala, one with the def and the other with the val keyword. As an adept in functional programming, I'd like to use the latter more.
Now I have a problem: It's no problem to write a def function with a polymorphic type parameter:
def function[T](n: T) = {print(n)} // syntactically fine
How to do the same thing with the val keyword still eludes me though. This naive approach is syntactically invalid:
val function[T]: (a: T) => print(a) // Doesn't compile
That said, it is absolutely possible that I misunderstand Scala's approach on polymorphism and generics here.
defcreates methods, not functions. And actually what you asked is a FAQ search there for "difference between functions and methods"_ - TL;DR; what you want is not possible in Scala 2 but will be in Scala 3.