module Graphics.UI.Threepenny.Editors.Validation
( ValidationResult
, ok
, fromWarnings
, getWarnings
, Validable(..)
, isValid
, updateIfValid
) where
newtype ValidationResult = ValidationResult [String]
ok :: ValidationResult
ok = ValidationResult []
fromWarnings :: [String] -> ValidationResult
fromWarnings = ValidationResult
getWarnings :: ValidationResult -> [String]
getWarnings (ValidationResult ww) = ww
instance Show ValidationResult where
show = unlines . getWarnings
class Validable a where
validate :: a -> ValidationResult
isValid :: Validable a => a -> Bool
isValid x
| ValidationResult [] <- validate x = True
| otherwise = False
updateIfValid :: Validable a => a -> a -> a
updateIfValid new old
| isValid new = new
| otherwise = old