/
Params.purs
44 lines (33 loc) · 1018 Bytes
/
Params.purs
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
33
34
35
36
37
38
39
40
41
42
43
44
module Payload.Params
( DecodeError
, class FromParam
, class FromSegments
, class ToParam
, fromParam
, fromSegments
, toParam
) where
import Prelude
import Data.Either (Either(..))
import Data.Int as Int
import Data.List (List)
import Data.Maybe (maybe)
type DecodeError = String
class FromParam a where
fromParam :: String -> Either DecodeError a
instance fromParamInt :: FromParam Int where
fromParam s = maybe (Left errorMsg) Right (Int.fromString s)
where
errorMsg = "Could not decode '" <> s <> "' into an Int"
instance fromParamString :: FromParam String where
fromParam s = Right s
class FromSegments a where
fromSegments :: List String -> Either DecodeError a
instance fromSegmentsListString :: FromSegments (List String) where
fromSegments s = Right s
class ToParam a where
toParam :: a -> String
instance toParamInt :: ToParam Int where
toParam = show
instance toParamString :: ToParam String where
toParam s = s