Skip to content

Commit 03df5e6

Browse files
committed
Aeson instances for URI
1 parent ced403b commit 03df5e6

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

pub/functora/src/cfg/Functora/CfgOrphan.hs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,26 @@
22

33
module Functora.CfgOrphan () where
44

5+
import qualified Data.Aeson as A
56
import Functora.Prelude
67
import qualified Text.URI as URI
78
import qualified Toml
89

10+
instance A.ToJSON URI where
11+
toJSON =
12+
A.toJSON . URI.render
13+
14+
instance A.FromJSON URI where
15+
parseJSON =
16+
A.withText "URI"
17+
$ either (fail . displayException) pure
18+
. URI.mkURI
19+
920
instance Toml.HasCodec URI where
1021
hasCodec =
11-
Toml.textBy URI.render $
12-
first (from @String @Text . displayException) . URI.mkURI
22+
Toml.textBy URI.render
23+
$ first (from @String @Text . displayException)
24+
. URI.mkURI
1325

1426
instance Toml.HasItemCodec URI where
1527
hasItemCodec =
@@ -21,4 +33,5 @@ instance Toml.HasItemCodec URI where
2133
(const . Toml.MatchError Toml.TText $ Toml.AnyValue src)
2234
$ URI.mkURI txt
2335
)
24-
$ Toml.Text . URI.render
36+
$ Toml.Text
37+
. URI.render

0 commit comments

Comments
 (0)