muScript: allMatch/anyMatch
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
This commit is contained in:
parent
5e3dae3ef9
commit
ee7c5f8327
|
@ -61,6 +61,8 @@ public class StandardLib {
|
|||
.set("isEmpty", StandardLib::isEmpty)
|
||||
.set("concat", StandardLib::concat)
|
||||
.set("filter", StandardLib::filter)
|
||||
.set("allMatch", StandardLib::allMatch)
|
||||
.set("anyMatch", StandardLib::anyMatch)
|
||||
.set("map", StandardLib::map)
|
||||
.set("flatMap", StandardLib::flatMap)
|
||||
.set("fold", StandardLib::fold)
|
||||
|
@ -160,6 +162,18 @@ public class StandardLib {
|
|||
return of(args.get(0).asList().getValue().stream().filter(a -> dc.call(a).asBool().getValue()).toList());
|
||||
}
|
||||
|
||||
public static DBool allMatch(DList args) {
|
||||
if (args.size() != 2) throw new IllegalArgumentException("Invalid number of arguments for allMatch: expected 2 but got " + args.size());
|
||||
DCallable dc = args.get(1).asCallable();
|
||||
return of(args.get(0).asList().getValue().stream().allMatch(a -> dc.call(a).asBool().getValue()));
|
||||
}
|
||||
|
||||
public static DBool anyMatch(DList args) {
|
||||
if (args.size() != 2) throw new IllegalArgumentException("Invalid number of arguments for anyMatch: expected 2 but got " + args.size());
|
||||
DCallable dc = args.get(1).asCallable();
|
||||
return of(args.get(0).asList().getValue().stream().anyMatch(a -> dc.call(a).asBool().getValue()));
|
||||
}
|
||||
|
||||
public static DList map(DList args) {
|
||||
if (args.size() != 2) throw new IllegalArgumentException("Invalid number of arguments for map: expected 2 but got " + args.size());
|
||||
return of(args.get(0).asList().getValue().stream().<Dynamic<?>>map(args.get(1).asCallable()::call).toList());
|
||||
|
|
Loading…
Reference in New Issue