Prelude.filter

This commit is contained in:
2021-08-12 18:49:36 -06:00
parent 821656b423
commit 595595ddc8
3 changed files with 10 additions and 2 deletions

View File

@@ -70,7 +70,7 @@ class Kiss {
"symbol" => Symbol("Prelude.symbol"),
"expList" => Symbol("Prelude.expList"),
"map" => Symbol("Lambda.map"),
"filter" => Symbol("Lambda.filter"), // TODO use truthy as the default filter function
"filter" => Symbol("Prelude.filter"),
"flatten" => Symbol("Lambda.flatten"),
"has" => Symbol("Lambda.has"),
"count" => Symbol("Lambda.count"),

View File

@@ -517,4 +517,10 @@ class Prelude {
throw "Can't run a subprocess on this target.";
#end
}
public static function filter<T>(l:Iterable<T>, ?p:(T) -> Bool):kiss.List<T> {
if (p == null)
p = Prelude.truthy;
return Lambda.filter(l, p);
}
}

View File

@@ -44,6 +44,8 @@
(method :Array<String> queryImageUrls [:Array<String> imageTitles]
(flatten
(for =>_id image (the haxe.DynamicAccess<Dynamic> .pages .query (query [=>"titles" imageTitles =>"prop" ["imageinfo"] =>"iiprop" ["url"]]))
(image.imageinfo.map ->image image.url))))
(if image.imageinfo
(image.imageinfo.map ->image image.url)
[]))))
(var headers [=>"User-Agent" "NatArchiveTool/0.0.0 (https://github.com/NQNStudios/kisslang/tree/main/projects/nat-archive-tool; natquaylenelson@gmail.com) Requests/2.26.0"])