Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
slightly improve Map.keys/Map.items (see #6063)
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Mar 5, 2016
1 parent 66cf6ba commit 494d7dc
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions language/src/ceylon/language/Map.ceylon
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,24 @@ shared interface Map<out Key=Object, out Item=Anything>
shared actual formal Map<Key,Item> clone();

"A [[Collection]] containing the keys of this map."
//TODO: should be a Set
shared actual default Collection<Key> keys
=> object satisfies Collection<Key> {
=> object extends Object()
satisfies Set<Key> {
contains(Object key) => outer.defines(key);
iterator() => outer.map(Entry.key).iterator();
clone() => [*this];
size => outer.size;
empty => outer.empty;
clone() => set(this);
};

"A [[Collection]] containing the items stored in this
map. An element can be stored under more than one key
in the map, and so it can occur more than once in the
resulting collection."
shared default Collection<Item> items
=> object satisfies Collection<Item> {
=> object extends Object()

This comment has been minimized.

Copy link
@jvasileff

jvasileff Mar 5, 2016

Contributor

@gavinking the compiler is complaining that we need something for hash and equals

This comment has been minimized.

Copy link
@gavinking

gavinking Mar 5, 2016

Author Contributor

Yeah, I just push that fix.

This comment has been minimized.

Copy link
@jvasileff

jvasileff Mar 5, 2016

Contributor

quick 😄

satisfies Collection<Item> {
shared actual Boolean contains(Object item) {
for (k->v in outer) {
if (exists v, v==item) {
Expand All @@ -144,8 +148,9 @@ shared interface Map<out Key=Object, out Item=Anything>
}
}
iterator() => outer.map(Entry.item).iterator();
clone() => [*this];
size => outer.size;
empty => outer.empty;
clone() => [*this];
};

"Invert this map, producing a new immutable map where
Expand Down

0 comments on commit 494d7dc

Please sign in to comment.