diff --git a/colonnade/src/Colonnade/Decoding.hs b/colonnade/src/Colonnade/Decoding.hs index c698581..408e0f2 100644 --- a/colonnade/src/Colonnade/Decoding.hs +++ b/colonnade/src/Colonnade/Decoding.hs @@ -23,9 +23,12 @@ headless f = DecodingAp Headless f (DecodingPure id) headed :: content -> (content -> Either String a) -> Decoding Headed content a headed h f = DecodingAp (Headed h) f (DecodingPure id) +-- | Maps over a 'Decoding' that expects headers, converting these +-- expected headers into the indices of the columns that they +-- correspond to. headedToIndexed :: forall content a. Eq content - => Vector content - -> Decoding Headed content a + => Vector content -- ^ Headers in the source document + -> Decoding Headed content a -- ^ Decoding that contains expected headers -> Either (HeadingError content) (Decoding Indexed content a) headedToIndexed v = go where diff --git a/colonnade/src/Colonnade/Types.hs b/colonnade/src/Colonnade/Types.hs index 1f3e5d2..f9b05c1 100644 --- a/colonnade/src/Colonnade/Types.hs +++ b/colonnade/src/Colonnade/Types.hs @@ -14,6 +14,8 @@ module Colonnade.Types import Data.Vector (Vector) import Data.Functor.Contravariant (Contravariant(..)) import Data.Functor.Contravariant.Divisible (Divisible(..)) +import Control.Exception (Exception) +import Data.Typeable (Typeable) import qualified Data.Vector as Vector -- | Isomorphic to 'Identity' @@ -33,6 +35,8 @@ data HeadingError content = HeadingError , headingErrorDuplicate :: Vector (content,Int) -- ^ headers that occurred more than once } deriving (Show,Read) +instance (Show content, Typeable content) => Exception (HeadingError content) + instance Monoid (HeadingError content) where mempty = HeadingError Vector.empty Vector.empty mappend (HeadingError a1 b1) (HeadingError a2 b2) = HeadingError