blob: fd739cd5af1a748de39967c53eed8859ee14a2c4 (
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 :: Text -> Maybe Text
nonEmpty str =
if T.null str
then Nothing
else Just str
number :: (Int -> Bool) -> Text -> Maybe Int
number numberForm str =
case reads (T.unpack str) :: [(Int, String)] of
(num, _) : _ ->
if numberForm num
then Just num
else Nothing
_ ->
Nothing
|