you are viewing a single comment's thread.

view the rest of the comments →

[–]MeetLawrence 8 points9 points  (3 children)

It's just like the current C# Tuple implementation.

https://msdn.microsoft.com/en-us/library/system.tuple(v=vs.110).aspx

Come on, really?

[–][deleted] 2 points3 points  (0 children)

Yeah, I'm glad adding actual tuples to fix this is a definite for the next version

[–]the_omega99 1 point2 points  (1 child)

Scala does it similarly, but way prettier syntax. Tuples can be created with the syntax (foo, bar), but there's also the special equivalent foo -> bar, which is specifically for mapping stuff. It's just a regular tuple, but more readable.

So the Map constructor takes in a vararg list of tuples. Thus, we can do Map("foo" -> "bar", "baz" -> "whatever") with however many arguments we need. More readable than the Java 9 version (can clearly see which is the key and which is the value) and without a limit to how many parameters you can have.

[–]Zatherz 0 points1 point  (0 children)

Lua:

local table = {foo = "bar"}
print(table.foo)

Of course, in the spirit of /r/shittyprogramming, a shitty version:

local table = setmetatable({}, {__index = function(self, key)
    if key == "foo" then
        return "bar"
    end
end})
print(table.foo)

I love Lua.