1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-18 06:34:48 +00:00

on bad type, contains? shuld return false (not error)

Note this actually changes behavior from a thin wrapper over `index-of`.
This is because `(index-of 3 3)` throws "error: expected iterable type, got 3"
This commit is contained in:
Techcable 2022-08-26 12:23:02 -07:00
parent 12a1849090
commit 765eb84c33
No known key found for this signature in database
GPG Key ID: D7B98ADFF827CD17

View File

@ -1198,9 +1198,6 @@
~(def ,alias :dyn ,;more ,kw))
(defn- collection-type-error [val]
(errorf "Expected a collection (tuple|array|table|struct), but got %t" val))
(defn contains-value?
```Checks if a collection contains the specified value.
@ -1230,7 +1227,7 @@
(nil? k) (break))
(set k (next collection k))))
res)
(collection-type-error collection)))
false))
(defn contains-key?
```Checks if a collection contains the specified key.
@ -1251,7 +1248,6 @@
Noe that tables or structs (dictionaries) never contain null keys```
[collection key]
(assert (collection? collection) (collection-type-error collection))
(not (nil? (get collection key))))
(defn contains?
@ -1274,7 +1270,7 @@
(cond
(indexed? collection) (not (nil? (index-of val collection)))
(dictionary? collection) (not (nil? (get collection val)))
(collection-type-error collection)))
false))
(defdyn *defdyn-prefix* ``Optional namespace prefix to add to keywords declared with `defdyn`.