feat: add contains method to List and Set classes with example and documentation
Add a `contains(element)` method to the built-in `List` class in `builtin/core.wren` and its embedded source in `src/wren_core.c`, enabling linear search for an element. Introduce a new `Set` class example in `example/set.wren` implementing set operations (union, intersection, difference) using the new `contains` method. Update `doc/site/classes.markdown` with a warning against inheriting from built-in types due to internal bit representation constraints.
This commit is contained in:
@@ -84,6 +84,15 @@ static const char* libSource =
|
||||
" }\n"
|
||||
" return result\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" contains(element) {\n"
|
||||
" for (item in this) {\n"
|
||||
" if (element == item) {\n"
|
||||
" return true\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" return false\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"class Range is Sequence {}\n";
|
||||
|
||||
Reference in New Issue
Block a user