validate ( x pairs -- Either-x )


Vocabulary
monadics

Inputs
xan object
pairsArray of pairs of form: { error-value [ predicate? ] }


Outputs
Either-xan Either


Word description
Applies each predicate to x in turn. If the result of any is f, x is replaced with Left error-value according to the predicate which it failed, otherwise, raises x to a Right value.

Examples
USING: kernel math monadics sequences sets prettyprint ; : trivial-validate-username ( string -- Either-string ) { { "Name is too long." [ length 32 < ] } { "Forbidden Characters." [ "(){}<>\"" intersect { } = ] } } validate ; "EvilUsername\"" trivial-validate-username .
T{ Left { value "Forbidden Characters." } }


Definition