trim ( ... seq quot: ( ... elt -- ... ? ) -- ... newseq )
Factor handbook » The language » Collections » Sequence operations » Trimming sequences

Next:trim-head ( ... seq quot: ( ... elt -- ... ? ) -- ... newseq )


Vocabulary
sequences

Inputs
seqa sequence
quota quotation


Outputs
newseqa sequence


Word description
Removes elements starting from the left and right sides of a sequence if they match a predicate. Once an element does not match, the test stops and the rest of the sequence is left on the stack as a new sequence.

Examples
USING: prettyprint math sequences ; { 0 0 1 2 3 0 0 } [ zero? ] trim .
{ 1 2 3 }


See also
trim-slice, trim-head, trim-head-slice, trim-tail, trim-tail-slice

Definition


: trim ( ... seq quot: ( ... elt -- ... ? ) -- ... newseq )
[ trim-slice ] [ drop ] 2bi like ; inline