mirror of
https://github.com/github/semantic.git
synced 2025-01-05 14:11:33 +03:00
Move the ToJSONFields instance for populated Unions into Data.JSON.Fields.
This commit is contained in:
parent
7bb92dfd98
commit
5b62e4bf5c
@ -1,7 +1,11 @@
|
||||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
module Data.JSON.Fields where
|
||||
|
||||
import Data.Aeson
|
||||
import Data.Bifunctor.Join
|
||||
import Data.Foldable (toList)
|
||||
import Data.Proxy (Proxy(..))
|
||||
import Data.Union
|
||||
|
||||
class ToJSONFields a where
|
||||
toJSONFields :: KeyValue kv => a -> [kv]
|
||||
@ -15,3 +19,6 @@ instance ToJSONFields a => ToJSONFields (Maybe a) where
|
||||
|
||||
instance ToJSON a => ToJSONFields [a] where
|
||||
toJSONFields list = [ "children" .= list ]
|
||||
|
||||
instance (Apply1 Foldable fs, ToJSON a) => ToJSONFields (Union fs a) where
|
||||
toJSONFields = apply1 (Proxy :: Proxy Foldable) (\ r -> [ "children" .= toList r ])
|
||||
|
@ -16,7 +16,6 @@ import Data.Functor.Both (Both)
|
||||
import Data.JSON.Fields
|
||||
import qualified Data.Map as Map
|
||||
import Data.Output
|
||||
import Data.Proxy
|
||||
import Data.Semigroup ((<>))
|
||||
import Data.Text (pack, Text)
|
||||
import Data.Text.Encoding (decodeUtf8)
|
||||
@ -80,9 +79,6 @@ instance ToJSONFields a => ToJSONFields (Patch a) where
|
||||
instance ToJSON recur => ToJSONFields (Syntax recur) where
|
||||
toJSONFields syntax = [ "children" .= toList syntax ]
|
||||
|
||||
instance (Apply1 Foldable fs, ToJSON a) => ToJSONFields (Union fs a) where
|
||||
toJSONFields = apply1 (Proxy :: Proxy Foldable) (\ r -> [ "children" .= toList r ])
|
||||
|
||||
instance ToJSONFields (Union '[] a) where
|
||||
toJSONFields _ = []
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user