From: Doug Coleman Date: Tue, 14 Feb 2023 05:29:22 +0000 (-0600) Subject: sequences: add find* variant X-Git-Tag: 0.99~557 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=c6a6ff913b2bb1aad79327b7d26b4e69394ff66f sequences: add find* variant --- diff --git a/core/sequences/sequences.factor b/core/sequences/sequences.factor index e6717e23a1..b0e1f3190b 100644 --- a/core/sequences/sequences.factor +++ b/core/sequences/sequences.factor @@ -627,6 +627,27 @@ PRIVATE> : find-index ( ... seq quot: ( ... elt i -- ... ? ) -- ... i elt ) [ 0 ] 2dip find-index-from ; inline +: find-from* ( ... n seq quot: ( ... elt -- ... ? ) -- ... elt i/f ) + '[ _ find-from-unsafe element/index ] bounds-check-call ; inline + +: find* ( ... seq quot: ( ... elt -- ... ? ) -- ... elt i/f ) + [ 0 ] 2dip find-from-unsafe element/index ; inline + +: find-last-from* ( ... n seq quot: ( ... elt -- ... ? ) -- ... elt i/f ) + '[ _ find-last-from-unsafe element/index ] bounds-check-call ; inline + +: find-last* ( ... seq quot: ( ... elt -- ... ? ) -- ... elt i/f ) + [ index-of-last ] dip find-last-from* ; inline + +: find-index-from* ( ... n seq quot: ( ... elt i -- ... ? ) -- ... elt i/f ) + '[ + _ [ sequence-index-operator find-integer-from ] keepd + element/index + ] bounds-check-call ; inline + +: find-index* ( ... seq quot: ( ... elt i -- ... ? ) -- ... elt i/f ) + [ 0 ] 2dip find-index-from* ; inline + : all? ( ... seq quot: ( ... elt -- ... ? ) -- ... ? ) sequence-operator all-integers-from? ; inline