feat: make empty? an interface (#1139)

This commit is contained in:
Veit Heller 2021-01-20 09:54:08 +01:00 committed by GitHub
parent f23d5d0448
commit 2d34af6aa9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 10 additions and 3 deletions

View File

@ -46,6 +46,7 @@ It will sum the previous sum with each new value, starting at `0`.")
(doc empty? "checks whether the array `a` is empty.")
(defn empty? [a]
(= (Array.length a) 0))
(implements empty? Array.empty?)
(doc any? "checks whether any of the elements in `a` match the function `f`.")
(defn any? [f a]

View File

@ -67,3 +67,5 @@
(definterface slice (Fn [&a Int Int] a))
(definterface blit (Fn [a] a)) ; For types that can be freely memcopied -- exact name is up for discussion
(definterface empty? (Fn [&a] Bool))

View File

@ -288,7 +288,8 @@
(doc empty? "Check whether the map m is empty.")
(defn empty? [m]
(= @(len m) 0))
(= (Map.length m) 0))
(implements empty? Map.empty?)
(doc remove "Remove the value under the key k from the map m.")
(defn remove [m k]
@ -520,7 +521,8 @@
(doc empty? "Check whether the set s is empty.")
(defn empty? [s]
(= (length s) 0))
(= (Set.length s) 0))
(implements empty? Set.empty?)
(doc remove "Remove the value `v` from the set `s`.")
(defn remove [s v]

View File

@ -52,6 +52,7 @@
(doc empty? "checks whether the array `a` is empty.")
(defn empty? [a]
(= (StaticArray.length a) 0))
(implements empty? StaticArray.empty?)
(doc any? "checks whether any of the elements in `a` match the function `f`.")
(defn any? [f a]

View File

@ -73,6 +73,7 @@
(doc empty? "Check if the string is the empty string.")
(defn empty? [s]
(Int.= (length s) 0))
(implements empty? String.empty?)
(doc slice "Return part of a string, beginning at index `a` and ending at index `b`.")
(defn slice [s a b]

View File

@ -72,7 +72,7 @@
(empty? "")
"empty? returns true on empty string")
(assert-true test
(empty? &(zero))
(empty? &(the String (zero)))
"empty? returns true on (zero)")
(assert-equal test
&[\e \r \i \k]