Repository: apple/pkl
File: pkl-core/src/main/java/org/pkl/core/stdlib/base/MappingNodes.java (Java)

Code before:
    }
  }

  public abstract static class getOrNull extends ExternalMethod1Node {
    @Child private IndirectCallNode callNode = IndirectCallNode.create();

    @Specialization
    protected Object eval(VmMapping self, Object key) {
      return VmNull.lift(VmUtils.readMemberOrNull(self, key, callNode));
    }
  }

  public abstract static class getOrDefault extends ExternalMethod1Node {
    @Child private IndirectCallNode callNode = IndirectCallNode.create();
    @Child private ApplyVmFunction1Node applyNode = ApplyVmFunction1Node.create();

    @Specialization
    protected Object eval(VmMapping self, Object key) {
      var value = VmUtils.readMemberOrNull(self, key, callNode);
      if (value != null) {
        return value;
      }
      if (VmUtils.readMember(self, Identifier.DEFAULT) instanceof VmFunction defaultFn) {
        return applyNode.execute(defaultFn, key);
      }
      throw PklBugException.unreachableCode();
    }
  }

  public abstract static class fold extends ExternalMethod2Node {
    @Child private ApplyVmFunction3Node applyLambdaNode = ApplyVmFunction3NodeGen.create();

    @Specialization
    protected Object eval(VmMapping self, Object initial, VmFunction function) {
      var result = new MutableReference<>(initial);
      self.forceAndIterateMemberValues(
          (key, def, value) -> {
            result.set(applyLambdaNode.execute(function, result.get(), key, value));
            return true;
          });
      return result.get();
    }
  }

  public abstract static class every extends ExternalMethod1Node {
    @Child private ApplyVmFunction2Node applyLambdaNode = ApplyVmFunction2NodeGen.create();

    @Specialization
    protected boolean eval(VmMapping self, VmFunction function) {
      var result = new MutableBoolean(true);
      self.iterateMemberValues(

Review comment (suggestion):
```suggestion
      var defaultFunction = (VmFunction) VmUtils.readMember(self, Identifier.DEFAULT, callNode);
      return applyNode.execute(defaultFunction, key);
```

Code after:
  }

  public abstract static class getOrNull extends ExternalMethod1Node {
    @Child private IndirectCallNode callNode = IndirectCallNode.create();

    @Specialization
    protected Object eval(VmMapping self, Object key) {
      return VmNull.lift(VmUtils.readMemberOrNull(self, key, callNode));
    }
  }

  public abstract static class getOrDefault extends ExternalMethod1Node {
    @Child private IndirectCallNode callNode = IndirectCallNode.create();
    @Child private ApplyVmFunction1Node applyNode = ApplyVmFunction1Node.create();

    @Specialization
    protected Object eval(VmMapping self, Object key) {
      var value = VmUtils.readMemberOrNull(self, key, callNode);
      if (value != null) {
        return value;
      }

      var defaultFunction = (VmFunction) VmUtils.readMember(self, Identifier.DEFAULT, callNode);
      return applyNode.execute(defaultFunction, key);
    }
  }

  public abstract static class fold extends ExternalMethod2Node {
    @Child private ApplyVmFunction3Node applyLambdaNode = ApplyVmFunction3NodeGen.create();

    @Specialization
    protected Object eval(VmMapping self, Object initial, VmFunction function) {
      var result = new MutableReference<>(initial);
      self.forceAndIterateMemberValues(
          (key, def, value) -> {
            result.set(applyLambdaNode.execute(function, result.get(), key, value));
            return true;
          });
      return result.get();
    }
  }

  public abstract static class every extends ExternalMethod1Node {
    @Child private ApplyVmFunction2Node applyLambdaNode = ApplyVmFunction2NodeGen.create();

    @Specialization
    protected boolean eval(VmMapping self, VmFunction function) {
      var result = new MutableBoolean(true);
      self.iterateMemberValues(
          (key, member, value) -> {
            if (value == null) {