attempt-all ( ... seq quot: ( ... elt -- ... obj ) -- ... obj )
Factor handbook » The language » Continuations

Prev:continue-with ( obj continuation -- * )
Next:with-return ( quot -- )


Vocabulary
continuations

Inputs
seqa sequence
quota quotation


Outputs
objan object


Word description
Applies the quotation to elements in a sequence and returns the value from the first quotation that does not throw an error. If all quotations throw an error, returns the last error thrown.

Examples
The first two numbers throw, the last one doesn't:
USING: prettyprint continuations kernel math ; { 1 3 6 } [ dup odd? [ "Odd" throw ] when ] attempt-all .
6

All quotations throw, the last exception is rethrown:
USING: prettyprint continuations kernel math ; [ { 1 3 5 } [ dup odd? [ throw ] when ] attempt-all ] [ ] recover .
5


Definition