mirror of
https://github.com/byteverse/colonnade.git
synced 2026-09-02 01:13:51 +02:00
add column indexing function
This commit is contained in:
parent
5325778502
commit
3240edd8ec
@ -23,9 +23,12 @@ headless f = DecodingAp Headless f (DecodingPure id)
|
|||||||
headed :: content -> (content -> Either String a) -> Decoding Headed content a
|
headed :: content -> (content -> Either String a) -> Decoding Headed content a
|
||||||
headed h f = DecodingAp (Headed h) f (DecodingPure id)
|
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
|
headedToIndexed :: forall content a. Eq content
|
||||||
=> Vector content
|
=> Vector content -- ^ Headers in the source document
|
||||||
-> Decoding Headed content a
|
-> Decoding Headed content a -- ^ Decoding that contains expected headers
|
||||||
-> Either (HeadingError content) (Decoding Indexed content a)
|
-> Either (HeadingError content) (Decoding Indexed content a)
|
||||||
headedToIndexed v = go
|
headedToIndexed v = go
|
||||||
where
|
where
|
||||||
|
|||||||
@ -14,6 +14,8 @@ module Colonnade.Types
|
|||||||
import Data.Vector (Vector)
|
import Data.Vector (Vector)
|
||||||
import Data.Functor.Contravariant (Contravariant(..))
|
import Data.Functor.Contravariant (Contravariant(..))
|
||||||
import Data.Functor.Contravariant.Divisible (Divisible(..))
|
import Data.Functor.Contravariant.Divisible (Divisible(..))
|
||||||
|
import Control.Exception (Exception)
|
||||||
|
import Data.Typeable (Typeable)
|
||||||
import qualified Data.Vector as Vector
|
import qualified Data.Vector as Vector
|
||||||
|
|
||||||
-- | Isomorphic to 'Identity'
|
-- | Isomorphic to 'Identity'
|
||||||
@ -33,6 +35,8 @@ data HeadingError content = HeadingError
|
|||||||
, headingErrorDuplicate :: Vector (content,Int) -- ^ headers that occurred more than once
|
, headingErrorDuplicate :: Vector (content,Int) -- ^ headers that occurred more than once
|
||||||
} deriving (Show,Read)
|
} deriving (Show,Read)
|
||||||
|
|
||||||
|
instance (Show content, Typeable content) => Exception (HeadingError content)
|
||||||
|
|
||||||
instance Monoid (HeadingError content) where
|
instance Monoid (HeadingError content) where
|
||||||
mempty = HeadingError Vector.empty Vector.empty
|
mempty = HeadingError Vector.empty Vector.empty
|
||||||
mappend (HeadingError a1 b1) (HeadingError a2 b2) = HeadingError
|
mappend (HeadingError a1 b1) (HeadingError a2 b2) = HeadingError
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user