Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MapEntry #18

Open
Hixie opened this issue Oct 4, 2018 · 2 comments
Open

MapEntry #18

Hixie opened this issue Oct 4, 2018 · 2 comments

Comments

@Hixie
Copy link

Hixie commented Oct 4, 2018

I like the general direction of https://github.com/munificent/ui-as-code/blob/master/ideas/control-flow-elements.md. One random idea to throw out is whether maybe MapEntry would be a useful class to use in the case of map literals containing control flow. It would let you easily call into other methods and get back name/value pairs; currently, it's not clear how you would programmatically control the name side.

If the language supported tuples, this would also be a place to use those.

@munificent
Copy link
Owner

Oh, that is an interesting idea. That opens up some questions around whether you could use ... to spread a List into a map literal too.

My general impression is that MapEntry is rarely used, so this probably isn't worth the extra complexity. But it might be. I agree that tuples would be a natural fit if we had those. (I think Lasse also feels that if we had tuples, MapEntry would no longer need to exist except for compatibility reasons.)

@tatumizer
Copy link

Map may be retrofitted with a constructor with vararg list of MapEntries:
Map.fromEntries(MapEntry<K,V> entries...)

Then it will be possible to write (see the discussion in #15)

var map = Map.fromEntries {
  +MapEntry("foo", "bar");
  if (cond) {
    +MapEntry("baz", "haha");
  }
} 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants