]> gitweb.factorcode.org Git - factor.git/blobdiff - core/sequences/sequences.factor
add if-zero/when-zero/unless-zero to core/ and update usages
[factor.git] / core / sequences / sequences.factor
index f0dc6d36c7da928ea0b4920b5afe6be1fb3462a3..2e41d9d2e19d8accc58240a61c04d228dcf5ec63 100755 (executable)
@@ -29,13 +29,27 @@ M: sequence shorten 2dup length < [ set-length ] [ 2drop ] if ;
 
 : empty? ( seq -- ? ) length 0 = ; inline
 
+<PRIVATE
+
+: (if-empty) ( seq quot1 quot2 quot3 -- )
+    [ [ drop ] prepose ] [ ] tri* if ; inline
+
+PRIVATE>
+
 : if-empty ( seq quot1 quot2 -- )
-    [ dup empty? ] [ [ drop ] prepose ] [ ] tri* if ; inline
+    [ dup empty? ] (if-empty) ; inline
 
 : when-empty ( seq quot -- ) [ ] if-empty ; inline
 
 : unless-empty ( seq quot -- ) [ ] swap if-empty ; inline
 
+: if-zero ( n quot1 quot2 -- )
+    [ dup zero? ] (if-empty) ; inline
+
+: when-zero ( seq quot -- ) [ ] if-zero ; inline
+
+: unless-zero ( seq quot -- ) [ ] swap if-zero ; inline
+
 : delete-all ( seq -- ) 0 swap set-length ;
 
 : first ( seq -- first ) 0 swap nth ; inline