Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.5.4, 1.5.5, 1.5.6, 1.6-beta-1
-
None
Description
Add leftShift operators to map that receive a map or a String presentation of a map-entry
Add leftShift operators to map that receive a map or a String presentation of a map-entry
Following a discussion on groovy-user ('Strings to Map.Elements'), this seemed interesting.
Improvement should enable
m = [:]
m << "a:b"
m << [c:'d']
assert m == [a:'b',c:'d']
Adding following two methods to DefaultGroovyMethods might do the trick:
public static Map leftShift(Map self, Map other)
{ self.putAll(other); return self; }public static Map leftShift(Map self, String other)
{ String[] parts = other.split(":"); self.put(parts[0],parts[1]); return self; }