]> gitweb.factorcode.org Git - factor.git/commitdiff
sequences: Add 2any? combinator
authortimor <timor.dd@googlemail.com>
Thu, 18 Feb 2021 11:50:33 +0000 (12:50 +0100)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 18 Feb 2021 14:48:04 +0000 (07:48 -0700)
core/sequences/sequences-docs.factor
core/sequences/sequences-tests.factor
core/sequences/sequences.factor

index 690e888ca1675a3272e43ee44e1ba595368c62ae..85613f68c9f79ff4cafcbf7a50b66fa3786966e3 100644 (file)
@@ -491,7 +491,7 @@ HELP: 3map-as
 
 HELP: 2all?
 { $values { "seq1" sequence } { "seq2" sequence } { "quot" { $quotation ( ... elt1 elt2 -- ... ? ) } } { "?" boolean } }
-{ $description "Tests the predicate pairwise against elements of " { $snippet "seq1" } " and " { $snippet "seq2" } ". If the sequences have different lengths, then only the smallest sequences items are compared with the other." }
+{ $description "Tests if all pairwise elements of " { $snippet "seq1" } " and " { $snippet "seq2" } " fulfill the predicate. If the sequences have different lengths, then only the smallest sequences items are compared with the other." }
 { $examples
   { $example
     "USING: math prettyprint sequences ;"
@@ -500,6 +500,17 @@ HELP: 2all?
   }
 } ;
 
+HELP: 2any?
+{ $values { "seq1" sequence } { "seq2" sequence } { "quot" { $quotation ( ... elt1 elt2 -- ... ? ) } } { "?" boolean } }
+{ $description "Tests if any pairwise elements of " { $snippet "seq1" } " and " { $snippet "seq2" } " fulfill the predicate. If the sequences have different lengths, then only the smallest sequences items are compared with the other." }
+{ $examples
+  { $example
+    "USING: math prettyprint sequences ;"
+    "{ 2 4 5 8 } { 2 4 6 8 } [ < ] 2any? ."
+    "t"
+  }
+} ;
+
 HELP: find
 { $values { "seq" sequence }
           { "quot" { $quotation ( ... elt -- ... ? ) } }
index 74320d76bab40514103734053092a0ec7ab24e3d..722e61545c6104f6152272d53406b0e0a79c12df 100644 (file)
@@ -421,3 +421,7 @@ M: bogus-hashcode hashcode* 2drop 0 >bignum ;
 } [ { 11 22 33 } [ + ] BV{ } map-index-as ] unit-test
 
 { t } [ { } { 99 88 } [ <= ] 2all? ] unit-test
+
+{ f } [ { } { 99 88 } [ <= ] 2any? ] unit-test
+{ t } [ { 2 4 5 8 } { 2 4 6 8 } [ < ] 2any? ] unit-test
+{ f } [ { 2 4 6 8 } { 2 4 6 8 } [ < ] 2any? ] unit-test
index a6650fa9b559a8f7c65c3bf1b335dd0de30703bb..37def46ded4299e70f0ec909da82bfc1a977c576 100644 (file)
@@ -522,6 +522,9 @@ PRIVATE>
 : 2all? ( ... seq1 seq2 quot: ( ... elt1 elt2 -- ... ? ) -- ... ? )
     (2each) all-integers? ; inline
 
+: 2any? ( ... seq1 seq2 quot: ( ... elt1 elt2 -- ... ? ) -- ... ? )
+    [ not ] compose 2all? not ; inline
+
 : 3each ( ... seq1 seq2 seq3 quot: ( ... elt1 elt2 elt3 -- ... ) -- ... )
     (3each) each-integer ; inline