Handbook
Glossary
compact ( ... seq quot: ( ... elt -- ... ? ) elt -- ... seq' )
Vocabulary
sequences
.
extras
Inputs
seq
a
sequence
quot
a
quotation
with stack effect
( ... elt -- ... ? )
elt
an
object
Outputs
seq'
a
sequence
Word description
Generate a new sequence where all runs of elements for which the predicate returns true are replaced by a single instance of
elt
. Runs at the beginning or end of the sequence for which the predicate returns true are removed.
See also
collapse
Examples
Collapse multiple spaces in a string down to a single space
USING: kernel prettyprint sequences.extras ; " Hello, crazy world " [ CHAR: \s = ] " " compact .
"Hello, crazy world"
Definition
USING:
kernel
sequences
splitting
;
IN:
sequences.extras
:
compact
( ... seq quot: ( ... elt -- ... ? ) elt -- ... seq' )
[
split-when
harvest
]
dip
join
;
inline