Handbook
Glossary
if-empty ( ..a seq quot1: ( ..a -- ..b ) quot2: ( ..a seq -- ..b ) -- ..b )
Factor handbook
»
The language
»
Collections
»
Sequence operations
»
Control flow with sequences
Next:
when-empty ( ... seq quot: ( ... -- ... obj ) -- ... seq/obj )
Vocabulary
sequences
Inputs
seq
a
sequence
quot1
a
quotation
quot2
a
quotation
Outputs
None
Word description
Makes an implicit check if the sequence is empty. An empty sequence is dropped and
quot1
is called. Otherwise, if the sequence has any elements,
quot2
is called on it.
Examples
USING: kernel prettyprint sequences ; { 1 2 3 } [ "empty sequence" ] [ sum ] if-empty .
6
Definition
USING:
kernel
;
IN:
sequences
:
if-empty
( ..a seq quot1: ( ..a -- ..b ) quot2: ( ..a seq -- ..b ) -- ..b )
[
dup
empty?
]
[
[
drop
]
prepose
]
[
]
tri*
if
;
inline