Handbook
Glossary
find-pred ( ... seq quot: ( ... elt -- ... calc ) pred: ( ... calc -- ... ? ) -- ... calc/f i/f elt/f )
Vocabulary
sequences
.
extras
Inputs
seq
a
sequence
quot
a
quotation
pred
a
quotation
Outputs
calc/f
an
object
i/f
an
object
elt/f
an
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
USING:
kernel
sequences
sequences.private
;
IN:
sequences.extras
:
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