Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit a7e98a7

Browse files
authored
Merge pull request #18 from kRITZCREEK/add-foldable-traversable-intsnaces
adds instances
2 parents 237bc59 + d8d41a4 commit a7e98a7

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"private": true,
33
"scripts": {
44
"clean": "rimraf output && rimraf .pulp-cache",
5-
"build": "pulp build --censor-lib --strict",
5+
"build": "pulp build -- --censor-lib --strict",
66
"test": "pulp test"
77
},
88
"devDependencies": {

src/Data/Json/Extended/Cursor.purs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import Prelude
55
import Data.Array as A
66
import Data.Bifunctor (lmap)
77
import Data.Eq (class Eq1)
8+
import Data.Foldable (class Foldable)
89
import Data.Functor.Mu (Mu)
910
import Data.Json.Extended (EJson)
1011
import Data.Json.Extended as EJ
1112
import Data.Maybe (Maybe(..), maybe)
13+
import Data.Monoid (mempty)
1214
import Data.Ord (class Ord1)
1315
import Data.TacitString (TacitString)
16+
import Data.Traversable (class Traversable, traverse)
1417
import Data.Tuple (Tuple(..), lookup)
1518

1619
import 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+
6185
renderEJsonCursor Cursor String
6286
renderEJsonCursor = show
6387

0 commit comments

Comments
 (0)