Skip to content

Commit

Permalink
Support integer return type in array_sort closure
Browse files Browse the repository at this point in the history
  • Loading branch information
Pieter12345 committed Mar 16, 2024
1 parent 3f3cb89 commit 38e3bbd
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/main/java/com/laytonsmith/core/functions/ArrayHandling.java
Original file line number Diff line number Diff line change
Expand Up @@ -1828,9 +1828,12 @@ private CArray merge(CArray left, CArray right, CClosure closure, Target t) {
} else {
value = -1;
}
} else if(c.isInstanceOf(CInt.TYPE)) {
long longVal = ((CInt) c).getInt();
value = (longVal > 0 ? 1 : (longVal < 0 ? -1 : 0));
} else {
throw new CRECastException("The custom closure did not return a value (or returned an invalid"
+ " type). It must always return true, false, or null.", t);
+ " type). It must always return true, false, null, or an integer.", t);
}
if(value <= 0) {
result.push(left.get(0, t), t);
Expand Down Expand Up @@ -1882,10 +1885,10 @@ public String docs() {
+ " operation. Due to this, it has slightly different behavior than array_normalize, which could"
+ " have also been implemented in place.\n\nIf the sortType is a closure, it will perform a"
+ " custom sort type, and the array may contain any values, including sub array values. The closure"
+ " should accept two values, @left and @right, and should return true if the left value is larger"
+ " than the right, and false if the left value is smaller than the right, and null if they are"
+ " equal. The array will then be re-ordered using a merge sort, using your custom comparator to"
+ " determine the sort order.";
+ " should accept two values, @left and @right, and should return true or a positive integer if the"
+ " left value is larger than the right, and false or a negative integer if the left value is"
+ " smaller than the right, and null or 0 if they are equal. The array will then be re-ordered"
+ " using a merge sort, using your custom comparator to determine the sort order.";
}

@Override
Expand Down

0 comments on commit 38e3bbd

Please sign in to comment.