We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c9249e8 commit 07fd229Copy full SHA for 07fd229
src/main/java/com/annimon/ownlang/lib/MapValue.java
@@ -5,6 +5,7 @@
5
import java.util.Iterator;
6
import java.util.Map;
7
import java.util.Objects;
8
+import java.util.function.Consumer;
9
10
/**
11
*
@@ -31,6 +32,18 @@ public MapValue(Map<Value, Value> map) {
31
32
this.map = map;
33
}
34
35
+ public boolean ifPresent(String key, Consumer<Value> consumer) {
36
+ return ifPresent(new StringValue(key), consumer);
37
+ }
38
+
39
+ public boolean ifPresent(Value key, Consumer<Value> consumer) {
40
+ if (map.containsKey(key)) {
41
+ consumer.accept(map.get(key));
42
+ return true;
43
44
+ return false;
45
46
47
public ArrayValue toPairs() {
48
final int size = map.size();
49
final ArrayValue result = new ArrayValue(size);
0 commit comments