Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a few misc instances for some patch related types #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions reflex-aeson-orphans.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ library
build-depends: base >=4.9 && <4.12
, aeson
, reflex
, dependent-map
hs-source-dirs: src
default-language: Haskell2010
ghc-options: -Wall -fno-warn-orphans
24 changes: 24 additions & 0 deletions src/Reflex/Aeson/Orphans.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE UndecidableInstances #-}

module Reflex.Aeson.Orphans () where

import Data.Aeson
import Data.Dependent.Map (DMap)
import Data.Foldable (toList)
import Data.Functor.Misc
import Data.Maybe (listToMaybe)
import Reflex

deriving instance FromJSON SelectedCount
deriving instance ToJSON SelectedCount

instance ToJSON (f a) => ToJSON (ComposeMaybe f a) where
toJSON = toJSON . toList . getComposeMaybe
instance FromJSON (f a) => FromJSON (ComposeMaybe f a) where
parseJSON v = ComposeMaybe . listToMaybe <$> parseJSON v

deriving instance
( ToJSON (DMap k (ComposeMaybe v))
) => ToJSON (PatchDMap k v)

deriving instance
( FromJSON (DMap k (ComposeMaybe v))
) => FromJSON (PatchDMap k v)

deriving instance (ToJSONKey k, ToJSON v) => ToJSON (PatchMap k v)
deriving instance (Ord k, FromJSONKey k, FromJSON v) => FromJSON (PatchMap k v)