@@ -5,12 +5,15 @@ import Prelude
55import Data.Array as A
66import Data.Bifunctor (lmap )
77import Data.Eq (class Eq1 )
8+ import Data.Foldable (class Foldable )
89import Data.Functor.Mu (Mu )
910import Data.Json.Extended (EJson )
1011import Data.Json.Extended as EJ
1112import Data.Maybe (Maybe (..), maybe )
13+ import Data.Monoid (mempty )
1214import Data.Ord (class Ord1 )
1315import Data.TacitString (TacitString )
16+ import Data.Traversable (class Traversable , traverse )
1417import Data.Tuple (Tuple (..), lookup )
1518
1619import Matryoshka (Algebra , cata , project , embed )
@@ -58,6 +61,27 @@ instance showCursorF ∷ Show (CursorF TacitString) where
5861 AtKey k a → " (AtKey " <> show k <> " " <> show a <> " )"
5962 AtIndex i a → " (AtIndex " <> show i <> " " <> show a <> " )"
6063
64+ instance foldableCursorF :: Foldable CursorF where
65+ foldr f b = case _ of
66+ All -> b
67+ AtKey _ a -> f a b
68+ AtIndex _ a -> f a b
69+ foldl f b = case _ of
70+ All -> b
71+ AtKey _ a -> f b a
72+ AtIndex _ a -> f b a
73+ foldMap f = case _ of
74+ All -> mempty
75+ AtKey _ a -> f a
76+ AtIndex _ a -> f a
77+
78+ instance traversableCursorF :: Traversable CursorF where
79+ traverse f = case _ of
80+ All -> pure All
81+ AtKey k a -> AtKey k <$> f a
82+ AtIndex i a -> AtIndex i <$> f a
83+ sequence = traverse id
84+
6185renderEJsonCursor ∷ Cursor → String
6286renderEJsonCursor = show
6387
0 commit comments