shared void asd()
{
value map = HashMap<String,Integer> {"A" -> 1};
// Increment stored integer
map.put("A", (map.get("A") else 0)+1); // <- Compiles, but not readable
map["A"] += 1; // <- Readable, but doesnt compile
}
https://github.com/ceylon/ceylon/issues/4148
--
You received this message because you are subscribed to the Google Groups "ceylon-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceylon-users...@googlegroups.com.
To post to this group, send email to ceylon...@googlegroups.com.
Visit this group at https://groups.google.com/group/ceylon-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceylon-users/1e7212c4-616f-4494-ba75-ac861494ecb5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
map["A"] += 1; // <- Readable, but doesnt compile
// Increment stored integer
map.put("A", (map.get("A") else 0)+1); // <- not readable
map["A"] = (map["A"] else 0)+1; // <- readable
import ceylon.collection { HashMap }class MyMap<Key, Item>() extends HashMap<Key, Item>() given Key satisfies Object { shared void compute(Key key, Item(Item?) fun) { put(key, fun(get(key))); } shared void merge(Key key, Item item, Item(Item) fun) { put(key, fun(get(key) else item)); }}
shared void run() { value map = MyMap<String, Integer>(); map.compute("A", (x) => x else 0 + 1); map.merge("A", 0 , Integer.plus(1));}