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

Commit

Permalink
Merge pull request #18 from kRITZCREEK/add-foldable-traversable-intsn…
Browse files Browse the repository at this point in the history
…aces

adds instances
  • Loading branch information
garyb committed Apr 18, 2017
2 parents 237bc59 + d8d41a4 commit a7e98a7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": true,
"scripts": {
"clean": "rimraf output && rimraf .pulp-cache",
"build": "pulp build --censor-lib --strict",
"build": "pulp build -- --censor-lib --strict",
"test": "pulp test"
},
"devDependencies": {
Expand Down
24 changes: 24 additions & 0 deletions src/Data/Json/Extended/Cursor.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import Prelude
import Data.Array as A
import Data.Bifunctor (lmap)
import Data.Eq (class Eq1)
import Data.Foldable (class Foldable)
import Data.Functor.Mu (Mu)
import Data.Json.Extended (EJson)
import Data.Json.Extended as EJ
import Data.Maybe (Maybe(..), maybe)
import Data.Monoid (mempty)
import Data.Ord (class Ord1)
import Data.TacitString (TacitString)
import Data.Traversable (class Traversable, traverse)
import Data.Tuple (Tuple(..), lookup)

import Matryoshka (Algebra, cata, project, embed)
Expand Down Expand Up @@ -58,6 +61,27 @@ instance showCursorF ∷ Show (CursorF TacitString) where
AtKey k a → "(AtKey " <> show k <> " " <> show a <> ")"
AtIndex i a → "(AtIndex " <> show i <> " " <> show a <> ")"

instance foldableCursorF :: Foldable CursorF where
foldr f b = case _ of
All -> b
AtKey _ a -> f a b
AtIndex _ a -> f a b
foldl f b = case _ of
All -> b
AtKey _ a -> f b a
AtIndex _ a -> f b a
foldMap f = case _ of
All -> mempty
AtKey _ a -> f a
AtIndex _ a -> f a

instance traversableCursorF :: Traversable CursorF where
traverse f = case _ of
All -> pure All
AtKey k a -> AtKey k <$> f a
AtIndex i a -> AtIndex i <$> f a
sequence = traverse id

renderEJsonCursor Cursor String
renderEJsonCursor = show

Expand Down

0 comments on commit a7e98a7

Please sign in to comment.