Is there a way to have tuples with named fields in Scala, similar to anonymous classes in C#?

Viewed 20016

See: Can I specify a meaningful name for an anonymous class in C#?

In C# you can write:

var e = new { ID = 5, Name= "Prashant" };
assertEquals( 5, e.ID )

But in Scala I end up writing:

var e = (5, "Prashant")
assertEquals( 5, e._1 )

Scala maintains type safety through the use of generics (as does C#), but loses the readability of the name of each field, e.g I use "_1" instead of "ID".

Is there anything like this in Scala?

5 Answers
Related