find-pred ( ... seq quot: ( ... elt -- ... calc ) pred: ( ... calc -- ... ? ) -- ... calc/f i/f elt/f )


Vocabulary
sequences.extras

Inputs
seqa sequence
quota quotation
preda quotation


Outputs
calc/fan object
i/fan object
elt/fan object


Word description
A version of find that saves the calculation done by the first quotation and returns the calulation, element, and index if the calculation matches a predicate quotation.

Examples
USING: math kernel sequences.extras prettyprint ; { 4 5 6 } [ sq ] [ 20 > ] find-pred [ . ] tri@
25 5 1


Definition


: find-pred
( ... seq quot: ( ... elt -- ... calc ) pred: ( ... calc -- ... ? ) -- ... calc/f i/f elt/f )
[ 0 ] 3dip [ [ length check-length ] keep ] 2dip
[ [ [ nth-unsafe ] ] dip [ 1check ] curry compose ] dip
[ 1check ] curry compose find-pred-loop swapd ; inline