blob: 455ae5b84b9d64c55d556a14256c8e8e5f150c0b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
module Validation
( nonEmpty
, number
) where
import Data.Text (Text)
import qualified Data.Text as T
nonEmpty :: a -> Text -> Either a Text
nonEmpty x str =
if T.null str
then Left x
else Right str
number :: x -> (Int -> Bool) -> Text -> Either x Int
number x numberForm str =
case reads (T.unpack str) :: [(Int, String)] of
(num, _) : _ ->
if numberForm num
then Right num
else Left x
_ ->
Left x
|