aboutsummaryrefslogtreecommitdiff
path: root/server/src/Validation/Atomic.hs
blob: 7a7351aa49e093917ad7c7fe5f3f595bda523f0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module Validation.Atomic
  ( nonEmpty
  , nonNullNumber
  -- , number
  ) where

import           Data.Text  (Text)
import qualified Data.Text  as T

import qualified Common.Msg as Msg

nonEmpty :: Text -> Maybe Text
nonEmpty str =
  if T.null str
    then Just $ Msg.get Msg.Form_NonEmpty
    else Nothing

nonNullNumber :: Int -> Maybe Text
nonNullNumber n =
  if n == 0
     then Just $ Msg.get Msg.Form_NonNullNumber
     else Nothing

-- 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