Cleave combinators
Factor handbook » The language » Combinators » Dataflow combinators

Prev:Preserving combinators
Next:Spread combinators


The cleave combinators apply multiple quotations to a single value or set of values.

Two quotations:
Image
bi ( x p q -- )

Image
2bi ( x y p q -- )

Image
3bi ( x y z p q -- )


Three quotations:
Image
tri ( x p q r -- )

Image
2tri ( x y p q r -- )

Image
3tri ( x y z p q r -- )


An array of quotations:
Image
cleave ( x seq -- )

Image
2cleave ( x y seq -- )

Image
3cleave ( x y z seq -- )

Image
4cleave ( w x y z seq -- )


Cleave combinators provide a more readable alternative to repeated applications of the keep combinators. The following example using keep:
[ 1 + ] keep [ 1 - ] keep 2 *

can be more clearly written using tri:
[ 1 + ] [ 1 - ] [ 2 * ] tri