?either ( x left pred -- Either-x )


Vocabulary
monadics

Inputs
xan object
lefta fallback value
preda quotation of type ( x -- bool )


Outputs
Either-xan Either


Word description
Calls pred on x and either raises the original value to a Right or replaces it with the fallback value as a Left.

Examples
USING: math monadics prettyprint ; 90125 "Not a number." [ number? ] ?either .
T{ Right { value 90125 } }

USING: math monadics prettyprint ; "Hello!" "Not a number." [ number? ] ?either .
T{ Left { value "Not a number." } }


Definition