public static <K, V> Map<K, V> takeWhile(Map<K, V> self, @ClosureParams(MapEntryOrKeyValue.class) Closure<?> condition) {
if (self.isEmpty()) {
return createSimilarMap(self);
}
Map<K, V> ret = createSimilarMap(self);
BooleanClosureWrapper bcw = new BooleanClosureWrapper(condition);
for (Map.Entry<K, V> entry : self.entrySet()) {
if (!bcw.callForMap(entry)) break;
ret.put(entry.getKey(), entry.getValue());
}
return ret;
}