unless-empty ( ... seq quot: ( ... seq -- ... ) -- ... )
Factor handbook » The language » Collections » Sequence operations » Control flow with sequences

Prev:when-empty ( ... seq quot: ( ... -- ... obj ) -- ... seq/obj )


Vocabulary
sequences

Inputs
seqa sequence
quotthe second quotation of an if-empty


Outputs
None

Word description
Makes an implicit check if the sequence is empty. An empty sequence is dropped. Otherwise, the quot is called on the sequence.

Examples
This word is equivalent to if-empty with an empty first quotation:
USING: sequences prettyprint ; { 4 5 6 } [ ] [ sum . ] if-empty
15

USING: sequences prettyprint ; { 4 5 6 } [ sum . ] unless-empty
15


Definition


: unless-empty ( ... seq quot: ( ... seq -- ... ) -- ... )
[ ] swap if-empty ; inline