mirror of
https://github.com/carp-lang/Carp.git
synced 2024-11-04 01:25:04 +03:00
feat: make empty? an interface (#1139)
This commit is contained in:
parent
f23d5d0448
commit
2d34af6aa9
@ -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]
|
||||
|
@ -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))
|
||||
|
@ -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]
|
||||
|
@ -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]
|
||||
|
@ -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]
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user