Skip to content
Open
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
9 changes: 9 additions & 0 deletions src/Toml/Schema/Matcher.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import Control.Applicative (Alternative(..))
import Control.Monad (MonadPlus, ap, liftM)
import Data.Monoid (Endo(..))
import Data.Text (Text)
import Data.Bifunctor (Bifunctor (..))

-- | Computations that result in a 'Result' and which track a list
-- of nested contexts to assist in generating warnings and error
Expand Down Expand Up @@ -130,6 +131,14 @@ data Result e a
Eq {- ^ Default instance -},
Ord {- ^ Default instance -})

instance Functor (Result e) where
fmap _ (Failure e) = Failure e
fmap f (Success e a) = Success e (f a)

instance Bifunctor Result where
bimap f _ (Failure e) = Failure (fmap f e)
bimap f g (Success e a) = Success (fmap f e) (g a)

-- | Run a 'Matcher' with an empty scope.
runMatcher :: Matcher l a -> Result (MatchMessage l) a
runMatcher (Matcher m) = m [] mempty (Failure . runDList) (Success . runDList)
Expand Down