Foldable
is probably a reasonable choice from the standard libraries:
import Data.Foldable
infixr 1 <||>
(<||>) :: Foldable f => f a -> a -> a
v <||> a =
case toList v of
[] -> a
(x:xs) -> x
It does mean you have to decide whether to take the "first" element found or the "last" one though. Also unfortunately it doesn't yet have an Either
instance, though it's coming in GHC 7.8/base 4.7. In the meantime you can define it yourself:
instance Foldable (Either a) where
foldMap _ (Left _) = mempty
foldMap f (Right y) = f y
foldr _ z (Left _) = z
foldr f z (Right y) = f y z