-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCustomType.purs
36 lines (29 loc) · 896 Bytes
/
CustomType.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
module Example.CustomType where
import Prelude
import Data.Either (Either(..))
import Data.Foldable (find)
import Data.Int (fromString) as Int
import Effect (Effect)
import Effect.Console (log)
import Node.Process (getEnv)
import Type.Proxy (Proxy(..))
import TypedEnv (class ParseValue, printEnvError)
import TypedEnv (fromEnv) as TypedEnv
newtype Port = Port Int
instance showPort :: Show Port where
show (Port n) = show n
instance parseValuePort :: ParseValue Port where
parseValue = map Port <<< find (_ <= 65535) <<< Int.fromString
type Settings =
{ "HOST" :: String
, "PORT" :: Port
}
main :: Effect Unit
main = do
env <- TypedEnv.fromEnv (Proxy :: Proxy Settings) <$> getEnv
case env of
Left error ->
log $ "ERROR: " <> printEnvError error
Right { "HOST": host, "PORT": port } -> do
log $ "Connected to " <> host <> ":" <> show port
pure unit