aboutsummaryrefslogtreecommitdiff
path: root/src/server/Validation.hs
blob: 1f332c91d58873d2e74bdd1a7f2865518cbbc6dc (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