@@ -58,6 +58,7 @@ import Control.DeepSeq (NFData(..))
58import Data.ByteString.Builder (Builder, char7, toLazyByteString)
58import Data.ByteString.Builder (Builder, char7, toLazyByteString)
59import Data.Char (toLower, isUpper)
59import Data.Char (toLower, isUpper)
60import Data.Scientific (Scientific)
60import Data.Scientific (Scientific)
61+import Data.Foldable (Foldable(..))
61import Data.Hashable (Hashable(..))
62import Data.Hashable (Hashable(..))
62import Data.Data (Data)
63import Data.Data (Data)
63import Data.HashMap.Strict (HashMap)
64import Data.HashMap.Strict (HashMap)
@@ -66,6 +67,7 @@ import Data.String (IsString(..))
66import Data.Text (Text, pack, unpack)
67import Data.Text (Text, pack, unpack)
67import Data.Time (UTCTime)
68import Data.Time (UTCTime)
68import Data.Time.Format (FormatTime)
69import Data.Time.Format (FormatTime)
70+import Data.Traversable (Traversable(..))
69import Data.Typeable (Typeable)
71import Data.Typeable (Typeable)
70import Data.Vector (Vector)
72import Data.Vector (Vector)
71import qualified Data.HashMap.Strict as H
73import qualified Data.HashMap.Strict as H
@@ -186,6 +188,34 @@ instance Monoid (Result a) where
186 mappend = mplus
188 mappend = mplus
187 {-# INLINE mappend #-}
189 {-# INLINE mappend #-}
191+instance Foldable IResult where
192+ foldMap _ (IError _ _) = mempty
193+ foldMap f (ISuccess y) = f y
194+ {-# INLINE foldMap #-}
196+ foldr _ z (IError _ _) = z
197+ foldr f z (ISuccess y) = f y z
198+ {-# INLINE foldr #-}
200+instance Foldable Result where
201+ foldMap _ (Error _) = mempty
202+ foldMap f (Success y) = f y
203+ {-# INLINE foldMap #-}
205+ foldr _ z (Error _) = z
206+ foldr f z (Success y) = f y z
207+ {-# INLINE foldr #-}
209+instance Traversable IResult where
210+ traverse _ (IError path err) = pure (IError path err)
211+ traverse f (ISuccess a) = ISuccess <$> f a
212+ {-# INLINE traverse #-}
214+instance Traversable Result where
215+ traverse _ (Error err) = pure (Error err)
216+ traverse f (Success a) = Success <$> f a
217+ {-# INLINE traverse #-}
189-- | Failure continuation.
219-- | Failure continuation.
190type Failure f r = JSONPath -> String -> f r
220type Failure f r = JSONPath -> String -> f r
191-- | Success continuation.
221-- | Success continuation.