org.organicdesign.fp.collections.ImMap Maven / Gradle / Ivy
package org.organicdesign.fp.collections;
import java.util.Map;
/** An immutable map with no guarantees about its ordering. */
public interface ImMap extends BaseUnsortedMap {
/** Returns a new map with the given key/value added */
@Override ImMap assoc(K key, V val);
/** Returns a new map with an immutable copy of the given entry added */
@Override default ImMap assoc(Map.Entry entry) {
return assoc(entry.getKey(), entry.getValue());
}
/** Returns a new map with the given key/value removed */
@Override ImMap without(K key);
/**
Returns a view of the mappings contained in this map. The set should actually contain
UnmodMap.Entry items, but that return signature is illegal in Java, so you'll just have to
remember.
*/
@Override default ImSet> entrySet() {
return map(e -> (Map.Entry) e)
.toImSet();
}
/** Returns an immutable view of the keys contained in this map. */
@Override default ImSet keySet() {
return mutable().keySet().immutable();
}
/** Returns a mutable version of this mutable map. */
MutableMap mutable();
}