Skip to content

Commit

Permalink
LogicalMap: add methods plus and minus
Browse files Browse the repository at this point in the history
  • Loading branch information
btj committed Jun 28, 2021
1 parent a52866d commit fdf4d0b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions logicalcollections/src/logicalcollections/LogicalMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,24 @@ public static <K, V> boolean allEntriesMatch(Map<K, V> map, BiPredicate<K, V> pr
return map.keySet().stream().allMatch(k -> predicate.test(k, map.get(k)));
}

/**
* Returns a map that contains the entries of the given map
* as well as the given entry.
*/
public static <K, V> Map<K, V> plus(Map<K, V> map, K key, V value) {
var result = new HashMap<>(map);
result.put(key, value);
return result;
}

/**
* Returns a map that contains the entries of the given map
* except for the entry with the given key.
*/
public static <K, V> Map<K, V> minus(Map<K, V> map, K key) {
var result = new HashMap<>(map);
result.remove(key);
return result;
}

}

0 comments on commit fdf4d0b

Please sign in to comment.