compact ( ... seq quot: ( ... elt -- ... ? ) elt -- ... seq' )


Vocabulary
sequences.extras

Inputs
seqa sequence
quota quotation with stack effect ( ... elt -- ... ? )
eltan 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


: compact
( ... seq quot: ( ... elt -- ... ? ) elt -- ... seq' )
[ split-when harvest ] dip join ; inline