feat: add List.where method for filtering elements with predicate function

Implement a `where` method on the List class that takes a predicate function and returns a new list containing only elements for which the predicate returns true. The implementation iterates over the list, calls the predicate on each element, and collects matching elements into a new list. Includes test cases verifying filtering with both matching and non-matching predicates.
This commit is contained in:
Kyle Marek-Spartz
2014-02-15 06:42:14 +00:00
parent 6d11a2e4a1
commit 35fbcc5b49
3 changed files with 24 additions and 0 deletions
+8
View File
@@ -59,6 +59,14 @@ static const char* libSource =
" }\n"
" return result\n"
" }\n"
" \n"
" where (f) {\n"
" var result = []\n"
" for (element in this) {\n"
" if (f.call(element)) result.add(element)\n"
" }\n"
" return result\n"
" }\n"
"}\n";
// Validates that the given argument in [args] is a Num. Returns true if it is.